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,35 +393,42 @@ var JpegImage = (function JpegImageClosure() {
} }
var h, v; var h, v;
while (mcu < mcuExpected) { while (mcu <= mcuExpected) {
// reset interval stuff // reset interval stuff
var mcuToRead = resetInterval var mcuToRead = resetInterval
? Math.min(mcuExpected - mcu, resetInterval) ? Math.min(mcuExpected - mcu, resetInterval)
: mcuExpected; : mcuExpected;
for (i = 0; i < componentsLength; i++) {
components[i].pred = 0;
}
eobrun = 0;
if (componentsLength === 1) { // The `mcuToRead === 0` case should only occur when all of the expected
component = components[0]; // MCU data has been already parsed, i.e. when `mcu === mcuExpected`, but
for (n = 0; n < mcuToRead; n++) { // some corrupt JPEG images contain more data than intended and we thus
decodeBlock(component, decodeFn, mcu); // want to skip over any extra RSTx markers below (fixes issue11794.pdf).
mcu++; if (mcuToRead > 0) {
for (i = 0; i < componentsLength; i++) {
components[i].pred = 0;
} }
} else { eobrun = 0;
for (n = 0; n < mcuToRead; n++) {
for (i = 0; i < componentsLength; i++) { if (componentsLength === 1) {
component = components[i]; component = components[0];
h = component.h; for (n = 0; n < mcuToRead; n++) {
v = component.v; decodeBlock(component, decodeFn, mcu);
for (j = 0; j < v; j++) { mcu++;
for (k = 0; k < h; k++) { }
decodeMcu(component, decodeFn, mcu, j, k); } else {
for (n = 0; n < mcuToRead; n++) {
for (i = 0; i < componentsLength; i++) {
component = components[i];
h = component.h;
v = component.v;
for (j = 0; j < v; j++) {
for (k = 0; k < h; k++) {
decodeMcu(component, decodeFn, mcu, j, k);
}
} }
} }
mcu++;
} }
mcu++;
} }
} }
@ -434,8 +441,9 @@ var JpegImage = (function JpegImageClosure() {
if (fileMarker.invalid) { if (fileMarker.invalid) {
// Some bad images seem to pad Scan blocks with e.g. zero bytes, skip // 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). // past those to attempt to find a valid marker (fixes issue4090.pdf).
const partialMsg = mcuToRead > 0 ? "unexpected" : "excessive";
warn( warn(
`decodeScan - unexpected MCU data, current marker is: ${fileMarker.invalid}` `decodeScan - ${partialMsg} MCU data, current marker is: ${fileMarker.invalid}`
); );
offset = fileMarker.offset; 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, "link": true,
"type": "eq" "type": "eq"
}, },
{ "id": "issue11794",
"file": "pdfs/issue11794.pdf",
"md5": "00d17b10a5fd7c06cddd7a0d2066ecdd",
"rounds": 1,
"link": true,
"lastPage": 1,
"type": "eq"
},
{ {
"id": "bug852992", "id": "bug852992",
"file": "pdfs/bug852992_reduced.pdf", "file": "pdfs/bug852992_reduced.pdf",