From 54ee83eb125ff6bbf95a4e7a0e7ef2493e4aae4d Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 22 Sep 2016 10:11:27 +0200 Subject: [PATCH] Attempt to skip zero bytes at the end of Scan blocks when decoding JPEG images (issue 4090) --- src/core/jpg.js | 6 ++++++ test/pdfs/issue4090.pdf.link | 1 + test/test_manifest.json | 8 ++++++++ 3 files changed, 15 insertions(+) create mode 100644 test/pdfs/issue4090.pdf.link diff --git a/src/core/jpg.js b/src/core/jpg.js index e6bcdab2e..8aa96f929 100644 --- a/src/core/jpg.js +++ b/src/core/jpg.js @@ -365,6 +365,12 @@ var JpegImage = (function JpegImageClosure() { // find marker bitsCount = 0; marker = (data[offset] << 8) | data[offset + 1]; + // Some bad images seem to pad Scan blocks with zero bytes, skip past + // those to attempt to find a valid marker (fixes issue4090.pdf). + while (data[offset] === 0x00 && offset < data.length - 1) { + offset++; + marker = (data[offset] << 8) | data[offset + 1]; + } if (marker <= 0xFF00) { error('JPEG error: marker was not found'); } diff --git a/test/pdfs/issue4090.pdf.link b/test/pdfs/issue4090.pdf.link new file mode 100644 index 000000000..bcc5b3ceb --- /dev/null +++ b/test/pdfs/issue4090.pdf.link @@ -0,0 +1 @@ +http://web.archive.org/web/20160819222859/http://www.ets.org/Media/Tests/GRE/pdf/gre_research_validity_data.pdf diff --git a/test/test_manifest.json b/test/test_manifest.json index d3b86503c..7733a0477 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -639,6 +639,14 @@ "link": false, "type": "eq" }, + { "id": "issue4090", + "file": "pdfs/issue4090.pdf", + "md5": "8cec73e090985acf6094c683d7944425", + "rounds": 1, + "link": true, + "lastPage": 1, + "type": "eq" + }, { "id": "issue5202", "file": "pdfs/issue5202.pdf", "md5": "bb9cc69211112e66aab40828086a4e5a",