diff --git a/poppler/XRef.cc b/poppler/XRef.cc index 1bbbdc5..a0546b1 100644 --- a/poppler/XRef.cc +++ b/poppler/XRef.cc @@ -297,6 +297,7 @@ void XRef::init() { ownerPasswordOk = gFalse; rootNum = -1; strOwner = gFalse; + xrefReconstructed = gFalse; } XRef::XRef() { @@ -1610,7 +1611,10 @@ XRefEntry *XRef::getEntry(int i, GBool complainIfMissing) if ((!xRefStream) && mainXRefEntriesOffset) { if (!parseEntry(mainXRefEntriesOffset + 20*i, &entries[i])) { - error(errSyntaxError, -1, "Failed to parse XRef entry [{0:d}].", i); + rootNum = -1; + if (xrefReconstructed || !(ok = constructXRef(&xrefReconstructed))) { + error(errSyntaxError, -1, "Failed to parse XRef entry [{0:d}].", i); + } } } else { // Read XRef tables until the entry we're looking for is found @@ -1628,10 +1632,16 @@ XRefEntry *XRef::getEntry(int i, GBool complainIfMissing) } if (entries[i].type == xrefEntryNone) { - if (complainIfMissing) { - error(errSyntaxError, -1, "Invalid XRef entry"); + if (!xrefReconstructed) { + rootNum = -1; + constructXRef(&xrefReconstructed); + } + if (entries[i].type == xrefEntryNone) { + if (complainIfMissing) { + error(errSyntaxError, -1, "Invalid XRef entry"); + } + entries[i].type = xrefEntryFree; } - entries[i].type = xrefEntryFree; } } } diff --git a/poppler/XRef.h b/poppler/XRef.h index 70065d8..56231ef 100644 --- a/poppler/XRef.h +++ b/poppler/XRef.h @@ -201,6 +201,7 @@ private: int rootNum, rootGen; // catalog dict GBool ok; // true if xref table is valid int errCode; // error code (if is false) + GBool xrefReconstructed; // marker, true if xref was already reconstructed Object trailerDict; // trailer dictionary Goffset *streamEnds; // 'endstream' positions - only used in // damaged files