TMI-120: Fix IIOOBE when file has no image. Will throw exceptions when trying to read or get metadata.

This commit is contained in:
Harald Kuhr
2015-03-19 21:57:03 +01:00
parent 11f33741d4
commit 406ae28da7
3 changed files with 38 additions and 2 deletions
@@ -1360,6 +1360,22 @@ public class JPEGImageReaderTest extends ImageReaderAbstractTestCase<JPEGImageRe
return sortedNodes;
}
@Test
public void testGetNumImagesBogusDataPrepended() throws IOException {
// The JPEGImageReader (incorrectly) interprets this image to be a "tables only" image.
JPEGImageReader reader = createReader();
try {
reader.setInput(ImageIO.createImageInputStream(getClassLoaderResource("/broken-jpeg/broken-bogus-data-prepended-real-jfif-start-at-4801.jpg")));
assertEquals(-1, reader.getNumImages(false)); // Ok
assertEquals(0, reader.getNumImages(true)); // Should throw IIOException or return 0
}
finally {
reader.dispose();
}
}
@Test
public void testNegativeSOSComponentCount() throws IOException {
// The data in the stream looks like this:
Binary file not shown.

After

Width:  |  Height:  |  Size: 530 KiB