summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
authorArtem Strygin <art-snake@yandex-team.ru>2017-09-28 17:58:18 +0300
committerChromium commit bot <commit-bot@chromium.org>2017-09-28 15:10:48 +0000
commit0ec10f94ae0ec1927c4a33cd69eac0a5fbdcbd52 (patch)
tree57463da5d9d6fcf2aa310e0e9153078123edd977 /fpdfsdk
parent6e376202fca5c4f77645ba0eeee56ef3c44615a3 (diff)
downloadpdfium-0ec10f94ae0ec1927c4a33cd69eac0a5fbdcbd52.tar.xz
Fix infinite loop on form availability check.
The problem was, that the CPDF_SyntaxParser read last block not from requested position. In this case It move down requested position to fill whole buffer. As result this additional data was not requested by DownloadHints. To fix this allow resize data buffer in CPDF_SyntaxParser, to store more small block, and always read from requsted position. Also add reading check into CPDF_Parser::LoadLinearizedMainXRefTable to prevent infinite loops. Change-Id: I14d3f4457393025dca390aa3ceaa940716463534 Reviewed-on: https://pdfium-review.googlesource.com/11891 Commit-Queue: Art Snake <art-snake@yandex-team.ru> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/fpdf_dataavail_embeddertest.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/fpdfsdk/fpdf_dataavail_embeddertest.cpp b/fpdfsdk/fpdf_dataavail_embeddertest.cpp
index 8f37984c9b..281f08640e 100644
--- a/fpdfsdk/fpdf_dataavail_embeddertest.cpp
+++ b/fpdfsdk/fpdf_dataavail_embeddertest.cpp
@@ -63,6 +63,13 @@ class TestAsyncLoader : public FX_DOWNLOADHINTS, FX_FILEAVAIL {
return available_ranges_.empty() ? 0 : available_ranges_.rbegin()->second;
}
+ void FlushRequestedData() {
+ for (const auto& it : requested_segments_) {
+ SetDataAvailable(it.first, it.second);
+ }
+ ClearRequestedSegments();
+ }
+
private:
void SetDataAvailable(size_t start, size_t size) {
if (size == 0)
@@ -199,6 +206,26 @@ TEST_F(FPDFDataAvailEmbeddertest, LoadUsingHintTables) {
FPDF_ClosePage(page);
}
+TEST_F(FPDFDataAvailEmbeddertest, CheckFormAvailIfLinearized) {
+ 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_);
+
+ // 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_FORM_NOTAVAIL;
+ while (status == PDF_FORM_NOTAVAIL) {
+ loader.FlushRequestedData();
+ status = FPDFAvail_IsFormAvail(avail_, loader.hints());
+ }
+ EXPECT_NE(PDF_FORM_ERROR, status);
+}
+
TEST_F(FPDFDataAvailEmbeddertest,
DoNotLoadMainCrossRefForFirstPageIfLinearized) {
TestAsyncLoader loader("feature_linearized_loading.pdf");