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:
commit
c78eebbace
5 changed files with 34 additions and 1 deletions
|
@ -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.");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue