From 9199b02a4250a54d54c2339204f60d6550d8fb89 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 16 Nov 2019 02:07:02 +0100 Subject: [PATCH] Subtract `stream.start` when getting the `startXRef` property for documents with a Linearization dictionary (issue 11330) For documents with a Linearization dictionary the computed `startXRef` position will be relative to the raw file, rather than the actual PDF document itself (which begins with `%PDF-`). Hence it's necessary to subtract `stream.start` in this case, since otherwise the `XRef.readXRef` method will increment the position too far resulting in parsing errors. --- src/core/document.js | 2 +- test/pdfs/issue11330.pdf.link | 1 + test/test_manifest.json | 8 ++++++++ 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 test/pdfs/issue11330.pdf.link diff --git a/src/core/document.js b/src/core/document.js index 5c899105b..354e4c5d6 100644 --- a/src/core/document.js +++ b/src/core/document.js @@ -453,7 +453,7 @@ class PDFDocument { // Find the end of the first object. stream.reset(); if (find(stream, 'endobj', 1024)) { - startXRef = stream.pos + 6; + startXRef = (stream.pos + 6) - stream.start; } } else { // Find `startxref` by checking backwards from the end of the file. diff --git a/test/pdfs/issue11330.pdf.link b/test/pdfs/issue11330.pdf.link new file mode 100644 index 000000000..e07d7fcac --- /dev/null +++ b/test/pdfs/issue11330.pdf.link @@ -0,0 +1 @@ +https://github.com/mozilla/pdf.js/files/3844109/9069_10755570.1.pdf diff --git a/test/test_manifest.json b/test/test_manifest.json index 5353191d5..f8a7badbe 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -2992,6 +2992,14 @@ "lastPage": 1, "type": "eq" }, + { "id": "issue11330", + "file": "pdfs/issue11330.pdf", + "md5": "03a8a53d4b0dc825e08554f5c0178308", + "rounds": 1, + "link": true, + "lastPage": 1, + "type": "eq" + }, { "id": "issue4890", "file": "pdfs/issue4890.pdf", "md5": "1666feb4cd26318c2bdbea6a175dce87",