diff options
Diffstat (limited to 'core/fpdfapi/parser/cpdf_parser.cpp')
-rw-r--r-- | core/fpdfapi/parser/cpdf_parser.cpp | 54 |
1 files changed, 34 insertions, 20 deletions
diff --git a/core/fpdfapi/parser/cpdf_parser.cpp b/core/fpdfapi/parser/cpdf_parser.cpp index da95cc5f24..cff0f77b32 100644 --- a/core/fpdfapi/parser/cpdf_parser.cpp +++ b/core/fpdfapi/parser/cpdf_parser.cpp @@ -61,7 +61,9 @@ CPDF_Parser::CPDF_Parser() } CPDF_Parser::~CPDF_Parser() { - delete m_pTrailer; + if (m_pTrailer) + m_pTrailer->Release(); + ReleaseEncryptHandler(); SetEncryptDictionary(nullptr); @@ -70,10 +72,13 @@ CPDF_Parser::~CPDF_Parser() { m_pSyntax->m_pFileAccess = nullptr; } - for (CPDF_Dictionary* trailer : m_Trailers) - delete trailer; + for (CPDF_Dictionary* trailer : m_Trailers) { + if (trailer) + trailer->Release(); + } - delete m_pLinearized; + if (m_pLinearized) + m_pLinearized->Release(); } uint32_t CPDF_Parser::GetLastObjNum() const { @@ -352,7 +357,8 @@ bool CPDF_Parser::LoadAllCrossRefV4(FX_FILESIZE xrefpos) { CrossRefList.insert(CrossRefList.begin(), xrefpos); LoadCrossRefV4(xrefpos, 0, true); - std::unique_ptr<CPDF_Dictionary> pDict(LoadTrailerV4()); + std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict( + LoadTrailerV4()); if (!pDict) return false; @@ -406,7 +412,8 @@ bool CPDF_Parser::LoadLinearizedAllCrossRefV4(FX_FILESIZE xrefpos, CrossRefList.insert(CrossRefList.begin(), xrefpos); LoadCrossRefV4(xrefpos, 0, true); - std::unique_ptr<CPDF_Dictionary> pDict(LoadTrailerV4()); + std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict( + LoadTrailerV4()); if (!pDict) return false; @@ -583,14 +590,18 @@ bool CPDF_Parser::LoadAllCrossRefV5(FX_FILESIZE xrefpos) { bool CPDF_Parser::RebuildCrossRef() { m_ObjectInfo.clear(); m_SortedOffset.clear(); - delete m_pTrailer; - m_pTrailer = nullptr; + if (m_pTrailer) { + m_pTrailer->Release(); + m_pTrailer = nullptr; + } ParserState state = ParserState::kDefault; + int32_t inside_index = 0; uint32_t objnum = 0; uint32_t gennum = 0; int32_t depth = 0; + const uint32_t kBufferSize = 4096; std::vector<uint8_t> buffer(kBufferSize); @@ -744,7 +755,8 @@ bool CPDF_Parser::RebuildCrossRef() { CPDF_Object* pRoot = pDict->GetObjectFor("Root"); if (pRoot && pRoot->GetDict() && pRoot->GetDict()->GetObjectFor("Pages")) { - delete m_pTrailer; + if (m_pTrailer) + m_pTrailer->Release(); m_pTrailer = ToDictionary(pDict->Clone()); } } @@ -782,7 +794,8 @@ bool CPDF_Parser::RebuildCrossRef() { m_ObjectInfo[objnum].gennum = gennum; } - delete pObject; + if (pObject) + pObject->Release(); } --i; state = ParserState::kDefault; @@ -799,7 +812,7 @@ bool CPDF_Parser::RebuildCrossRef() { CPDF_Object* pObj = m_pSyntax->GetObject(m_pDocument, 0, 0, true); if (pObj) { if (!pObj->IsDictionary() && !pObj->AsStream()) { - delete pObj; + pObj->Release(); } else { CPDF_Stream* pStream = pObj->AsStream(); if (CPDF_Dictionary* pTrailer = @@ -825,11 +838,11 @@ bool CPDF_Parser::RebuildCrossRef() { } } } - delete pObj; + pObj->Release(); } else { if (pObj->IsStream()) { m_pTrailer = ToDictionary(pTrailer->Clone()); - delete pObj; + pObj->Release(); } else { m_pTrailer = pTrailer; } @@ -846,7 +859,7 @@ bool CPDF_Parser::RebuildCrossRef() { m_pSyntax->RestorePos(dwSavePos); } } else { - delete pObj; + pObj->Release(); } } } @@ -1405,7 +1418,7 @@ CPDF_Dictionary* CPDF_Parser::LoadTrailerV4() { if (m_pSyntax->GetKeyword() != "trailer") return nullptr; - std::unique_ptr<CPDF_Object> pObj( + std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pObj( m_pSyntax->GetObject(m_pDocument, 0, 0, true)); if (!ToDictionary(pObj.get())) return nullptr; @@ -1457,7 +1470,7 @@ bool CPDF_Parser::IsLinearizedFile(IFX_SeekableReadStream* pFileAccess, CPDF_Object* pLen = pDict->GetObjectFor("L"); if (!pLen) { - delete m_pLinearized; + m_pLinearized->Release(); m_pLinearized = nullptr; return false; } @@ -1473,7 +1486,7 @@ bool CPDF_Parser::IsLinearizedFile(IFX_SeekableReadStream* pFileAccess, return true; } - delete m_pLinearized; + m_pLinearized->Release(); m_pLinearized = nullptr; return false; } @@ -1582,11 +1595,12 @@ bool CPDF_Parser::LoadLinearizedAllCrossRefV5(FX_FILESIZE xrefpos) { CPDF_Parser::Error CPDF_Parser::LoadLinearizedMainXRefTable() { uint32_t dwSaveMetadataObjnum = m_pSyntax->m_MetadataObjnum; m_pSyntax->m_MetadataObjnum = 0; + if (m_pTrailer) { + m_pTrailer->Release(); + m_pTrailer = nullptr; + } - delete m_pTrailer; - m_pTrailer = nullptr; m_pSyntax->RestorePos(m_LastXRefOffset - m_pSyntax->m_HeaderOffset); - uint8_t ch = 0; uint32_t dwCount = 0; m_pSyntax->GetNextChar(ch); |