From 945840bd067d9ca3179a667f48b451cc2087931b Mon Sep 17 00:00:00 2001
From: Tobias Koenig <tobias.koenig@kdab.com>
Date: Wed, 24 Aug 2016 14:10:09 +0200
Subject: [PATCH] Fix loading of large PDF documents

Call FPDFAvail_IsPageAvail multiple times and check return value,
otherwise the page won't be loaded completely.

Change-Id: I9a6de3443eec6819be9b6eaa2a5b054329da4f80
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
---
 src/pdf/qpdfdocument.cpp | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/pdf/qpdfdocument.cpp b/src/pdf/qpdfdocument.cpp
index 3ef947f88..709c702bf 100644
--- a/src/pdf/qpdfdocument.cpp
+++ b/src/pdf/qpdfdocument.cpp
@@ -251,9 +251,15 @@ void QPdfDocumentPrivate::checkComplete()
 
     QPdfMutexLocker lock;
 
-    for (int i = 0, count = FPDF_GetPageCount(doc); i < count; ++i)
-        if (!FPDFAvail_IsPageAvail(avail, i, this))
+    for (int i = 0, count = FPDF_GetPageCount(doc); i < count; ++i) {
+        int result = PDF_DATA_NOTAVAIL;
+        while (result == PDF_DATA_NOTAVAIL) {
+            result = FPDFAvail_IsPageAvail(avail, i, this);
+        }
+
+        if (result == PDF_DATA_ERROR)
             loadComplete = false;
+    }
 
     lock.unlock();
 
-- 
GitLab