Chromium Code Reviews| Index: core/fpdfapi/fpdf_parser/cpdf_syntax_parser.cpp |
| diff --git a/core/fpdfapi/fpdf_parser/cpdf_syntax_parser.cpp b/core/fpdfapi/fpdf_parser/cpdf_syntax_parser.cpp |
| index 4bfaf99ed953d2dca089dda388d9a2922b82e7ac..200d3a4df04c8c258f912a08c5e74fadd640bd2b 100644 |
| --- a/core/fpdfapi/fpdf_parser/cpdf_syntax_parser.cpp |
| +++ b/core/fpdfapi/fpdf_parser/cpdf_syntax_parser.cpp |
| @@ -40,7 +40,15 @@ CPDF_SyntaxParser::CPDF_SyntaxParser() |
| : m_MetadataObjnum(0), |
|
Lei Zhang
2016/09/20 23:48:23
Use a delegate ctor?
: CPDF_SyntaxParser(nullptr)
Tom Sepez
2016/09/27 22:36:59
done
|
| m_pFileAccess(nullptr), |
| m_pFileBuf(nullptr), |
| - m_BufSize(CPDF_ModuleMgr::kFileBufSize) {} |
| + m_BufSize(CPDF_ModuleMgr::kFileBufSize), |
| + m_pPool(nullptr) {} |
| + |
| +CPDF_SyntaxParser::CPDF_SyntaxParser(CFX_ByteStringPool* pPool) |
| + : m_MetadataObjnum(0), |
| + m_pFileAccess(nullptr), |
| + m_pFileBuf(nullptr), |
| + m_BufSize(CPDF_ModuleMgr::kFileBufSize), |
| + m_pPool(pPool) {} |
| CPDF_SyntaxParser::~CPDF_SyntaxParser() { |
| FX_Free(m_pFileBuf); |
| @@ -409,15 +417,14 @@ CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjectHolder* pObjList, |
| CFX_ByteString str = ReadString(); |
| if (m_pCryptoHandler && bDecrypt) |
| m_pCryptoHandler->Decrypt(objnum, gennum, str); |
| - return new CPDF_String(str, FALSE); |
| + return new CPDF_String(MaybeIntern(str), FALSE); |
| } |
| if (word == "<") { |
| CFX_ByteString str = ReadHexString(); |
| if (m_pCryptoHandler && bDecrypt) |
| m_pCryptoHandler->Decrypt(objnum, gennum, str); |
| - |
| - return new CPDF_String(str, TRUE); |
| + return new CPDF_String(MaybeIntern(str), TRUE); |
| } |
| if (word == "[") { |
| @@ -429,8 +436,8 @@ CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjectHolder* pObjList, |
| } |
| if (word[0] == '/') { |
| - return new CPDF_Name( |
| - PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1))); |
| + return new CPDF_Name(MaybeIntern( |
| + PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1)))); |
| } |
| if (word == "<<") { |
| @@ -438,7 +445,7 @@ CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjectHolder* pObjList, |
| FX_FILESIZE dwSignValuePos = 0; |
| std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict( |
| - new CPDF_Dictionary); |
| + new CPDF_Dictionary(m_pPool)); |
| while (1) { |
| CFX_ByteString key = GetNextWord(nullptr); |
| if (key.IsEmpty()) |
| @@ -531,14 +538,14 @@ CPDF_Object* CPDF_SyntaxParser::GetObjectForStrict( |
| CFX_ByteString str = ReadString(); |
| if (m_pCryptoHandler) |
| m_pCryptoHandler->Decrypt(objnum, gennum, str); |
| - return new CPDF_String(str, FALSE); |
| + return new CPDF_String(MaybeIntern(str), FALSE); |
| } |
| if (word == "<") { |
| CFX_ByteString str = ReadHexString(); |
| if (m_pCryptoHandler) |
| m_pCryptoHandler->Decrypt(objnum, gennum, str); |
| - return new CPDF_String(str, TRUE); |
| + return new CPDF_String(MaybeIntern(str), TRUE); |
| } |
| if (word == "[") { |
| @@ -551,13 +558,13 @@ CPDF_Object* CPDF_SyntaxParser::GetObjectForStrict( |
| } |
| if (word[0] == '/') { |
| - return new CPDF_Name( |
| - PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1))); |
| + return new CPDF_Name(MaybeIntern( |
| + PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1)))); |
| } |
| if (word == "<<") { |
| std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict( |
| - new CPDF_Dictionary); |
| + new CPDF_Dictionary(m_pPool)); |
| while (1) { |
| FX_FILESIZE SavedPos = m_Pos; |
| CFX_ByteString key = GetNextWord(nullptr); |
| @@ -987,3 +994,7 @@ void CPDF_SyntaxParser::SetEncrypt( |
| std::unique_ptr<CPDF_CryptoHandler> pCryptoHandler) { |
| m_pCryptoHandler = std::move(pCryptoHandler); |
| } |
| + |
| +CFX_ByteString CPDF_SyntaxParser::MaybeIntern(const CFX_ByteString& str) { |
| + return m_pPool ? m_pPool->Intern(str) : str; |
| +} |