1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-23 08:38:06 +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.");
}