summaryrefslogtreecommitdiff
path: root/core/fpdfapi
diff options
context:
space:
mode:
authorArtem Strygin <art-snake@yandex-team.ru>2017-08-08 17:49:02 +0300
committerChromium commit bot <commit-bot@chromium.org>2017-08-09 15:58:43 +0000
commite13c4f887201e3cce33f927bfd6467e8e0263ea7 (patch)
tree489ac669431db51f460a87e9ea3397124342620e /core/fpdfapi
parent23a824c69d098d17f788f73c273465d096d1fed0 (diff)
downloadpdfium-e13c4f887201e3cce33f927bfd6467e8e0263ea7.tar.xz
Unify CPDF_Parser::ParseIndirectObjectAtXXX methods.
Change-Id: I9ee1da4d0a9751dae8d595b610cf77c074c22cdc Reviewed-on: https://pdfium-review.googlesource.com/10350 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Art Snake <art-snake@yandex-team.ru>
Diffstat (limited to 'core/fpdfapi')
-rw-r--r--core/fpdfapi/parser/cpdf_parser.cpp61
-rw-r--r--core/fpdfapi/parser/cpdf_parser.h7
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_Object> CPDF_Parser::ParseIndirectObjectAt(
CPDF_IndirectObjectHolder* pObjList,
FX_FILESIZE pos,
uint32_t objnum) {
+ return ParseIndirectObjectAtInternal(pObjList, pos, objnum, false, nullptr);
+}
+
+std::unique_ptr<CPDF_Object> 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_Object> 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_Object> CPDF_Parser::ParseIndirectObjectAt(
}
std::unique_ptr<CPDF_Object> 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_Object> 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<CPDF_Object> 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<CrossRefObjData>& objects);
+ std::unique_ptr<CPDF_Object> ParseIndirectObjectAtInternal(
+ CPDF_IndirectObjectHolder* pObjList,
+ FX_FILESIZE pos,
+ uint32_t objnum,
+ bool strict_parse,
+ FX_FILESIZE* pResultPos);
+
CFX_UnownedPtr<CPDF_Document> m_pDocument;
bool m_bHasParsed;
bool m_bXRefStream;