From b531fc4106b64f792ebfde49178096a1b982d3a1 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 12 Jan 2019 20:31:23 +0100 Subject: [PATCH] Avoid truncating inline images, where the data and the "EI" marker is glued together (issue 10388) (#10436) Thanks to the *excellent* debugging done by @janpe2, this was easy to fix! --- src/core/parser.js | 13 ++++++++++++- test/pdfs/.gitignore | 1 + test/pdfs/issue10388_reduced.pdf | Bin 0 -> 1127 bytes test/test_manifest.json | 7 +++++++ 4 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 test/pdfs/issue10388_reduced.pdf diff --git a/src/core/parser.js b/src/core/parser.js index 10b8b0c5f..c0a76bbb6 100644 --- a/src/core/parser.js +++ b/src/core/parser.js @@ -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. diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index f1f0bd85c..ad6cec7f2 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -72,6 +72,7 @@ !issue9458.pdf !issue9915_reduced.pdf !issue9940.pdf +!issue10388_reduced.pdf !issue10438_reduced.pdf !bad-PageLabels.pdf !decodeACSuccessive.pdf diff --git a/test/pdfs/issue10388_reduced.pdf b/test/pdfs/issue10388_reduced.pdf new file mode 100644 index 0000000000000000000000000000000000000000..44eac0d89cce631cbe4befd0a013dd39320c1761 GIT binary patch literal 1127 zcmah|&1(}u6fc&bj0S?Gh$kONj?K(wb~n3_1l&!QhFTlbpnGV1*SO~ z+P``x+#MctMvM(A7>6Z@AX(-T@J^(&S2lXrD8XRRbWTA+!As|D|1u$ee+B^T#EG!9ZYacmt~ zgX?x;ffmBsDZlkVv3l!6zGmI(>#mij5C;`iNVhJ(sM9X6{|X9r)y$hBPAzbP1aFBZ{&n4K%=PZ@#Wt(PI>QK9E>cp|kTscei+#S<0jUxQtM6B7m|BQ*Y T#8=1-qPS0nqN8-Wyyl?4;8Ht1 literal 0 HcmV?d00001 diff --git a/test/test_manifest.json b/test/test_manifest.json index f3aaffd80..60c981d2b 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -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",