summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorart-snake <art-snake@yandex-team.ru>2016-10-20 13:29:45 -0700
committerCommit bot <commit-bot@chromium.org>2016-10-20 13:29:45 -0700
commitef38283688c1ee7c08bcf4204cfb78e09c039782 (patch)
treee610f19e8b9a3a13b50a4f9a1b37ac33d1b21433
parent7403f8a2a0d87179a1ccd57ceccd2d84fa59c319 (diff)
downloadpdfium-chromium/2897.tar.xz
Fix loading page using hint tables.chromium/2897
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. R=npm, dsinclair Review-Url: https://chromiumcodereview.appspot.com/2437773003
-rw-r--r--BUILD.gn1
-rw-r--r--core/fpdfapi/parser/cpdf_data_avail.cpp11
-rw-r--r--core/fpdfapi/parser/cpdf_document.cpp4
-rw-r--r--core/fpdfapi/parser/cpdf_document_unittest.cpp42
4 files changed, 56 insertions, 2 deletions
diff --git a/BUILD.gn b/BUILD.gn
index 1af2c28c55..c9f85fa0ed 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -1634,6 +1634,7 @@ test("pdfium_unittests") {
"core/fpdfapi/page/fpdf_page_parser_old_unittest.cpp",
"core/fpdfapi/page/fpdf_page_parser_unittest.cpp",
"core/fpdfapi/parser/cpdf_array_unittest.cpp",
+ "core/fpdfapi/parser/cpdf_document_unittest.cpp",
"core/fpdfapi/parser/cpdf_object_unittest.cpp",
"core/fpdfapi/parser/cpdf_parser_unittest.cpp",
"core/fpdfapi/parser/cpdf_simple_parser_unittest.cpp",
diff --git a/core/fpdfapi/parser/cpdf_data_avail.cpp b/core/fpdfapi/parser/cpdf_data_avail.cpp
index e23aa8ecfb..e52d0611f9 100644
--- a/core/fpdfapi/parser/cpdf_data_avail.cpp
+++ b/core/fpdfapi/parser/cpdf_data_avail.cpp
@@ -1625,6 +1625,8 @@ CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::IsPageAvail(
nResult = m_pHintTables->CheckPage(dwPage, pHints);
if (nResult != DataAvailable)
return nResult;
+ // We should say to the document, which object is the page.
+ m_pDocument->SetPageObjNum(dwPage, GetPage(dwPage)->GetObjNum());
m_pagesLoadState.insert(dwPage);
return DataAvailable;
}
@@ -1763,11 +1765,18 @@ CPDF_Dictionary* CPDF_DataAvail::GetPage(int index) {
uint32_t dwObjNum = 0;
bool bPagePosGot = m_pHintTables->GetPagePos(index, &szPageStartPos,
&szPageLength, &dwObjNum);
+ if (!dwObjNum)
+ return nullptr;
+ // Page object already can be parsed in document.
+ CPDF_Object* pPageDict = m_pDocument->GetIndirectObject(dwObjNum);
+ if (pPageDict)
+ return pPageDict->GetDict();
+
if (!bPagePosGot)
return nullptr;
m_syntaxParser.InitParser(m_pFileRead, (uint32_t)szPageStartPos);
- CPDF_Object* pPageDict = ParseIndirectObjectAt(0, dwObjNum, m_pDocument);
+ pPageDict = ParseIndirectObjectAt(0, dwObjNum, m_pDocument);
if (!pPageDict)
return nullptr;
diff --git a/core/fpdfapi/parser/cpdf_document.cpp b/core/fpdfapi/parser/cpdf_document.cpp
index c5f64a790c..5f64c14d31 100644
--- a/core/fpdfapi/parser/cpdf_document.cpp
+++ b/core/fpdfapi/parser/cpdf_document.cpp
@@ -425,7 +425,9 @@ CPDF_Document::CPDF_Document(std::unique_ptr<CPDF_Parser> pParser)
CPDF_Document::~CPDF_Document() {
delete m_pDocPage;
- CPDF_ModuleMgr::Get()->GetPageModule()->ClearStockFont(this);
+ if (CPDF_ModuleMgr::Get()->GetPageModule()) {
+ CPDF_ModuleMgr::Get()->GetPageModule()->ClearStockFont(this);
+ }
m_pByteStringPool.DeleteObject(); // Make weak.
}
diff --git a/core/fpdfapi/parser/cpdf_document_unittest.cpp b/core/fpdfapi/parser/cpdf_document_unittest.cpp
new file mode 100644
index 0000000000..128b8d91c4
--- /dev/null
+++ b/core/fpdfapi/parser/cpdf_document_unittest.cpp
@@ -0,0 +1,42 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/fpdfapi/parser/cpdf_document.h"
+
+#include <memory>
+
+#include "core/fpdfapi/parser/cpdf_parser.h"
+#include "core/fpdfapi/parser/cpdf_dictionary.h"
+#include "core/fxcrt/fx_memory.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+using ScopedDictionary =
+ std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>>;
+
+} // namespace
+
+TEST(cpdf_document, 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).
+ std::unique_ptr<CPDF_Parser> parser(new CPDF_Parser());
+ CPDF_Document document(std::move(parser));
+ 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));
+}