From 0bf6961663ec38568b9323e66a8c808d9aa726fb Mon Sep 17 00:00:00 2001 From: Artem Strygin Date: Mon, 11 Sep 2017 16:35:02 +0300 Subject: Simplify CPDF_Parser::LoadCrossRefV4 Change-Id: Ie1170e71fb2d8f87857e68620f27e478a0801d21 Reviewed-on: https://pdfium-review.googlesource.com/13670 Reviewed-by: dsinclair Commit-Queue: Art Snake --- core/fpdfapi/parser/cpdf_parser.cpp | 22 ++++++++++++++-------- core/fpdfapi/parser/cpdf_parser.h | 2 +- core/fpdfapi/parser/cpdf_parser_unittest.cpp | 8 ++++---- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/core/fpdfapi/parser/cpdf_parser.cpp b/core/fpdfapi/parser/cpdf_parser.cpp index b0a8126a3d..9239c5f0d0 100644 --- a/core/fpdfapi/parser/cpdf_parser.cpp +++ b/core/fpdfapi/parser/cpdf_parser.cpp @@ -379,7 +379,7 @@ bool CPDF_Parser::VerifyCrossRefV4() { } bool CPDF_Parser::LoadAllCrossRefV4(FX_FILESIZE xrefpos) { - if (!LoadCrossRefV4(xrefpos, 0, true)) + if (!LoadCrossRefV4(xrefpos, true)) return false; std::unique_ptr trailer = LoadTrailerV4(); @@ -411,7 +411,7 @@ bool CPDF_Parser::LoadAllCrossRefV4(FX_FILESIZE xrefpos) { // SLOW ... CrossRefList.insert(CrossRefList.begin(), xrefpos); - LoadCrossRefV4(xrefpos, 0, true); + LoadCrossRefV4(xrefpos, true); std::unique_ptr pDict(LoadTrailerV4()); if (!pDict) @@ -426,8 +426,12 @@ bool CPDF_Parser::LoadAllCrossRefV4(FX_FILESIZE xrefpos) { } for (size_t i = 0; i < CrossRefList.size(); ++i) { - if (!LoadCrossRefV4(CrossRefList[i], XRefStreamList[i], false)) + if (!LoadCrossRefV4(CrossRefList[i], false)) return false; + + if (XRefStreamList[i] && !LoadCrossRefV5(&XRefStreamList[i], false)) + return false; + if (i == 0 && !VerifyCrossRefV4()) return false; } @@ -466,7 +470,7 @@ bool CPDF_Parser::LoadLinearizedAllCrossRefV4(FX_FILESIZE xrefpos, // SLOW ... CrossRefList.insert(CrossRefList.begin(), xrefpos); - LoadCrossRefV4(xrefpos, 0, true); + LoadCrossRefV4(xrefpos, true); std::unique_ptr pDict(LoadTrailerV4()); if (!pDict) @@ -481,7 +485,10 @@ bool CPDF_Parser::LoadLinearizedAllCrossRefV4(FX_FILESIZE xrefpos, } for (size_t i = 1; i < CrossRefList.size(); ++i) { - if (!LoadCrossRefV4(CrossRefList[i], XRefStreamList[i], false)) + if (!LoadCrossRefV4(CrossRefList[i], false)) + return false; + + if (XRefStreamList[i] && !LoadCrossRefV5(&XRefStreamList[i], false)) return false; } return true; @@ -622,7 +629,6 @@ bool CPDF_Parser::ParseCrossRefV4(std::vector* out_objects) { } bool CPDF_Parser::LoadCrossRefV4(FX_FILESIZE pos, - FX_FILESIZE streampos, bool bSkip) { m_pSyntax->SetPos(pos); std::vector objects; @@ -631,7 +637,7 @@ bool CPDF_Parser::LoadCrossRefV4(FX_FILESIZE pos, MergeCrossRefObjectsData(objects); - return !streampos || LoadCrossRefV5(&streampos, false); + return true; } void CPDF_Parser::MergeCrossRefObjectsData( @@ -1359,7 +1365,7 @@ CPDF_Parser::Error CPDF_Parser::StartLinearizedParse( FX_FILESIZE dwFirstXRefOffset = m_pSyntax->GetPos(); bool bXRefRebuilt = false; - bool bLoadV4 = LoadCrossRefV4(dwFirstXRefOffset, 0, false); + bool bLoadV4 = LoadCrossRefV4(dwFirstXRefOffset, false); if (!bLoadV4 && !LoadCrossRefV5(&dwFirstXRefOffset, true)) { if (!RebuildCrossRef()) return FORMAT_ERROR; diff --git a/core/fpdfapi/parser/cpdf_parser.h b/core/fpdfapi/parser/cpdf_parser.h index 20bd6be9b4..5cd1301ddd 100644 --- a/core/fpdfapi/parser/cpdf_parser.h +++ b/core/fpdfapi/parser/cpdf_parser.h @@ -122,7 +122,7 @@ class CPDF_Parser { std::unique_ptr m_pSyntax; std::map m_ObjectInfo; - bool LoadCrossRefV4(FX_FILESIZE pos, FX_FILESIZE streampos, bool bSkip); + bool LoadCrossRefV4(FX_FILESIZE pos, bool bSkip); bool RebuildCrossRef(); private: diff --git a/core/fpdfapi/parser/cpdf_parser_unittest.cpp b/core/fpdfapi/parser/cpdf_parser_unittest.cpp index 25c22c701b..d441b12cef 100644 --- a/core/fpdfapi/parser/cpdf_parser_unittest.cpp +++ b/core/fpdfapi/parser/cpdf_parser_unittest.cpp @@ -116,7 +116,7 @@ TEST(cpdf_parser, LoadCrossRefV4) { ASSERT_TRUE( parser.InitTestFromBuffer(xref_table, FX_ArraySize(xref_table))); - ASSERT_TRUE(parser.LoadCrossRefV4(0, 0, false)); + ASSERT_TRUE(parser.LoadCrossRefV4(0, false)); const FX_FILESIZE offsets[] = {0, 17, 81, 0, 331, 409}; const CPDF_Parser::ObjectType types[] = { CPDF_Parser::ObjectType::kFree, @@ -147,7 +147,7 @@ TEST(cpdf_parser, LoadCrossRefV4) { ASSERT_TRUE( parser.InitTestFromBuffer(xref_table, FX_ArraySize(xref_table))); - ASSERT_TRUE(parser.LoadCrossRefV4(0, 0, false)); + ASSERT_TRUE(parser.LoadCrossRefV4(0, false)); const FX_FILESIZE offsets[] = {0, 0, 0, 25325, 0, 0, 0, 0, 25518, 25635, 0, 0, 25777}; const CPDF_Parser::ObjectType types[] = { @@ -186,7 +186,7 @@ TEST(cpdf_parser, LoadCrossRefV4) { ASSERT_TRUE( parser.InitTestFromBuffer(xref_table, FX_ArraySize(xref_table))); - ASSERT_TRUE(parser.LoadCrossRefV4(0, 0, false)); + ASSERT_TRUE(parser.LoadCrossRefV4(0, false)); const FX_FILESIZE offsets[] = {0, 0, 0, 25325, 0, 0, 0, 0, 0, 25635, 0, 0, 25777}; const CPDF_Parser::ObjectType types[] = { @@ -224,7 +224,7 @@ TEST(cpdf_parser, LoadCrossRefV4) { ASSERT_TRUE( parser.InitTestFromBuffer(xref_table, FX_ArraySize(xref_table))); - ASSERT_TRUE(parser.LoadCrossRefV4(0, 0, false)); + ASSERT_TRUE(parser.LoadCrossRefV4(0, false)); const FX_FILESIZE offsets[] = {0, 23, 0, 0, 0, 45, 179}; const CPDF_Parser::ObjectType types[] = { CPDF_Parser::ObjectType::kFree, -- cgit v1.2.3