mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2026-04-05 00:00:01 -04:00
TMI-107: Better fix, with test case on stream level. JPEGSegmentImageInputStream now recovers from EOFException while parsing segments.
This commit is contained in:
@@ -153,4 +153,29 @@ public class JPEGSegmentImageInputStreamTest {
|
||||
|
||||
assertEquals(1061L, length); // Sanity check: same as file size, except padding and the filtered ICC_PROFILE segment
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEOFExceptionInSegmentParsingShouldNotCreateBadState() throws IOException {
|
||||
ImageInputStream iis = new JPEGSegmentImageInputStream(ImageIO.createImageInputStream(getClassLoaderResource("/broken-jpeg/broken-no-sof-ascii-transfer-mode.jpg")));
|
||||
int fileLength = 2021;
|
||||
|
||||
byte[] buffer = new byte[4096];
|
||||
|
||||
// NOTE: This is a simulation of how the native parts of com.sun...JPEGImageReader would read the image...
|
||||
assertEquals(fileLength, iis.read(buffer, 0, buffer.length));
|
||||
assertEquals(fileLength, iis.getStreamPosition());
|
||||
|
||||
iis.seek(0x2012); // bad segment length, should have been 0x0012, not 0x2012
|
||||
assertEquals(0x2012, iis.getStreamPosition());
|
||||
|
||||
// So far, so good (but stream position is now really beyond EOF)...
|
||||
|
||||
// This however, will blow up with an EOFException internally (but we'll return -1 to be good)
|
||||
assertEquals(-1, iis.read(buffer, 0, buffer.length));
|
||||
assertEquals(0x2012, iis.getStreamPosition());
|
||||
|
||||
// Again, should just continue returning -1 for ever
|
||||
assertEquals(-1, iis.read(buffer, 0, buffer.length));
|
||||
assertEquals(0x2012, iis.getStreamPosition());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user