Skip to content

Commit

Permalink
Avoid truncating inline images, where the data and the "EI" marker is…
Browse files Browse the repository at this point in the history
… glued together (issue 10388) (#10436)

Thanks to the *excellent* debugging done by @janpe2, this was easy to fix!
  • Loading branch information
Snuffleupagus authored and timvandermeij committed Jan 12, 2019
1 parent eb7cd88 commit b531fc4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/core/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,18 @@ var Parser = (function ParserClosure() {
stream.skip(-(stream.pos - maybeEIPos)); // Reset the stream position.
}
}
return ((stream.pos - 4) - startPos);

let endOffset = 4;
stream.skip(-endOffset); // Set the stream position to just before "EI".
ch = stream.peekByte();
stream.skip(endOffset); // ... and remember to reset the stream position.

// Ensure that we don't accidentally truncate the inline image, when the
// data is immediately followed by the "EI" marker (fixes issue10388.pdf).
if (!isSpace(ch)) {
endOffset--;
}
return ((stream.pos - endOffset) - startPos);
},
/**
* Find the EOI (end-of-image) marker 0xFFD9 of the stream.
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
!issue9458.pdf
!issue9915_reduced.pdf
!issue9940.pdf
!issue10388_reduced.pdf
!issue10438_reduced.pdf
!bad-PageLabels.pdf
!decodeACSuccessive.pdf
Expand Down
Binary file added test/pdfs/issue10388_reduced.pdf
Binary file not shown.
7 changes: 7 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,13 @@
"link": true,
"type": "load"
},
{ "id": "issue10388",
"file": "pdfs/issue10388_reduced.pdf",
"md5": "62a6b2adbea1535432bd94a3516e2d4c",
"rounds": 1,
"link": false,
"type": "eq"
},
{ "id": "issue7507",
"file": "pdfs/issue7507.pdf",
"md5": "f7aeaafe0c89b94436e94eaa63307303",
Expand Down

0 comments on commit b531fc4

Please sign in to comment.