Skip to content

Commit

Permalink
Subtract stream.start when getting the startXRef property for doc…
Browse files Browse the repository at this point in the history
…uments 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.
  • Loading branch information
Snuffleupagus committed Nov 16, 2019
1 parent f7aafcb commit 9199b02
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/issue11330.pdf.link
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/~https://github.com/mozilla/pdf.js/files/3844109/9069_10755570.1.pdf
8 changes: 8 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 9199b02

Please sign in to comment.