From e13c4f887201e3cce33f927bfd6467e8e0263ea7 Mon Sep 17 00:00:00 2001 From: Artem Strygin Date: Tue, 8 Aug 2017 17:49:02 +0300 Subject: Unify CPDF_Parser::ParseIndirectObjectAtXXX methods. Change-Id: I9ee1da4d0a9751dae8d595b610cf77c074c22cdc Reviewed-on: https://pdfium-review.googlesource.com/10350 Reviewed-by: dsinclair Commit-Queue: Art Snake --- core/fpdfapi/parser/cpdf_parser.cpp | 61 +++++++++++-------------------------- core/fpdfapi/parser/cpdf_parser.h | 7 +++++ 2 files changed, 24 insertions(+), 44 deletions(-) diff --git a/core/fpdfapi/parser/cpdf_parser.cpp b/core/fpdfapi/parser/cpdf_parser.cpp index d669f24674..32c616c1c6 100644 --- a/core/fpdfapi/parser/cpdf_parser.cpp +++ b/core/fpdfapi/parser/cpdf_parser.cpp @@ -1378,6 +1378,15 @@ std::unique_ptr CPDF_Parser::ParseIndirectObjectAt( CPDF_IndirectObjectHolder* pObjList, FX_FILESIZE pos, uint32_t objnum) { + return ParseIndirectObjectAtInternal(pObjList, pos, objnum, false, nullptr); +} + +std::unique_ptr CPDF_Parser::ParseIndirectObjectAtInternal( + CPDF_IndirectObjectHolder* pObjList, + FX_FILESIZE pos, + uint32_t objnum, + bool strict_parse, + FX_FILESIZE* pResultPos) { FX_FILESIZE SavedPos = m_pSyntax->GetPos(); m_pSyntax->SetPos(pos); bool bIsNumber; @@ -1387,8 +1396,6 @@ std::unique_ptr CPDF_Parser::ParseIndirectObjectAt( return nullptr; } - FX_FILESIZE objOffset = m_pSyntax->GetPos(); - objOffset -= word.GetLength(); uint32_t parser_objnum = FXSYS_atoui(word.c_str()); if (objnum && parser_objnum != objnum) { m_pSyntax->SetPos(SavedPos); @@ -1408,19 +1415,20 @@ std::unique_ptr CPDF_Parser::ParseIndirectObjectAt( } std::unique_ptr pObj = - m_pSyntax->GetObject(pObjList, objnum, parser_gennum, true); - m_pSyntax->GetPos(); + strict_parse + ? m_pSyntax->GetObjectForStrict(pObjList, objnum, parser_gennum) + : m_pSyntax->GetObject(pObjList, objnum, parser_gennum, true); - CFX_ByteString bsWord = m_pSyntax->GetKeyword(); - if (bsWord == "endobj") - m_pSyntax->GetPos(); + if (pResultPos) + *pResultPos = m_pSyntax->m_Pos; - m_pSyntax->SetPos(SavedPos); if (pObj) { if (!objnum) pObj->m_ObjNum = parser_objnum; pObj->m_GenNum = parser_gennum; } + + m_pSyntax->SetPos(SavedPos); return pObj; } @@ -1429,42 +1437,7 @@ std::unique_ptr CPDF_Parser::ParseIndirectObjectAtByStrict( FX_FILESIZE pos, uint32_t objnum, FX_FILESIZE* pResultPos) { - FX_FILESIZE SavedPos = m_pSyntax->GetPos(); - m_pSyntax->SetPos(pos); - - bool bIsNumber; - CFX_ByteString word = m_pSyntax->GetNextWord(&bIsNumber); - if (!bIsNumber) { - m_pSyntax->SetPos(SavedPos); - return nullptr; - } - - uint32_t parser_objnum = FXSYS_atoui(word.c_str()); - if (objnum && parser_objnum != objnum) { - m_pSyntax->SetPos(SavedPos); - return nullptr; - } - - word = m_pSyntax->GetNextWord(&bIsNumber); - if (!bIsNumber) { - m_pSyntax->SetPos(SavedPos); - return nullptr; - } - - uint32_t gennum = FXSYS_atoui(word.c_str()); - if (m_pSyntax->GetKeyword() != "obj") { - m_pSyntax->SetPos(SavedPos); - return nullptr; - } - - std::unique_ptr pObj = - m_pSyntax->GetObjectForStrict(pObjList, objnum, gennum); - - if (pResultPos) - *pResultPos = m_pSyntax->m_Pos; - - m_pSyntax->SetPos(SavedPos); - return pObj; + return ParseIndirectObjectAtInternal(pObjList, pos, objnum, true, pResultPos); } uint32_t CPDF_Parser::GetFirstPageNo() const { diff --git a/core/fpdfapi/parser/cpdf_parser.h b/core/fpdfapi/parser/cpdf_parser.h index 189de168f4..c379905aed 100644 --- a/core/fpdfapi/parser/cpdf_parser.h +++ b/core/fpdfapi/parser/cpdf_parser.h @@ -187,6 +187,13 @@ class CPDF_Parser { uint32_t* start_obj_num_at_last_block); void MergeCrossRefObjectsData(const std::vector& objects); + std::unique_ptr ParseIndirectObjectAtInternal( + CPDF_IndirectObjectHolder* pObjList, + FX_FILESIZE pos, + uint32_t objnum, + bool strict_parse, + FX_FILESIZE* pResultPos); + CFX_UnownedPtr m_pDocument; bool m_bHasParsed; bool m_bXRefStream; -- cgit v1.2.3