| Index: core/fpdfapi/parser/cpdf_parser.cpp
|
| diff --git a/core/fpdfapi/parser/cpdf_parser.cpp b/core/fpdfapi/parser/cpdf_parser.cpp
|
| index c8c07bd0b7053f02e7e0cae312bae97bb71359cf..aa37a2d8835bb80bbca022f8a8ba9bae11ad312e 100644
|
| --- a/core/fpdfapi/parser/cpdf_parser.cpp
|
| +++ b/core/fpdfapi/parser/cpdf_parser.cpp
|
| @@ -54,7 +54,6 @@ CPDF_Parser::CPDF_Parser()
|
| m_pTrailer(nullptr),
|
| m_pEncryptDict(nullptr),
|
| m_bVersionUpdated(false),
|
| - m_pLinearized(nullptr),
|
| m_dwFirstPageNo(0),
|
| m_dwXrefStartObjNum(0) {
|
| m_pSyntax.reset(new CPDF_SyntaxParser);
|
| @@ -72,8 +71,6 @@ CPDF_Parser::~CPDF_Parser() {
|
|
|
| for (CPDF_Dictionary* trailer : m_Trailers)
|
| delete trailer;
|
| -
|
| - delete m_pLinearized;
|
| }
|
|
|
| uint32_t CPDF_Parser::GetLastObjNum() const {
|
| @@ -734,9 +731,10 @@ bool CPDF_Parser::RebuildCrossRef() {
|
| m_SortedOffset.insert(obj_pos);
|
| last_obj = start_pos;
|
| FX_FILESIZE obj_end = 0;
|
| - CPDF_Object* pObject = ParseIndirectObjectAtByStrict(
|
| - m_pDocument, obj_pos, objnum, &obj_end);
|
| - if (CPDF_Stream* pStream = ToStream(pObject)) {
|
| + std::unique_ptr<CPDF_Object> pObject =
|
| + ParseIndirectObjectAtByStrict(m_pDocument, obj_pos, objnum,
|
| + &obj_end);
|
| + if (CPDF_Stream* pStream = ToStream(pObject.get())) {
|
| if (CPDF_Dictionary* pDict = pStream->GetDict()) {
|
| if ((pDict->KeyExist("Type")) &&
|
| (pDict->GetStringFor("Type") == "XRef" &&
|
| @@ -781,8 +779,6 @@ bool CPDF_Parser::RebuildCrossRef() {
|
| m_ObjectInfo[objnum].type = 1;
|
| m_ObjectInfo[objnum].gennum = gennum;
|
| }
|
| -
|
| - delete pObject;
|
| }
|
| --i;
|
| state = ParserState::kDefault;
|
| @@ -796,11 +792,10 @@ bool CPDF_Parser::RebuildCrossRef() {
|
| last_trailer = pos + i - 7;
|
| m_pSyntax->RestorePos(pos + i - m_pSyntax->m_HeaderOffset);
|
|
|
| - CPDF_Object* pObj = m_pSyntax->GetObject(m_pDocument, 0, 0, true);
|
| + std::unique_ptr<CPDF_Object> pObj =
|
| + m_pSyntax->GetObject(m_pDocument, 0, 0, true);
|
| if (pObj) {
|
| - if (!pObj->IsDictionary() && !pObj->AsStream()) {
|
| - delete pObj;
|
| - } else {
|
| + if (pObj->IsDictionary() || pObj->AsStream()) {
|
| CPDF_Stream* pStream = pObj->AsStream();
|
| if (CPDF_Dictionary* pTrailer =
|
| pStream ? pStream->GetDict() : pObj->AsDictionary()) {
|
| @@ -825,11 +820,9 @@ bool CPDF_Parser::RebuildCrossRef() {
|
| }
|
| }
|
| }
|
| - delete pObj;
|
| } else {
|
| if (pObj->IsStream()) {
|
| m_pTrailer = ToDictionary(pTrailer->Clone());
|
| - delete pObj;
|
| } else {
|
| m_pTrailer = pTrailer;
|
| }
|
| @@ -845,8 +838,6 @@ bool CPDF_Parser::RebuildCrossRef() {
|
| }
|
| m_pSyntax->RestorePos(dwSavePos);
|
| }
|
| - } else {
|
| - delete pObj;
|
| }
|
| }
|
| }
|
| @@ -1090,7 +1081,7 @@ CPDF_Array* CPDF_Parser::GetIDArray() {
|
| return nullptr;
|
|
|
| if (CPDF_Reference* pRef = pID->AsReference()) {
|
| - pID = ParseIndirectObject(nullptr, pRef->GetRefObjNum());
|
| + pID = ParseIndirectObject(nullptr, pRef->GetRefObjNum()).release();
|
| m_pTrailer->SetFor("ID", pID);
|
| }
|
| return ToArray(pID);
|
| @@ -1108,7 +1099,7 @@ uint32_t CPDF_Parser::GetInfoObjNum() {
|
| return pRef ? pRef->GetRefObjNum() : 0;
|
| }
|
|
|
| -CPDF_Object* CPDF_Parser::ParseIndirectObject(
|
| +std::unique_ptr<CPDF_Object> CPDF_Parser::ParseIndirectObject(
|
| CPDF_IndirectObjectHolder* pObjList,
|
| uint32_t objnum) {
|
| if (!IsValidObjectNumber(objnum))
|
| @@ -1311,7 +1302,7 @@ void CPDF_Parser::GetIndirectBinary(uint32_t objnum,
|
| m_pSyntax->RestorePos(SavedPos);
|
| }
|
|
|
| -CPDF_Object* CPDF_Parser::ParseIndirectObjectAt(
|
| +std::unique_ptr<CPDF_Object> CPDF_Parser::ParseIndirectObjectAt(
|
| CPDF_IndirectObjectHolder* pObjList,
|
| FX_FILESIZE pos,
|
| uint32_t objnum) {
|
| @@ -1344,7 +1335,7 @@ CPDF_Object* CPDF_Parser::ParseIndirectObjectAt(
|
| return nullptr;
|
| }
|
|
|
| - CPDF_Object* pObj =
|
| + std::unique_ptr<CPDF_Object> pObj =
|
| m_pSyntax->GetObject(pObjList, objnum, parser_gennum, true);
|
| m_pSyntax->SavePos();
|
|
|
| @@ -1361,7 +1352,7 @@ CPDF_Object* CPDF_Parser::ParseIndirectObjectAt(
|
| return pObj;
|
| }
|
|
|
| -CPDF_Object* CPDF_Parser::ParseIndirectObjectAtByStrict(
|
| +std::unique_ptr<CPDF_Object> CPDF_Parser::ParseIndirectObjectAtByStrict(
|
| CPDF_IndirectObjectHolder* pObjList,
|
| FX_FILESIZE pos,
|
| uint32_t objnum,
|
| @@ -1394,7 +1385,9 @@ CPDF_Object* CPDF_Parser::ParseIndirectObjectAtByStrict(
|
| return nullptr;
|
| }
|
|
|
| - CPDF_Object* pObj = m_pSyntax->GetObjectForStrict(pObjList, objnum, gennum);
|
| + std::unique_ptr<CPDF_Object> pObj =
|
| + m_pSyntax->GetObjectForStrict(pObjList, objnum, gennum);
|
| +
|
| if (pResultPos)
|
| *pResultPos = m_pSyntax->m_Pos;
|
|
|
| @@ -1453,30 +1446,29 @@ bool CPDF_Parser::IsLinearizedFile(IFX_SeekableReadStream* pFileAccess,
|
| return false;
|
|
|
| CPDF_Dictionary* pDict = m_pLinearized->GetDict();
|
| - if (pDict && pDict->GetObjectFor("Linearized")) {
|
| - m_pSyntax->GetNextWord(nullptr);
|
| + if (!pDict || !pDict->GetObjectFor("Linearized")) {
|
| + m_pLinearized.reset();
|
| + return false;
|
| + }
|
|
|
| - CPDF_Object* pLen = pDict->GetObjectFor("L");
|
| - if (!pLen) {
|
| - delete m_pLinearized;
|
| - m_pLinearized = nullptr;
|
| - return false;
|
| - }
|
| + m_pSyntax->GetNextWord(nullptr);
|
|
|
| - if (pLen->GetInteger() != (int)pFileAccess->GetSize())
|
| - return false;
|
| + CPDF_Object* pLen = pDict->GetObjectFor("L");
|
| + if (!pLen) {
|
| + m_pLinearized.reset();
|
| + return false;
|
| + }
|
|
|
| - if (CPDF_Number* pNo = ToNumber(pDict->GetObjectFor("P")))
|
| - m_dwFirstPageNo = pNo->GetInteger();
|
| + if (pLen->GetInteger() != (int)pFileAccess->GetSize())
|
| + return false;
|
|
|
| - if (CPDF_Number* pTable = ToNumber(pDict->GetObjectFor("T")))
|
| - m_LastXRefOffset = pTable->GetInteger();
|
| + if (CPDF_Number* pNo = ToNumber(pDict->GetObjectFor("P")))
|
| + m_dwFirstPageNo = pNo->GetInteger();
|
|
|
| - return true;
|
| - }
|
| - delete m_pLinearized;
|
| - m_pLinearized = nullptr;
|
| - return false;
|
| + if (CPDF_Number* pTable = ToNumber(pDict->GetObjectFor("T")))
|
| + m_LastXRefOffset = pTable->GetInteger();
|
| +
|
| + return true;
|
| }
|
|
|
| CPDF_Parser::Error CPDF_Parser::StartLinearizedParse(
|
|
|