Skip to content

Commit afcc99a

Browse files
committed
When parsing corrupt documents without any trailer-dictionary, fallback to the "top"-dictionary (issue 14269)
There's obviously no guarantee that this will work in general, if the document is sufficiently corrupt, but it should hopefully be better than just throwing `InvalidPDFException` as currently happens. Please note that, as is often the case with corrupt documents, it's somewhat difficult to know if we're rendering the document "correctly" with this patch[1]. In this case even Adobe Reader cannot open the document, which is always a good sign that it's *really* corrupt, however we're at least able to render *something* with this patch. --- [1] Whatever "correct" even means when dealing with corrupt PDF documents, where often times different PDF viewers won't agree completely.
1 parent 28fb397 commit afcc99a

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

src/core/xref.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,10 @@ class XRef {
590590
if (trailerDict) {
591591
return trailerDict;
592592
}
593+
// No trailer dictionary found, taking the "top"-dictionary (if exists).
594+
if (this.topDict) {
595+
return this.topDict;
596+
}
593597
// nothing helps
594598
throw new InvalidPDFException("Invalid PDF structure.");
595599
}
@@ -680,6 +684,8 @@ class XRef {
680684
throw e;
681685
}
682686
info("(while reading XRef): " + e);
687+
688+
this.startXRefQueue.shift();
683689
}
684690

685691
if (recoveryMode) {

test/pdfs/issue14269.pdf.link

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/mozilla/pdf.js/files/7529789/test.pdf

test/test_manifest.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@
9191
"rounds": 1,
9292
"type": "eq"
9393
},
94+
{ "id": "issue14269",
95+
"file": "pdfs/issue14269.pdf",
96+
"md5": "f34abf77a418f54e13fbcd03b063432e",
97+
"rounds": 1,
98+
"link": true,
99+
"lastPage": 1,
100+
"type": "eq"
101+
},
94102
{ "id": "issue11549",
95103
"file": "pdfs/issue11549_reduced.pdf",
96104
"md5": "a1ea636f413e02e10dbdf379ab4a99ae",

0 commit comments

Comments
 (0)