mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-23 08:38:06 +02:00
Try to improve handling of missing trailer dictionaries in XRef.indexObjects
(issue 18986)
The problem with the referenced PDF document has nothing to do with invalid dates, as the issue seems to suggest, but rather with the fact that it has neither an XRef table nor a trailer dictionary. Given that crucial parts of the internal document structure is missing, you might argue that it's not really a PDF document. In an attempt to support this kind of corruption, we'll simply iterate through all (previously found) XRef entries and pick one that *might* be a valid /Root dictionary. There's obviously no guarantee that this works, and it might not be fast in larger PDF documents, but at least it cannot be any worse than *immediately* throwing `InvalidPDFException` as we previously did here. *Please note:* I'm totally fine with this patch being rejected, since it's somewhat questionable if we should actually attempt to support "PDF documents" with this level of corruption.
This commit is contained in:
parent
cefd1ebcd2
commit
e92a929a58
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