Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fallback and try a *previous* generation if all else fails in XRef.indexObjects (issue 15577) #15589

Merged
merged 1 commit into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions src/core/xref.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,8 +556,15 @@ class XRef {
this.readXRef(/* recoveryMode */ true);
}
// finding main trailer
let trailerDict;
for (const trailer of trailers) {
let trailerDict, trailerError;
for (const trailer of [...trailers, "generationFallback", ...trailers]) {
if (trailer === "generationFallback") {
if (!trailerError) {
break; // No need to fallback if there were no validation errors.
}
this._generationFallback = true;
continue;
}
stream.pos = trailer;
const parser = new Parser({
lexer: new Lexer(stream),
Expand Down Expand Up @@ -590,6 +597,7 @@ class XRef {
}
// The top-level /Pages dictionary isn't obviously corrupt.
} catch (ex) {
trailerError = ex;
continue;
}
// taking the first one with 'ID'
Expand Down Expand Up @@ -780,7 +788,17 @@ class XRef {
const gen = ref.gen;
let num = ref.num;
if (xrefEntry.gen !== gen) {
throw new XRefEntryException(`Inconsistent generation in XRef: ${ref}`);
const msg = `Inconsistent generation in XRef: ${ref}`;
// Try falling back to a *previous* generation (fixes issue15577.pdf).
if (this._generationFallback && xrefEntry.gen < gen) {
warn(msg);
return this.fetchUncompressed(
Ref.get(num, xrefEntry.gen),
xrefEntry,
suppressEncryption
);
}
throw new XRefEntryException(msg);
}
const stream = this.stream.makeSubStream(
xrefEntry.offset + this.stream.start
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/issue15577.pdf.link
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/mozilla/pdf.js/files/9813960/hang-080214-152005-90.pdf
8 changes: 8 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,14 @@
"lastPage": 1,
"type": "eq"
},
{ "id": "issue15577",
"file": "pdfs/issue15577.pdf",
"md5": "6939244cf44b7b31ff960b58ed7e4004",
"link": true,
"rounds": 1,
"lastPage": 1,
"type": "eq"
},
{ "id": "hmm-pdf",
"file": "pdfs/hmm.pdf",
"md5": "e08467e60101ee5f4a59716e86db6dc9",
Expand Down