From 94df367590a2ccd4f799df8958ddc014f496edb1 Mon Sep 17 00:00:00 2001 From: Artem Strygin Date: Thu, 28 Sep 2017 18:14:15 +0300 Subject: 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 Reviewed-by: dsinclair --- core/fpdfapi/parser/cpdf_data_avail.cpp | 6 ++++-- fpdfsdk/fpdf_dataavail_embeddertest.cpp | 28 ++++++++++++++++++++++++++++ 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); +} -- cgit v1.2.3