summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtem Strygin <art-snake@yandex-team.ru>2017-09-28 18:14:15 +0300
committerChromium commit bot <commit-bot@chromium.org>2017-09-28 15:24:28 +0000
commit94df367590a2ccd4f799df8958ddc014f496edb1 (patch)
treee1e3ca41b61ab7cd07e843bae53f0bcd6b18c25a
parent0ec10f94ae0ec1927c4a33cd69eac0a5fbdcbd52 (diff)
downloadpdfium-94df367590a2ccd4f799df8958ddc014f496edb1.tar.xz
Fix load non first pages in linearized document with hints table.
Tha problem was, that when we use hints tables, we do not check pages tree availability, but currently for receiving page object in CPDF_Document, the pages tree should be available anyway. Change-Id: I908d00027fd8727f074a38e47fea095229ef5147 Reviewed-on: https://pdfium-review.googlesource.com/11892 Commit-Queue: Art Snake <art-snake@yandex-team.ru> Reviewed-by: dsinclair <dsinclair@chromium.org>
-rw-r--r--core/fpdfapi/parser/cpdf_data_avail.cpp6
-rw-r--r--fpdfsdk/fpdf_dataavail_embeddertest.cpp28
2 files changed, 32 insertions, 2 deletions
diff --git a/core/fpdfapi/parser/cpdf_data_avail.cpp b/core/fpdfapi/parser/cpdf_data_avail.cpp
index ec865ba936..1db0470f37 100644
--- a/core/fpdfapi/parser/cpdf_data_avail.cpp
+++ b/core/fpdfapi/parser/cpdf_data_avail.cpp
@@ -1316,8 +1316,10 @@ CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::IsPageAvail(
nResult = m_pHintTables->CheckPage(dwPage);
if (nResult != DataAvailable)
return nResult;
- m_pagesLoadState.insert(dwPage);
- return GetPage(dwPage) ? DataAvailable : DataError;
+ if (GetPage(dwPage)) {
+ m_pagesLoadState.insert(dwPage);
+ return DataAvailable;
+ }
}
if (!m_bMainXRefLoadedOK) {
diff --git a/fpdfsdk/fpdf_dataavail_embeddertest.cpp b/fpdfsdk/fpdf_dataavail_embeddertest.cpp
index 281f08640e..c40f8579b6 100644
--- a/fpdfsdk/fpdf_dataavail_embeddertest.cpp
+++ b/fpdfsdk/fpdf_dataavail_embeddertest.cpp
@@ -265,3 +265,31 @@ TEST_F(FPDFDataAvailEmbeddertest,
EXPECT_TRUE(page);
FPDF_ClosePage(page);
}
+
+TEST_F(FPDFDataAvailEmbeddertest, LoadSecondPageIfLinearizedWithHints) {
+ TestAsyncLoader loader("feature_linearized_loading.pdf");
+ avail_ = FPDFAvail_Create(loader.file_avail(), loader.file_access());
+ ASSERT_EQ(PDF_DATA_AVAIL, FPDFAvail_IsDocAvail(avail_, loader.hints()));
+ document_ = FPDFAvail_GetDocument(avail_, nullptr);
+ ASSERT_TRUE(document_);
+
+ static constexpr uint32_t kSecondPageNum = 1;
+
+ // Prevent access to non requested data to coerce the parser to send new
+ // request for non available (non requested before) data.
+ loader.set_is_new_data_available(false);
+ loader.ClearRequestedSegments();
+
+ int status = PDF_DATA_NOTAVAIL;
+ while (status == PDF_DATA_NOTAVAIL) {
+ loader.FlushRequestedData();
+ status = FPDFAvail_IsPageAvail(avail_, kSecondPageNum, loader.hints());
+ }
+ EXPECT_EQ(PDF_DATA_AVAIL, status);
+
+ // Prevent loading data, while page loading.
+ loader.set_is_new_data_available(false);
+ FPDF_PAGE page = FPDF_LoadPage(document(), kSecondPageNum);
+ EXPECT_TRUE(page);
+ FPDF_ClosePage(page);
+}