mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Handle some corrupt/truncated JPEG images that are missing the EOI (End of Image) marker (issue 11052)
Note that even Adobe Reader cannot render the PDF file completely, which is always a good indication that it's corrupt.
This commit is contained in:
parent
aaef00ce5d
commit
0f78fdb229
3 changed files with 22 additions and 5 deletions
|
@ -403,16 +403,19 @@ var JpegImage = (function JpegImageClosure() {
|
|||
// find marker
|
||||
bitsCount = 0;
|
||||
fileMarker = findNextFileMarker(data, offset);
|
||||
// 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).
|
||||
if (fileMarker && fileMarker.invalid) {
|
||||
if (!fileMarker) {
|
||||
// Reached the end of the image data without finding an EOI marker.
|
||||
break;
|
||||
} else 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).
|
||||
warn('decodeScan - unexpected MCU data, current marker is: ' +
|
||||
fileMarker.invalid);
|
||||
offset = fileMarker.offset;
|
||||
}
|
||||
var marker = fileMarker && fileMarker.marker;
|
||||
if (!marker || marker <= 0xFF00) {
|
||||
throw new JpegError('marker was not found');
|
||||
throw new JpegError('decodeScan - a valid marker was not found.');
|
||||
}
|
||||
|
||||
if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
|
||||
|
@ -943,7 +946,13 @@ var JpegImage = (function JpegImageClosure() {
|
|||
offset = nextFileMarker.offset;
|
||||
break;
|
||||
}
|
||||
throw new JpegError('unknown marker ' + fileMarker.toString(16));
|
||||
if (offset > (data.length - 2)) {
|
||||
warn('JpegImage.parse - reached the end of the image data ' +
|
||||
'without finding an EOI marker (0xFFD9).');
|
||||
break markerLoop;
|
||||
}
|
||||
throw new JpegError('JpegImage.parse - unknown marker: ' +
|
||||
fileMarker.toString(16));
|
||||
}
|
||||
fileMarker = readUint16();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue