From 5c0336872e02a71f4a92664eaa9d8e23e681f9b7 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 5 Dec 2019 15:44:51 +0100 Subject: [PATCH] Handle corrupt ASCII85Decode inline images with truncated EOD markers (issue 11385) In the PDF document in question, there's an ASCII85Decode inline image where the '>' part of EOD (end-of-data) marker is missing; hence the PDF document is corrupt. --- src/core/parser.js | 10 ++++++++++ test/pdfs/issue11385.pdf.link | 1 + test/test_manifest.json | 8 ++++++++ 3 files changed, 19 insertions(+) create mode 100644 test/pdfs/issue11385.pdf.link diff --git a/src/core/parser.js b/src/core/parser.js index 1768842968e35..010e9152a8b8c 100644 --- a/src/core/parser.js +++ b/src/core/parser.js @@ -344,6 +344,8 @@ class Parser { let startPos = stream.pos, ch, length; while ((ch = stream.getByte()) !== -1) { if (ch === TILDE) { + const tildePos = stream.pos; + ch = stream.peekByte(); // Handle corrupt PDF documents which contains whitespace "inside" of // the EOD marker (fixes issue10614.pdf). @@ -355,6 +357,14 @@ class Parser { stream.skip(); break; } + // Handle corrupt PDF documents which contains truncated EOD markers, + // where the '>' character is missing (fixes issue11385.pdf). + if (stream.pos > tildePos) { + const maybeEI = stream.peekBytes(2); + if (maybeEI[0] === /* E = */ 0x45 && maybeEI[1] === /* I = */ 0x49) { + break; + } + } } } length = stream.pos - startPos; diff --git a/test/pdfs/issue11385.pdf.link b/test/pdfs/issue11385.pdf.link new file mode 100644 index 0000000000000..7a3cd2c005540 --- /dev/null +++ b/test/pdfs/issue11385.pdf.link @@ -0,0 +1 @@ +https://github.com/mozilla/pdf.js/files/3926686/problematic.pdf diff --git a/test/test_manifest.json b/test/test_manifest.json index f8a7badbedba9..1bd45a6d1045d 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -1595,6 +1595,14 @@ "lastPage": 1, "type": "eq" }, + { "id": "issue11385", + "file": "pdfs/issue11385.pdf", + "md5": "cc04b23b845366857426a5aa6acf227b", + "rounds": 1, + "link": true, + "lastPage": 1, + "type": "eq" + }, { "id": "issue6071", "file": "pdfs/issue6071.pdf", "md5": "2e08526d8e7c9ba4269fc12ef488d3eb",