summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Astals Cid <aacid@kde.org>2014-02-26 22:09:44 +0100
committerAlbert Astals Cid <aacid@kde.org>2014-02-26 22:09:44 +0100
commitdb909c2a14f962234a813ba9853535b9692cfd5a (patch)
tree4de2b997673e93e44a26a1117b724887c71cc131
parentb2394eee5384edf4128d598030989e66d64714ef (diff)
Try harder to open broken files
Bug #75232
-rw-r--r--poppler/PDFDoc.cc33
-rw-r--r--poppler/PDFDoc.h8
2 files changed, 26 insertions, 15 deletions
diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc
index d7aae9fc..4f3ab311 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@frogmouth.net>
-// Copyright (C) 2005, 2007-2009, 2011-2013 Albert Astals Cid <aacid@kde.org>
+// Copyright (C) 2005, 2007-2009, 2011-2014 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2008 Julien Rebetez <julienr@svn.gnome.org>
// Copyright (C) 2008, 2010 Pino Toscano <pino@kde.org>
// Copyright (C) 2008, 2010, 2011 Carlos Garcia Campos <carlosgc@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 42c7cba7..1e5b8088 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@frogmouth.net>
-// Copyright (C) 2005, 2009 Albert Astals Cid <aacid@kde.org>
+// Copyright (C) 2005, 2009, 2014 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2008 Julien Rebetez <julienr@svn.gnome.org>
// Copyright (C) 2008 Pino Toscano <pino@kde.org>
// Copyright (C) 2008 Carlos Garcia Campos <carlosgc@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;