From 461b1d93f717e248ceb3c1e1bbb8285ba3258f8c Mon Sep 17 00:00:00 2001 From: art-snake Date: Mon, 31 Oct 2016 12:25:30 -0700 Subject: Fix loading page using hint tables. When linearized document have hint table, The FPDFAvail_IsPageAvail return true, but FPDF_LoadPage return nullptr, for non first pages. This happens, bacause document not use hint tables, to load page. To fix this, I force save the page's ObjNum in document. This is restoring of original fix: https://codereview.chromium.org/2437773003/ Review-Url: https://codereview.chromium.org/2444903002 --- core/fpdfapi/parser/cpdf_document_unittest.cpp | 44 ++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 6 deletions(-) (limited to 'core/fpdfapi/parser/cpdf_document_unittest.cpp') diff --git a/core/fpdfapi/parser/cpdf_document_unittest.cpp b/core/fpdfapi/parser/cpdf_document_unittest.cpp index 799ecc694e..9336626f45 100644 --- a/core/fpdfapi/parser/cpdf_document_unittest.cpp +++ b/core/fpdfapi/parser/cpdf_document_unittest.cpp @@ -15,6 +15,9 @@ namespace { +using ScopedDictionary = + std::unique_ptr>; + CPDF_Dictionary* CreatePageTreeNode(CPDF_Array* kids, CPDF_Document* pDoc, int count) { @@ -35,13 +38,9 @@ CPDF_Dictionary* CreateNumberedPage(size_t number) { return page; } -} // namespace - class CPDF_TestDocumentForPages : public CPDF_Document { public: CPDF_TestDocumentForPages() : CPDF_Document(nullptr) { - CPDF_ModuleMgr* module_mgr = CPDF_ModuleMgr::Get(); - module_mgr->InitPageModule(); // Set up test CPDF_Array* zeroToTwo = new CPDF_Array(); zeroToTwo->AddReference(this, AddIndirectObject(CreateNumberedPage(0))); @@ -80,8 +79,18 @@ class CPDF_TestDocumentForPages : public CPDF_Document { std::unique_ptr> m_pOwnedRootDict; }; +} // namespace + +class cpdf_document_test : public testing::Test { + public: + void SetUp() override { + CPDF_ModuleMgr* module_mgr = CPDF_ModuleMgr::Get(); + module_mgr->InitPageModule(); + } + void TearDown() override {} +}; -TEST(cpdf_document, GetPages) { +TEST_F(cpdf_document_test, GetPages) { std::unique_ptr document = pdfium::MakeUnique(); for (int i = 0; i < 7; i++) { @@ -94,7 +103,7 @@ TEST(cpdf_document, GetPages) { EXPECT_FALSE(page); } -TEST(cpdf_document, GetPagesReverseOrder) { +TEST_F(cpdf_document_test, GetPagesReverseOrder) { std::unique_ptr document = pdfium::MakeUnique(); for (int i = 6; i >= 0; i--) { @@ -106,3 +115,26 @@ TEST(cpdf_document, GetPagesReverseOrder) { CPDF_Dictionary* page = document->GetPage(7); EXPECT_FALSE(page); } + +TEST_F(cpdf_document_test, UseCachedPageObjNumIfHaveNotPagesDict) { + // ObjNum can be added in CPDF_DataAvail::IsPageAvail, and PagesDict + // can be not exists in this case. + // (case, when hint table is used to page check in CPDF_DataAvail). + CPDF_Document document(pdfium::MakeUnique()); + ScopedDictionary dict(new CPDF_Dictionary()); + const int page_count = 100; + dict->SetIntegerFor("N", page_count); + document.LoadLinearizedDoc(dict.get()); + ASSERT_EQ(page_count, document.GetPageCount()); + CPDF_Object* page_stub = new CPDF_Dictionary(); + const uint32_t obj_num = document.AddIndirectObject(page_stub); + const int test_page_num = 33; + + EXPECT_FALSE(document.IsPageLoaded(test_page_num)); + EXPECT_EQ(nullptr, document.GetPage(test_page_num)); + + document.SetPageObjNum(test_page_num, obj_num); + + EXPECT_TRUE(document.IsPageLoaded(test_page_num)); + EXPECT_EQ(page_stub, document.GetPage(test_page_num)); +} -- cgit v1.2.3