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
@ -680,6 +680,31 @@ class XRef {
|
|||||||
if (this.topDict) {
|
if (this.topDict) {
|
||||||
return 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
|
// nothing helps
|
||||||
throw new InvalidPDFException("Invalid PDF structure.");
|
throw new InvalidPDFException("Invalid PDF structure.");
|
||||||
}
|
}
|
||||||
|
|||||||
1
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
@ -156,6 +156,7 @@
|
|||||||
!bug1020858.pdf
|
!bug1020858.pdf
|
||||||
!prefilled_f1040.pdf
|
!prefilled_f1040.pdf
|
||||||
!bug1050040.pdf
|
!bug1050040.pdf
|
||||||
|
!issue18986.pdf
|
||||||
!bug1200096.pdf
|
!bug1200096.pdf
|
||||||
!bug1068432.pdf
|
!bug1068432.pdf
|
||||||
!issue12295.pdf
|
!issue12295.pdf
|
||||||
|
|||||||
BIN
test/pdfs/issue18986.pdf
Normal file
BIN
test/pdfs/issue18986.pdf
Normal file
Binary file not shown.
@ -4727,6 +4727,13 @@
|
|||||||
"link": false,
|
"link": false,
|
||||||
"type": "eq"
|
"type": "eq"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "issue18986",
|
||||||
|
"file": "pdfs/issue18986.pdf",
|
||||||
|
"md5": "e147084fabd9677366f6ae3586dd311b",
|
||||||
|
"rounds": 1,
|
||||||
|
"type": "load"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "issue6652",
|
"id": "issue6652",
|
||||||
"file": "pdfs/issue6652.pdf",
|
"file": "pdfs/issue6652.pdf",
|
||||||
|
|||||||
@ -623,7 +623,7 @@ describe("api", function () {
|
|||||||
expect(false).toEqual(true);
|
expect(false).toEqual(true);
|
||||||
} catch (reason) {
|
} catch (reason) {
|
||||||
expect(reason instanceof InvalidPDFException).toEqual(true);
|
expect(reason instanceof InvalidPDFException).toEqual(true);
|
||||||
expect(reason.message).toEqual("Invalid PDF structure.");
|
expect(reason.message).toEqual("Invalid Root reference.");
|
||||||
}
|
}
|
||||||
|
|
||||||
await loadingTask.destroy();
|
await loadingTask.destroy();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user