mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2026-05-01 00:00:02 -04:00
#595 Avoid infinite loop on corrupted JPEG stream
This commit is contained in:
+1
-13
@@ -173,19 +173,7 @@ public final class JPEGImageReader extends ImageReaderBase {
|
||||
private boolean isLossless() throws IOException {
|
||||
assertInput();
|
||||
|
||||
try {
|
||||
if (getSOF().marker == JPEG.SOF3) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (IIOException e) {
|
||||
// May happen if no SOF is found, in case we'll just fall through
|
||||
if (DEBUG) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return getSOF().marker == JPEG.SOF3;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+7
-2
@@ -572,12 +572,17 @@ final class JPEGSegmentImageInputStream extends ImageInputStreamImpl {
|
||||
|
||||
@Override
|
||||
public int read(final ImageInputStream stream) {
|
||||
return data[pos++] & 0xff;
|
||||
return data.length > pos ? data[pos++] & 0xff : -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(final ImageInputStream stream, byte[] b, int off, int len) {
|
||||
int length = Math.min(data.length - pos, len);
|
||||
int dataLeft = data.length - pos;
|
||||
if (dataLeft <= 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int length = Math.min(dataLeft, len);
|
||||
System.arraycopy(data, pos, b, off, length);
|
||||
pos += length;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user