Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to recover when encountering JPEG markers with too short marker lengths (issue 8169) #8170

Merged
merged 1 commit into from
Mar 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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