Always skip over any additional, unexpected, RSTx (restart) markers in corrupt JPEG images (issue 11794)

This commit is contained in:
Jonas Jenwald 2020-04-12 12:27:11 +02:00
parent 26cffd03b0
commit 06f6f8719f
3 changed files with 38 additions and 21 deletions

View File

@ -393,11 +393,17 @@ var JpegImage = (function JpegImageClosure() {
}
var h, v;
while (mcu < mcuExpected) {
while (mcu <= mcuExpected) {
// reset interval stuff
var mcuToRead = resetInterval
? Math.min(mcuExpected - mcu, resetInterval)
: mcuExpected;
// The `mcuToRead === 0` case should only occur when all of the expected
// MCU data has been already parsed, i.e. when `mcu === mcuExpected`, but
// some corrupt JPEG images contain more data than intended and we thus
// want to skip over any extra RSTx markers below (fixes issue11794.pdf).
if (mcuToRead > 0) {
for (i = 0; i < componentsLength; i++) {
components[i].pred = 0;
}
@ -424,6 +430,7 @@ var JpegImage = (function JpegImageClosure() {
mcu++;
}
}
}
// find marker
bitsCount = 0;
@ -434,8 +441,9 @@ var JpegImage = (function JpegImageClosure() {
if (fileMarker.invalid) {
// Some bad images seem to pad Scan blocks with e.g. zero bytes, skip
// past those to attempt to find a valid marker (fixes issue4090.pdf).
const partialMsg = mcuToRead > 0 ? "unexpected" : "excessive";
warn(
`decodeScan - unexpected MCU data, current marker is: ${fileMarker.invalid}`
`decodeScan - ${partialMsg} MCU data, current marker is: ${fileMarker.invalid}`
);
offset = fileMarker.offset;
}

View File

@ -0,0 +1 @@
https://github.com/mozilla/pdf.js/files/4459214/test.pdf

View File

@ -2468,6 +2468,14 @@
"link": true,
"type": "eq"
},
{ "id": "issue11794",
"file": "pdfs/issue11794.pdf",
"md5": "00d17b10a5fd7c06cddd7a0d2066ecdd",
"rounds": 1,
"link": true,
"lastPage": 1,
"type": "eq"
},
{
"id": "bug852992",
"file": "pdfs/bug852992_reduced.pdf",