[poppler] poppler/PDFDoc.cc

Albert Astals Cid aacid at kemper.freedesktop.org
Fri Jan 2 08:24:12 PST 2015


 poppler/PDFDoc.cc |   38 ++++++++++++++++++++++----------------
 1 file changed, 22 insertions(+), 16 deletions(-)

New commits:
commit 173f182fb568843f97e7d45d1b16bebbd2aa7413
Author: Li Junling <lijunling at sina.com>
Date:   Fri Jan 2 17:23:24 2015 +0100

    Find last 'startxref' in the last 24K instead of the last 1K
    
    Bug #85919

diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc
index ec8d3df..b6af8e8 100644
--- a/poppler/PDFDoc.cc
+++ b/poppler/PDFDoc.cc
@@ -1820,27 +1820,33 @@ Goffset PDFDoc::getStartXRef(GBool tryingToReconstruct)
       int c, n, i;
 
       // read last xrefSearchSize bytes
-      str->setPos(xrefSearchSize, -1);
-      for (n = 0; n < xrefSearchSize; ++n) {
-        if ((c = str->getChar()) == EOF) {
-          break;
+      int segnum = 0;
+      int maxXRefSearch = 24576;
+      if (str->getLength() < maxXRefSearch) maxXRefSearch = str->getLength();
+      for (; (xrefSearchSize - 16) * segnum < maxXRefSearch; segnum++) {
+        str->setPos((xrefSearchSize - 16) * segnum + xrefSearchSize, -1);
+        for (n = 0; n < xrefSearchSize; ++n) {
+          if ((c = str->getChar()) == EOF) {
+            break;
+          }
+          buf[n] = c;
         }
-        buf[n] = c;
-      }
-      buf[n] = '\0';
+        buf[n] = '\0';
 
-      // find startxref
-      for (i = n - 9; i >= 0; --i) {
-        if (!strncmp(&buf[i], "startxref", 9)) {
+        // find startxref
+        for (i = n - 9; i >= 0; --i) {
+          if (!strncmp(&buf[i], "startxref", 9)) {
+            break;
+          }
+        }
+        if (i < 0) {
+          startXRefPos = 0;
+        } else {
+          for (p = &buf[i + 9]; isspace(*p); ++p);
+          startXRefPos = strToLongLong(p);
           break;
         }
       }
-      if (i < 0) {
-        startXRefPos = 0;
-      } else {
-        for (p = &buf[i+9]; isspace(*p); ++p) ;
-        startXRefPos =  strToLongLong(p);
-      }
     }
 
   }


More information about the poppler mailing list