Skip to content

Commit

Permalink
Merge pull request #8170 from Snuffleupagus/issue-8169
Browse files Browse the repository at this point in the history
Try to recover when encountering JPEG markers with too short marker lengths (issue 8169)
  • Loading branch information
Snuffleupagus authored Mar 20, 2017
2 parents b2ed788 + be1a6f2 commit cfc45e5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/core/jpg.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
}
}(this, function (exports, sharedUtil) {

var warn = sharedUtil.warn;
var error = sharedUtil.error;

/**
Expand Down Expand Up @@ -604,8 +605,28 @@ var JpegImage = (function JpegImageClosure() {
}

function readDataBlock() {
function isValidMarkerAt(pos) {
if (pos < data.length - 1) {
return (data[pos] === 0xFF &&
data[pos + 1] >= 0xC0 && data[pos + 1] <= 0xFE);
}
return true;
}

var length = readUint16();
var array = data.subarray(offset, offset + length - 2);
var endOffset = offset + length - 2;

if (!isValidMarkerAt(endOffset)) {
warn('readDataBlock - incorrect length, next marker is: ' +
(data[endOffset] << 8 | data[endOffset + 1]).toString('16'));
var pos = offset;
while (!isValidMarkerAt(pos)) {
pos++;
}
endOffset = pos;
}

var array = data.subarray(offset, endOffset);
offset += array.length;
return array;
}
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/issue8169.pdf.link
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
http://web.archive.org/save/_embed/http://210.243.166.143/prob1.pdf
7 changes: 7 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,13 @@
"link": false,
"type": "eq"
},
{ "id": "issue8169",
"file": "pdfs/issue8169.pdf",
"md5": "62fd6479f9e1c8c5ce8cba6b1781d0a5",
"rounds": 1,
"link": true,
"type": "eq"
},
{ "id": "txt2pdf",
"file": "pdfs/txt2pdf.pdf",
"md5": "02cefa0f5e8d96313bb05163b2f88c8c",
Expand Down

0 comments on commit cfc45e5

Please sign in to comment.