1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 22:58:07 +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:
Jonas Jenwald 2024-11-05 16:42:31 +01:00
parent cefd1ebcd2
commit e92a929a58
5 changed files with 34 additions and 1 deletions

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();