diff options
Diffstat (limited to 'core/fpdfapi/fpdf_parser')
-rw-r--r-- | core/fpdfapi/fpdf_parser/cfdf_document.cpp | 9 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_parser/cpdf_dictionary.cpp | 17 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_parser/cpdf_document.cpp | 34 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_parser/cpdf_object_unittest.cpp | 22 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_parser/cpdf_stream.cpp | 2 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_parser/cpdf_syntax_parser.cpp | 32 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_parser/cpdf_syntax_parser.h | 7 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_parser/include/cfdf_document.h | 6 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h | 8 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_parser/include/cpdf_document.h | 6 |
10 files changed, 95 insertions, 48 deletions
diff --git a/core/fpdfapi/fpdf_parser/cfdf_document.cpp b/core/fpdfapi/fpdf_parser/cfdf_document.cpp index c602f634ad..128c513c60 100644 --- a/core/fpdfapi/fpdf_parser/cfdf_document.cpp +++ b/core/fpdfapi/fpdf_parser/cfdf_document.cpp @@ -14,18 +14,21 @@ CFDF_Document::CFDF_Document() : CPDF_IndirectObjectHolder(), m_pRootDict(nullptr), m_pFile(nullptr), - m_bOwnFile(FALSE) {} + m_bOwnFile(FALSE), + m_pByteStringPool(WrapUnique(new CFX_ByteStringPool)) {} CFDF_Document::~CFDF_Document() { if (m_bOwnFile && m_pFile) m_pFile->Release(); + m_pByteStringPool.Clear(); // Make weak. } CFDF_Document* CFDF_Document::CreateNewDoc() { CFDF_Document* pDoc = new CFDF_Document; - pDoc->m_pRootDict = new CPDF_Dictionary; + pDoc->m_pRootDict = new CPDF_Dictionary(pDoc->GetByteStringPool()); pDoc->AddIndirectObject(pDoc->m_pRootDict); - pDoc->m_pRootDict->SetFor("FDF", new CPDF_Dictionary); + pDoc->m_pRootDict->SetFor("FDF", + new CPDF_Dictionary(pDoc->GetByteStringPool())); return pDoc; } diff --git a/core/fpdfapi/fpdf_parser/cpdf_dictionary.cpp b/core/fpdfapi/fpdf_parser/cpdf_dictionary.cpp index 1a84fcb142..0b415d370d 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_dictionary.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_dictionary.cpp @@ -19,7 +19,8 @@ #include "third_party/base/stl_util.h" #include "third_party/base/logging.h" -CPDF_Dictionary::CPDF_Dictionary() {} +CPDF_Dictionary::CPDF_Dictionary(const CFX_WeakPtr<CFX_ByteStringPool>& pPool) + : m_pPool(pPool) {} CPDF_Dictionary::~CPDF_Dictionary() { // Mark the object as deleted so that it will not be deleted again @@ -61,7 +62,7 @@ CPDF_Object* CPDF_Dictionary::CloneNonCyclic( bool bDirect, std::set<const CPDF_Object*>* pVisited) const { pVisited->insert(this); - CPDF_Dictionary* pCopy = new CPDF_Dictionary(); + CPDF_Dictionary* pCopy = new CPDF_Dictionary(m_pPool); for (const auto& it : *this) { CPDF_Object* value = it.second; if (!pdfium::ContainsKey(*pVisited, value)) { @@ -174,7 +175,7 @@ void CPDF_Dictionary::SetFor(const CFX_ByteString& key, CPDF_Object* pObj) { auto it = m_Map.find(key); if (it == m_Map.end()) { if (pObj) - m_Map.insert(std::make_pair(key, pObj)); + m_Map.insert(std::make_pair(MaybeIntern(key), pObj)); return; } @@ -211,7 +212,7 @@ void CPDF_Dictionary::ReplaceKey(const CFX_ByteString& oldkey, new_it->second->Release(); new_it->second = old_it->second; } else { - m_Map.insert(std::make_pair(newkey, old_it->second)); + m_Map.insert(std::make_pair(MaybeIntern(newkey), old_it->second)); } m_Map.erase(old_it); } @@ -222,12 +223,12 @@ void CPDF_Dictionary::SetIntegerFor(const CFX_ByteString& key, int i) { void CPDF_Dictionary::SetNameFor(const CFX_ByteString& key, const CFX_ByteString& name) { - SetFor(key, new CPDF_Name(name)); + SetFor(key, new CPDF_Name(MaybeIntern(name))); } void CPDF_Dictionary::SetStringFor(const CFX_ByteString& key, const CFX_ByteString& str) { - SetFor(key, new CPDF_String(str, FALSE)); + SetFor(key, new CPDF_String(MaybeIntern(str), FALSE)); } void CPDF_Dictionary::SetReferenceFor(const CFX_ByteString& key, @@ -265,3 +266,7 @@ void CPDF_Dictionary::SetMatrixFor(const CFX_ByteString& key, pArray->AddNumber(matrix.f); SetFor(key, pArray); } + +CFX_ByteString CPDF_Dictionary::MaybeIntern(const CFX_ByteString& str) { + return m_pPool ? m_pPool->Intern(str) : str; +} diff --git a/core/fpdfapi/fpdf_parser/cpdf_document.cpp b/core/fpdfapi/fpdf_parser/cpdf_document.cpp index 1694566f1b..7e75a437a8 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_document.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_document.cpp @@ -383,14 +383,15 @@ void ProcessNonbCJK(CPDF_Dictionary* pBaseDict, pBaseDict->SetFor("Widths", pWidths); } -CPDF_Dictionary* CalculateFontDesc(CFX_ByteString basefont, +CPDF_Dictionary* CalculateFontDesc(CPDF_Document* pDoc, + CFX_ByteString basefont, int flags, int italicangle, int ascend, int descend, CPDF_Array* bbox, int32_t stemV) { - CPDF_Dictionary* pFontDesc = new CPDF_Dictionary; + CPDF_Dictionary* pFontDesc = new CPDF_Dictionary(pDoc->GetByteStringPool()); pFontDesc->SetNameFor("Type", "FontDescriptor"); pFontDesc->SetNameFor("FontName", basefont); pFontDesc->SetIntegerFor("Flags", flags); @@ -413,7 +414,8 @@ CPDF_Document::CPDF_Document(std::unique_ptr<CPDF_Parser> pParser) m_iFirstPageNo(0), m_dwFirstPageObjNum(0), m_pDocPage(new CPDF_DocPageData(this)), - m_pDocRender(new CPDF_DocRenderData(this)) { + m_pDocRender(new CPDF_DocRenderData(this)), + m_pByteStringPool(WrapUnique(new CFX_ByteStringPool)) { if (pParser) SetLastObjNum(m_pParser->GetLastObjNum()); } @@ -421,6 +423,7 @@ CPDF_Document::CPDF_Document(std::unique_ptr<CPDF_Parser> pParser) CPDF_Document::~CPDF_Document() { delete m_pDocPage; CPDF_ModuleMgr::Get()->GetPageModule()->ClearStockFont(this); + m_pByteStringPool.Clear(); // Make weak. } CPDF_Object* CPDF_Document::ParseIndirectObject(uint32_t objnum) { @@ -687,20 +690,21 @@ CPDF_Image* CPDF_Document::LoadImageF(CPDF_Object* pObj) { void CPDF_Document::CreateNewDoc() { ASSERT(!m_pRootDict && !m_pInfoDict); - m_pRootDict = new CPDF_Dictionary; + m_pRootDict = new CPDF_Dictionary(m_pByteStringPool); m_pRootDict->SetNameFor("Type", "Catalog"); AddIndirectObject(m_pRootDict); - CPDF_Dictionary* pPages = new CPDF_Dictionary; + + CPDF_Dictionary* pPages = new CPDF_Dictionary(m_pByteStringPool); pPages->SetNameFor("Type", "Pages"); pPages->SetNumberFor("Count", 0); pPages->SetFor("Kids", new CPDF_Array); m_pRootDict->SetReferenceFor("Pages", this, AddIndirectObject(pPages)); - m_pInfoDict = new CPDF_Dictionary; + m_pInfoDict = new CPDF_Dictionary(m_pByteStringPool); AddIndirectObject(m_pInfoDict); } CPDF_Dictionary* CPDF_Document::CreateNewPage(int iPage) { - CPDF_Dictionary* pDict = new CPDF_Dictionary; + CPDF_Dictionary* pDict = new CPDF_Dictionary(m_pByteStringPool); pDict->SetNameFor("Type", "Page"); uint32_t dwObjNum = AddIndirectObject(pDict); if (InsertNewPage(this, iPage, pDict, m_PageList) < 0) { @@ -743,7 +747,7 @@ size_t CPDF_Document::CalculateEncodingDict(int charset, } if (i == FX_ArraySize(g_FX_CharsetUnicodes)) return i; - CPDF_Dictionary* pEncodingDict = new CPDF_Dictionary; + CPDF_Dictionary* pEncodingDict = new CPDF_Dictionary(m_pByteStringPool); pEncodingDict->SetNameFor("BaseEncoding", "WinAnsiEncoding"); CPDF_Array* pArray = new CPDF_Array; pArray->AddInteger(128); @@ -765,7 +769,7 @@ CPDF_Dictionary* CPDF_Document::ProcessbCJK( FX_BOOL bVert, CFX_ByteString basefont, std::function<void(FX_WCHAR, FX_WCHAR, CPDF_Array*)> Insert) { - CPDF_Dictionary* pFontDict = new CPDF_Dictionary; + CPDF_Dictionary* pFontDict = new CPDF_Dictionary(m_pByteStringPool); CFX_ByteString cmap; CFX_ByteString ordering; int supplement = 0; @@ -815,7 +819,7 @@ CPDF_Dictionary* CPDF_Document::ProcessbCJK( pFontDict->SetNameFor("Type", "Font"); pFontDict->SetNameFor("Subtype", "CIDFontType2"); pFontDict->SetNameFor("BaseFont", basefont); - CPDF_Dictionary* pCIDSysInfo = new CPDF_Dictionary; + CPDF_Dictionary* pCIDSysInfo = new CPDF_Dictionary(m_pByteStringPool); pCIDSysInfo->SetStringFor("Registry", "Adobe"); pCIDSysInfo->SetStringFor("Ordering", ordering); pCIDSysInfo->SetIntegerFor("Supplement", supplement); @@ -840,7 +844,7 @@ CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, FX_BOOL bVert) { CalculateFlags(pFont->IsBold(), pFont->IsItalic(), pFont->IsFixedWidth(), false, false, charset == FXFONT_SYMBOL_CHARSET); - CPDF_Dictionary* pBaseDict = new CPDF_Dictionary; + CPDF_Dictionary* pBaseDict = new CPDF_Dictionary(m_pByteStringPool); pBaseDict->SetNameFor("Type", "Font"); std::unique_ptr<CFX_UnicodeEncoding> pEncoding( new CFX_UnicodeEncoding(pFont)); @@ -907,7 +911,7 @@ CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, FX_BOOL bVert) { } } CPDF_Dictionary* pFontDesc = - CalculateFontDesc(basefont, flags, italicangle, pFont->GetAscent(), + CalculateFontDesc(this, basefont, flags, italicangle, pFont->GetAscent(), pFont->GetDescent(), pBBox, nStemV); pFontDict->SetReferenceFor("FontDescriptor", this, AddIndirectObject(pFontDesc)); @@ -972,7 +976,7 @@ CPDF_Font* CPDF_Document::AddWindowsFont(LOGFONTA* pLogFont, ptm->otmrcFontBox.right, ptm->otmrcFontBox.top}; FX_Free(tm_buf); basefont.Replace(" ", ""); - CPDF_Dictionary* pBaseDict = new CPDF_Dictionary; + CPDF_Dictionary* pBaseDict = new CPDF_Dictionary(m_pByteStringPool); pBaseDict->SetNameFor("Type", "Font"); CPDF_Dictionary* pFontDict = pBaseDict; if (!bCJK) { @@ -1002,8 +1006,8 @@ CPDF_Font* CPDF_Document::AddWindowsFont(LOGFONTA* pLogFont, for (int i = 0; i < 4; i++) pBBox->AddInteger(bbox[i]); CPDF_Dictionary* pFontDesc = - CalculateFontDesc(basefont, flags, italicangle, ascend, descend, pBBox, - pLogFont->lfWeight / 5); + CalculateFontDesc(this, basefont, flags, italicangle, ascend, descend, + pBBox, pLogFont->lfWeight / 5); pFontDesc->SetIntegerFor("CapHeight", capheight); pFontDict->SetReferenceFor("FontDescriptor", this, AddIndirectObject(pFontDesc)); diff --git a/core/fpdfapi/fpdf_parser/cpdf_object_unittest.cpp b/core/fpdfapi/fpdf_parser/cpdf_object_unittest.cpp index dad98cd28e..1548b1914a 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_object_unittest.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_object_unittest.cpp @@ -66,7 +66,7 @@ class PDFObjectsTest : public testing::Test { m_ArrayObj->InsertAt(0, new CPDF_Number(8902)); m_ArrayObj->InsertAt(1, new CPDF_Name("address")); // Dictionary object. - m_DictObj = new CPDF_Dictionary; + m_DictObj = new CPDF_Dictionary(CFX_WeakPtr<CFX_ByteStringPool>()); m_DictObj->SetFor("bool", new CPDF_Boolean(false)); m_DictObj->SetFor("num", new CPDF_Number(0.23f)); // Stream object. @@ -74,7 +74,7 @@ class PDFObjectsTest : public testing::Test { size_t buf_len = FX_ArraySize(content); uint8_t* buf = reinterpret_cast<uint8_t*>(malloc(buf_len)); memcpy(buf, content, buf_len); - m_StreamDictObj = new CPDF_Dictionary; + m_StreamDictObj = new CPDF_Dictionary(CFX_WeakPtr<CFX_ByteStringPool>()); m_StreamDictObj->SetFor("key1", new CPDF_String(L" test dict")); m_StreamDictObj->SetFor("key2", new CPDF_Number(-1)); CPDF_Stream* stream_obj = new CPDF_Stream(buf, buf_len, m_StreamDictObj); @@ -553,7 +553,7 @@ TEST(PDFArrayTest, GetTypeAt) { CPDF_Dictionary* vals[3]; ScopedArray arr(new CPDF_Array); for (size_t i = 0; i < 3; ++i) { - vals[i] = new CPDF_Dictionary; + vals[i] = new CPDF_Dictionary(CFX_WeakPtr<CFX_ByteStringPool>()); for (size_t j = 0; j < 3; ++j) { std::string key("key"); char buf[33]; @@ -580,7 +580,7 @@ TEST(PDFArrayTest, GetTypeAt) { CPDF_Stream* stream_vals[3]; ScopedArray arr(new CPDF_Array); for (size_t i = 0; i < 3; ++i) { - vals[i] = new CPDF_Dictionary; + vals[i] = new CPDF_Dictionary(CFX_WeakPtr<CFX_ByteStringPool>()); for (size_t j = 0; j < 3; ++j) { std::string key("key"); char buf[33]; @@ -625,11 +625,13 @@ TEST(PDFArrayTest, GetTypeAt) { arr_val->AddNumber(1); arr_val->AddNumber(2); arr->InsertAt(11, arr_val); - CPDF_Dictionary* dict_val = new CPDF_Dictionary; + CPDF_Dictionary* dict_val = + new CPDF_Dictionary(CFX_WeakPtr<CFX_ByteStringPool>()); dict_val->SetFor("key1", new CPDF_String("Linda", false)); dict_val->SetFor("key2", new CPDF_String("Zoe", false)); arr->InsertAt(12, dict_val); - CPDF_Dictionary* stream_dict = new CPDF_Dictionary; + CPDF_Dictionary* stream_dict = + new CPDF_Dictionary(CFX_WeakPtr<CFX_ByteStringPool>()); stream_dict->SetFor("key1", new CPDF_String("John", false)); stream_dict->SetFor("key2", new CPDF_String("King", false)); uint8_t data[] = "A stream for test"; @@ -768,7 +770,7 @@ TEST(PDFArrayTest, CloneDirectObject) { TEST(PDFDictionaryTest, CloneDirectObject) { CPDF_IndirectObjectHolder objects_holder; - ScopedDict dict(new CPDF_Dictionary); + ScopedDict dict(new CPDF_Dictionary(CFX_WeakPtr<CFX_ByteStringPool>())); dict->SetReferenceFor("foo", &objects_holder, 1234); ASSERT_EQ(1U, dict->GetCount()); CPDF_Object* obj = dict->GetObjectFor("foo"); @@ -790,7 +792,8 @@ TEST(PDFObjectTest, CloneCheckLoop) { // Create an object with a reference loop. ScopedArray arr_obj(new CPDF_Array); // Dictionary object. - CPDF_Dictionary* dict_obj = new CPDF_Dictionary; + CPDF_Dictionary* dict_obj = + new CPDF_Dictionary(CFX_WeakPtr<CFX_ByteStringPool>()); dict_obj->SetFor("arr", arr_obj.get()); arr_obj->InsertAt(0, dict_obj); @@ -808,7 +811,8 @@ TEST(PDFObjectTest, CloneCheckLoop) { { CPDF_IndirectObjectHolder objects_holder; // Create an object with a reference loop. - CPDF_Dictionary* dict_obj = new CPDF_Dictionary; + CPDF_Dictionary* dict_obj = + new CPDF_Dictionary(CFX_WeakPtr<CFX_ByteStringPool>()); CPDF_Array* arr_obj = new CPDF_Array; objects_holder.AddIndirectObject(dict_obj); EXPECT_EQ(1u, dict_obj->GetObjNum()); diff --git a/core/fpdfapi/fpdf_parser/cpdf_stream.cpp b/core/fpdfapi/fpdf_parser/cpdf_stream.cpp index cc584b78b3..3b047205c4 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_stream.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_stream.cpp @@ -93,7 +93,7 @@ void CPDF_Stream::SetData(const uint8_t* pData, uint32_t size) { FXSYS_memcpy(m_pDataBuf.get(), pData, size); m_dwSize = size; if (!m_pDict) - m_pDict.reset(new CPDF_Dictionary); + m_pDict.reset(new CPDF_Dictionary(CFX_WeakPtr<CFX_ByteStringPool>())); m_pDict->SetIntegerFor("Length", size); m_pDict->RemoveFor("Filter"); m_pDict->RemoveFor("DecodeParms"); diff --git a/core/fpdfapi/fpdf_parser/cpdf_syntax_parser.cpp b/core/fpdfapi/fpdf_parser/cpdf_syntax_parser.cpp index 4bfaf99ed9..a29137cd43 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_syntax_parser.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_syntax_parser.cpp @@ -37,10 +37,15 @@ struct SearchTagRecord { int CPDF_SyntaxParser::s_CurrentRecursionDepth = 0; CPDF_SyntaxParser::CPDF_SyntaxParser() + : CPDF_SyntaxParser(CFX_WeakPtr<CFX_ByteStringPool>()) {} + +CPDF_SyntaxParser::CPDF_SyntaxParser( + const CFX_WeakPtr<CFX_ByteStringPool>& pPool) : m_MetadataObjnum(0), m_pFileAccess(nullptr), m_pFileBuf(nullptr), - m_BufSize(CPDF_ModuleMgr::kFileBufSize) {} + m_BufSize(CPDF_ModuleMgr::kFileBufSize), + m_pPool(pPool) {} CPDF_SyntaxParser::~CPDF_SyntaxParser() { FX_Free(m_pFileBuf); @@ -409,15 +414,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 +433,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 +442,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 +535,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 +555,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 +991,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; +} diff --git a/core/fpdfapi/fpdf_parser/cpdf_syntax_parser.h b/core/fpdfapi/fpdf_parser/cpdf_syntax_parser.h index 8ca7e33824..5838fb7144 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_syntax_parser.h +++ b/core/fpdfapi/fpdf_parser/cpdf_syntax_parser.h @@ -9,6 +9,8 @@ #include <memory> +#include "core/fxcrt/include/cfx_string_pool_template.h" +#include "core/fxcrt/include/cfx_weak_ptr.h" #include "core/fxcrt/include/fx_basic.h" class CPDF_CryptoHandler; @@ -21,6 +23,7 @@ class IFX_FileRead; class CPDF_SyntaxParser { public: CPDF_SyntaxParser(); + explicit CPDF_SyntaxParser(const CFX_WeakPtr<CFX_ByteStringPool>& pPool); ~CPDF_SyntaxParser(); void InitParser(IFX_FileRead* pFileAccess, uint32_t HeaderOffset); @@ -64,7 +67,6 @@ class CPDF_SyntaxParser { static int s_CurrentRecursionDepth; uint32_t GetDirectNum(); - FX_BOOL GetNextChar(uint8_t& ch); FX_BOOL GetCharAtBackward(FX_FILESIZE pos, uint8_t& ch); void GetNextWordInternal(bool* bIsNumber); @@ -80,6 +82,8 @@ class CPDF_SyntaxParser { uint32_t objnum, uint32_t gennum); + CFX_ByteString MaybeIntern(const CFX_ByteString& str); + FX_FILESIZE m_Pos; int m_MetadataObjnum; IFX_FileRead* m_pFileAccess; @@ -91,6 +95,7 @@ class CPDF_SyntaxParser { std::unique_ptr<CPDF_CryptoHandler> m_pCryptoHandler; uint8_t m_WordBuffer[257]; uint32_t m_WordSize; + CFX_WeakPtr<CFX_ByteStringPool> m_pPool; }; #endif // CORE_FPDFAPI_FPDF_PARSER_CPDF_SYNTAX_PARSER_H_ diff --git a/core/fpdfapi/fpdf_parser/include/cfdf_document.h b/core/fpdfapi/fpdf_parser/include/cfdf_document.h index 834aecd1ba..25366b0cd4 100644 --- a/core/fpdfapi/fpdf_parser/include/cfdf_document.h +++ b/core/fpdfapi/fpdf_parser/include/cfdf_document.h @@ -9,6 +9,8 @@ #include "core/fpdfapi/fpdf_parser/include/cpdf_indirect_object_holder.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_object.h" +#include "core/fxcrt/include/cfx_string_pool_template.h" +#include "core/fxcrt/include/cfx_weak_ptr.h" #include "core/fxcrt/include/fx_basic.h" class CPDF_Dictionary; @@ -23,6 +25,9 @@ class CFDF_Document : public CPDF_IndirectObjectHolder { FX_BOOL WriteBuf(CFX_ByteTextBuf& buf) const; CPDF_Dictionary* GetRoot() const { return m_pRootDict; } + CFX_WeakPtr<CFX_ByteStringPool> GetByteStringPool() const { + return m_pByteStringPool; + } protected: CFDF_Document(); @@ -31,6 +36,7 @@ class CFDF_Document : public CPDF_IndirectObjectHolder { CPDF_Dictionary* m_pRootDict; IFX_FileRead* m_pFile; FX_BOOL m_bOwnFile; + CFX_WeakPtr<CFX_ByteStringPool> m_pByteStringPool; }; #endif // CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CFDF_DOCUMENT_H_ diff --git a/core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h b/core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h index fc69ce2f4b..501b287dfc 100644 --- a/core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h +++ b/core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h @@ -11,6 +11,8 @@ #include <set> #include "core/fpdfapi/fpdf_parser/include/cpdf_object.h" +#include "core/fxcrt/include/cfx_string_pool_template.h" +#include "core/fxcrt/include/cfx_weak_ptr.h" #include "core/fxcrt/include/fx_coordinates.h" #include "core/fxcrt/include/fx_string.h" @@ -21,7 +23,7 @@ class CPDF_Dictionary : public CPDF_Object { using iterator = std::map<CFX_ByteString, CPDF_Object*>::iterator; using const_iterator = std::map<CFX_ByteString, CPDF_Object*>::const_iterator; - CPDF_Dictionary(); + explicit CPDF_Dictionary(const CFX_WeakPtr<CFX_ByteStringPool>& pPool); // CPDF_Object. Type GetType() const override; @@ -78,13 +80,17 @@ class CPDF_Dictionary : public CPDF_Object { const_iterator begin() const { return m_Map.begin(); } const_iterator end() const { return m_Map.end(); } + CFX_WeakPtr<CFX_ByteStringPool> GetByteStringPool() const { return m_pPool; } + protected: ~CPDF_Dictionary() override; + CFX_ByteString MaybeIntern(const CFX_ByteString& str); CPDF_Object* CloneNonCyclic( bool bDirect, std::set<const CPDF_Object*>* visited) const override; + CFX_WeakPtr<CFX_ByteStringPool> m_pPool; std::map<CFX_ByteString, CPDF_Object*> m_Map; }; diff --git a/core/fpdfapi/fpdf_parser/include/cpdf_document.h b/core/fpdfapi/fpdf_parser/include/cpdf_document.h index 1cc32dc3b2..383c6faeb4 100644 --- a/core/fpdfapi/fpdf_parser/include/cpdf_document.h +++ b/core/fpdfapi/fpdf_parser/include/cpdf_document.h @@ -13,6 +13,8 @@ #include "core/fpdfapi/fpdf_parser/include/cpdf_indirect_object_holder.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_object.h" #include "core/fpdfdoc/include/cpdf_linklist.h" +#include "core/fxcrt/include/cfx_string_pool_template.h" +#include "core/fxcrt/include/cfx_weak_ptr.h" #include "core/fxcrt/include/fx_basic.h" class CFX_Font; @@ -47,6 +49,9 @@ class CPDF_Document : public CPDF_IndirectObjectHolder { CPDF_Parser* GetParser() const { return m_pParser.get(); } CPDF_Dictionary* GetRoot() const { return m_pRootDict; } CPDF_Dictionary* GetInfo() const { return m_pInfoDict; } + CFX_WeakPtr<CFX_ByteStringPool> GetByteStringPool() const { + return m_pByteStringPool; + } void DeletePage(int iPage); int GetPageCount() const; @@ -134,6 +139,7 @@ class CPDF_Document : public CPDF_IndirectObjectHolder { std::unique_ptr<JBig2_DocumentContext> m_pCodecContext; std::unique_ptr<CPDF_LinkList> m_pLinksContext; CFX_ArrayTemplate<uint32_t> m_PageList; + CFX_WeakPtr<CFX_ByteStringPool> m_pByteStringPool; }; #endif // CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_DOCUMENT_H_ |