mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-04 03:55:28 -04:00
#525: Fix for negative arrays size in old style JPEG in TIFF.
This commit is contained in:
parent
cd6a6258b6
commit
96cb3a07f4
@ -1293,21 +1293,22 @@ public final class TIFFImageReader extends ImageReaderBase {
|
||||
imageInput.seek(stripTileOffsets[0]);
|
||||
|
||||
if ((short) (imageInput.readByte() << 8 | imageInput.readByte()) == (short) JPEG.SOS) {
|
||||
int len = 2 + (imageInput.readByte() << 8 | imageInput.readByte());
|
||||
processWarningOccurred("Incorrect StripOffsets/TileOffsets, points to SOS marker, ignoring offsets/byte counts.");
|
||||
int len = 2 + (imageInput.readUnsignedByte() << 8 | imageInput.readUnsignedByte());
|
||||
stripTileOffsets[0] += len;
|
||||
stripTileByteCounts[0] -= len;
|
||||
}
|
||||
|
||||
// We'll prepend each tile with a JFIF "header" (SOI...SOS)
|
||||
imageInput.seek(realJPEGOffset);
|
||||
jpegHeader = new byte[(int) (stripTileOffsets[0] - realJPEGOffset)];
|
||||
jpegHeader = new byte[Math.max(0, (int) (stripTileOffsets[0] - realJPEGOffset))];
|
||||
imageInput.readFully(jpegHeader);
|
||||
}
|
||||
|
||||
// In case of single tile, make sure we read the entire JFIF stream
|
||||
if (stripTileByteCounts != null && stripTileByteCounts.length == 1) {
|
||||
// TODO: Consider issue warning here!
|
||||
stripTileByteCounts[0] = Math.max(stripTileByteCounts[0], jpegLength);
|
||||
if (stripTileByteCounts != null && stripTileByteCounts.length == 1 && stripTileByteCounts[0] < jpegLength) {
|
||||
processWarningOccurred("Incorrect StripByteCounts/TileByteCounts for single tile, using JPEGInterchangeFormatLength instead.");
|
||||
stripTileByteCounts[0] = jpegLength;
|
||||
}
|
||||
|
||||
// Read data
|
||||
|
@ -308,6 +308,27 @@ public class TIFFImageReaderTest extends ImageReaderAbstractTest<TIFFImageReader
|
||||
assertNotNull(image);
|
||||
assertEquals(testData.getDimension(0), new Dimension(image.getWidth(), image.getHeight()));
|
||||
verify(warningListener, atLeastOnce()).warningOccurred(eq(reader), and(contains("Old-style JPEG"), contains("tables")));
|
||||
verify(warningListener, atLeastOnce()).warningOccurred(eq(reader), and(contains("Incorrect StripOffsets/TileOffsets"), contains("SOS marker")));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadOldStyleWangMultiStrip2() throws IOException {
|
||||
TestData testData = new TestData(getClassLoaderResource("/tiff/662260-color.tif"), new Dimension(1600, 1200));
|
||||
|
||||
try (ImageInputStream stream = testData.getInputStream()) {
|
||||
TIFFImageReader reader = createReader();
|
||||
reader.setInput(stream);
|
||||
|
||||
IIOReadWarningListener warningListener = mock(IIOReadWarningListener.class);
|
||||
reader.addIIOReadWarningListener(warningListener);
|
||||
|
||||
BufferedImage image = reader.read(1);
|
||||
|
||||
assertNotNull(image);
|
||||
assertEquals(testData.getDimension(0), new Dimension(image.getWidth(), image.getHeight()));
|
||||
verify(warningListener, atLeastOnce()).warningOccurred(eq(reader), and(contains("Old-style JPEG"), contains("tables")));
|
||||
verify(warningListener, atLeastOnce()).warningOccurred(eq(reader), and(contains("Incorrect StripOffsets/TileOffsets"), contains("SOS marker")));
|
||||
}
|
||||
}
|
||||
|
||||
|
BIN
imageio/imageio-tiff/src/test/resources/tiff/662260-color.tif
Normal file
BIN
imageio/imageio-tiff/src/test/resources/tiff/662260-color.tif
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user