1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 14:48:08 +02:00

Merge pull request #19007 from Snuffleupagus/issue-18986

Try to improve handling of missing trailer dictionaries in `XRef.indexObjects` (issue 18986)
This commit is contained in:
Jonas Jenwald 2024-11-05 21:45:27 +01:00 committed by GitHub
commit c78eebbace
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 34 additions and 1 deletions

View file

@ -680,6 +680,31 @@ class XRef {
if (this.topDict) {
return this.topDict;
}
// When no trailer dictionary candidate exists, try picking the first
// dictionary that contains a /Root entry (fixes issue18986.pdf).
if (!trailerDicts.length) {
for (const [num, entry] of this.entries.entries()) {
if (!entry) {
continue;
}
const ref = Ref.get(num, entry.gen);
let obj;
try {
obj = this.fetch(ref);
} catch {
continue;
}
if (obj instanceof BaseStream) {
obj = obj.dict;
}
if (obj instanceof Dict && obj.has("Root")) {
return obj;
}
}
}
// nothing helps
throw new InvalidPDFException("Invalid PDF structure.");
}

View file

@ -156,6 +156,7 @@
!bug1020858.pdf
!prefilled_f1040.pdf
!bug1050040.pdf
!issue18986.pdf
!bug1200096.pdf
!bug1068432.pdf
!issue12295.pdf

BIN
test/pdfs/issue18986.pdf Normal file

Binary file not shown.

View file

@ -4727,6 +4727,13 @@
"link": false,
"type": "eq"
},
{
"id": "issue18986",
"file": "pdfs/issue18986.pdf",
"md5": "e147084fabd9677366f6ae3586dd311b",
"rounds": 1,
"type": "load"
},
{
"id": "issue6652",
"file": "pdfs/issue6652.pdf",

View file

@ -623,7 +623,7 @@ describe("api", function () {
expect(false).toEqual(true);
} catch (reason) {
expect(reason instanceof InvalidPDFException).toEqual(true);
expect(reason.message).toEqual("Invalid PDF structure.");
expect(reason.message).toEqual("Invalid Root reference.");
}
await loadingTask.destroy();