[poppler] poppler/PDFDoc.cc poppler/PDFDoc.h

Albert Astals Cid aacid at kemper.freedesktop.org
Wed Feb 26 13:10:58 PST 2014


 poppler/PDFDoc.cc |   33 ++++++++++++++++++++++-----------
 poppler/PDFDoc.h  |    8 ++++----
 2 files changed, 26 insertions(+), 15 deletions(-)

New commits:
commit db909c2a14f962234a813ba9853535b9692cfd5a
Author: Albert Astals Cid <aacid at kde.org>
Date:   Wed Feb 26 22:09:44 2014 +0100

    Try harder to open broken files
    
    Bug #75232

diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc
index d7aae9f..4f3ab31 100644
--- a/poppler/PDFDoc.cc
+++ b/poppler/PDFDoc.cc
@@ -14,7 +14,7 @@
 // under GPL version 2 or later
 //
 // Copyright (C) 2005, 2006, 2008 Brad Hards <bradh at frogmouth.net>
-// Copyright (C) 2005, 2007-2009, 2011-2013 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2005, 2007-2009, 2011-2014 Albert Astals Cid <aacid at kde.org>
 // Copyright (C) 2008 Julien Rebetez <julienr at svn.gnome.org>
 // Copyright (C) 2008, 2010 Pino Toscano <pino at kde.org>
 // Copyright (C) 2008, 2010, 2011 Carlos Garcia Campos <carlosgc at gnome.org>
@@ -259,9 +259,16 @@ GBool PDFDoc::setup(GooString *ownerPassword, GooString *userPassword) {
   // read xref table
   xref = new XRef(str, getStartXRef(), getMainXRefEntriesOffset(), &wasReconstructed);
   if (!xref->isOk()) {
-    error(errSyntaxError, -1, "Couldn't read xref table");
-    errCode = xref->getErrorCode();
-    return gFalse;
+    if (wasReconstructed) {
+      delete xref;
+      startXRefPos = -1;
+      xref = new XRef(str, getStartXRef(gTrue), getMainXRefEntriesOffset(gTrue), &wasReconstructed);
+    }
+    if (!xref->isOk()) {
+      error(errSyntaxError, -1, "Couldn't read xref table");
+      errCode = xref->getErrorCode();
+      return gFalse;
+    }
   }
 
   // check for encryption
@@ -517,12 +524,16 @@ Linearization *PDFDoc::getLinearization()
   return linearization;
 }
 
-GBool PDFDoc::isLinearized() {
+GBool PDFDoc::isLinearized(GBool tryingToReconstruct) {
   if ((str->getLength()) &&
       (getLinearization()->getLength() == str->getLength()))
     return gTrue;
-  else
-    return gFalse;
+  else {
+    if (tryingToReconstruct)
+      return getLinearization()->getLength() > 0;
+    else
+      return gFalse;
+  }
 }
 
 static GBool
@@ -1635,11 +1646,11 @@ long long PDFDoc::strToLongLong(char *s) {
 }
 
 // Read the 'startxref' position.
-Goffset PDFDoc::getStartXRef()
+Goffset PDFDoc::getStartXRef(GBool tryingToReconstruct)
 {
   if (startXRefPos == -1) {
 
-    if (isLinearized()) {
+    if (isLinearized(tryingToReconstruct)) {
       char buf[linearizationSearchSize+1];
       int c, n, i;
 
@@ -1697,11 +1708,11 @@ Goffset PDFDoc::getStartXRef()
   return startXRefPos;
 }
 
-Goffset PDFDoc::getMainXRefEntriesOffset()
+Goffset PDFDoc::getMainXRefEntriesOffset(GBool tryingToReconstruct)
 {
   Guint mainXRefEntriesOffset = 0;
 
-  if (isLinearized()) {
+  if (isLinearized(tryingToReconstruct)) {
     mainXRefEntriesOffset = getLinearization()->getMainXRefEntriesOffset();
   }
 
diff --git a/poppler/PDFDoc.h b/poppler/PDFDoc.h
index 42c7cba..1e5b808 100644
--- a/poppler/PDFDoc.h
+++ b/poppler/PDFDoc.h
@@ -14,7 +14,7 @@
 // under GPL version 2 or later
 //
 // Copyright (C) 2005, 2006, 2008 Brad Hards <bradh at frogmouth.net>
-// Copyright (C) 2005, 2009 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2005, 2009, 2014 Albert Astals Cid <aacid at kde.org>
 // Copyright (C) 2008 Julien Rebetez <julienr at svn.gnome.org>
 // Copyright (C) 2008 Pino Toscano <pino at kde.org>
 // Copyright (C) 2008 Carlos Garcia Campos <carlosgc at gnome.org>
@@ -219,7 +219,7 @@ public:
 
 
   // Is this document linearized?
-  GBool isLinearized();
+  GBool isLinearized(GBool tryingToReconstruct = gFalse);
 
   // Return the document's Info dictionary (if any).
   Object *getDocInfo(Object *obj) { return xref->getDocInfo(obj); }
@@ -301,10 +301,10 @@ private:
   void checkHeader();
   GBool checkEncryption(GooString *ownerPassword, GooString *userPassword);
   // Get the offset of the start xref table.
-  Goffset getStartXRef();
+  Goffset getStartXRef(GBool tryingToReconstruct = gFalse);
   // Get the offset of the entries in the main XRef table of a
   // linearized document (0 for non linearized documents).
-  Goffset getMainXRefEntriesOffset();
+  Goffset getMainXRefEntriesOffset(GBool tryingToReconstruct = gFalse);
   long long strToLongLong(char *s);
 
   GooString *fileName;


More information about the poppler mailing list