[src/core/jpg.js] Remove some redundant marker validation during the MCU parsing in the decodeScan
function
Some of the code in `src/core/jpg.js` is fairly old, and has with time become unnecessary when the surrounding code has been updated to handle various types of JPEG corruption. In particular the `if (!marker || marker <= 0xff00) { ... }` branch is now dead code, since: - The `!marker` case can no longer happen, since we would already have broken out of the loop thanks to the `!fileMarker` branch a handful of lines above. - The `marker <= 0xff00` case can also no longer happen, since the `findNextFileMarker` function validate markers much more thoroughly (by checking `marker >= 0xffc0 && marker <= 0xfffe`). Hence we'd again have broken out of the loop via the `!fileMarker` branch above when no valid marker was found.
This commit is contained in:
parent
50bc4a18e8
commit
26cffd03b0
@ -429,23 +429,17 @@ var JpegImage = (function JpegImageClosure() {
|
||||
bitsCount = 0;
|
||||
fileMarker = findNextFileMarker(data, offset);
|
||||
if (!fileMarker) {
|
||||
// Reached the end of the image data without finding an EOI marker.
|
||||
break;
|
||||
} else if (fileMarker.invalid) {
|
||||
break; // Reached the end of the image data without finding any marker.
|
||||
}
|
||||
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
|
||||
`decodeScan - unexpected MCU data, current marker is: ${fileMarker.invalid}`
|
||||
);
|
||||
offset = fileMarker.offset;
|
||||
}
|
||||
var marker = fileMarker && fileMarker.marker;
|
||||
if (!marker || marker <= 0xff00) {
|
||||
throw new JpegError("decodeScan - a valid marker was not found.");
|
||||
}
|
||||
|
||||
if (marker >= 0xffd0 && marker <= 0xffd7) {
|
||||
if (fileMarker.marker >= 0xffd0 && fileMarker.marker <= 0xffd7) {
|
||||
// RSTx
|
||||
offset += 2;
|
||||
} else {
|
||||
@ -458,8 +452,7 @@ var JpegImage = (function JpegImageClosure() {
|
||||
// attempt to find the next valid marker (fixes issue8182.pdf).
|
||||
if (fileMarker && fileMarker.invalid) {
|
||||
warn(
|
||||
"decodeScan - unexpected Scan data, current marker is: " +
|
||||
fileMarker.invalid
|
||||
`decodeScan - unexpected Scan data, current marker is: ${fileMarker.invalid}`
|
||||
);
|
||||
offset = fileMarker.offset;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user