mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-04 03:55:28 -04:00
#266: Fix NPE for empty streams.
This commit is contained in:
parent
c2aa7e3150
commit
9a6096664e
@ -240,16 +240,21 @@ final class JPEGSegmentImageInputStream extends ImageInputStreamImpl {
|
|||||||
private void streamInit() throws IOException {
|
private void streamInit() throws IOException {
|
||||||
stream.seek(0);
|
stream.seek(0);
|
||||||
|
|
||||||
|
try {
|
||||||
int soi = stream.readUnsignedShort();
|
int soi = stream.readUnsignedShort();
|
||||||
|
|
||||||
if (soi != JPEG.SOI) {
|
if (soi != JPEG.SOI) {
|
||||||
throw new IIOException(String.format("Not a JPEG stream (starts with: 0x%04x, expected SOI: 0x%04x)", soi, JPEG.SOI));
|
throw new IIOException(String.format("Not a JPEG stream (starts with: 0x%04x, expected SOI: 0x%04x)", soi, JPEG.SOI));
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
segment = new Segment(soi, 0, 0, 2);
|
segment = new Segment(soi, 0, 0, 2);
|
||||||
|
|
||||||
segments.add(segment);
|
segments.add(segment);
|
||||||
currentSegment = segments.size() - 1; // 0
|
currentSegment = segments.size() - 1; // 0
|
||||||
}
|
}
|
||||||
|
catch (EOFException eof) {
|
||||||
|
throw new IIOException(String.format("Not a JPEG stream (short stream. expected SOI: 0x%04x)", JPEG.SOI), eof);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean isAppSegmentMarker(final int marker) {
|
static boolean isAppSegmentMarker(final int marker) {
|
||||||
|
@ -74,6 +74,24 @@ public class JPEGSegmentImageInputStreamTest {
|
|||||||
stream.read();
|
stream.read();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(expected = IIOException.class)
|
||||||
|
public void testStreamNonJPEGArray() throws IOException {
|
||||||
|
ImageInputStream stream = new JPEGSegmentImageInputStream(ImageIO.createImageInputStream(new ByteArrayInputStream(new byte[] {42, 42, 0, 0, 77, 99})));
|
||||||
|
stream.readFully(new byte[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IIOException.class)
|
||||||
|
public void testStreamEmpty() throws IOException {
|
||||||
|
ImageInputStream stream = new JPEGSegmentImageInputStream(ImageIO.createImageInputStream(new ByteArrayInputStream(new byte[0])));
|
||||||
|
stream.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IIOException.class)
|
||||||
|
public void testStreamEmptyArray() throws IOException {
|
||||||
|
ImageInputStream stream = new JPEGSegmentImageInputStream(ImageIO.createImageInputStream(new ByteArrayInputStream(new byte[0])));
|
||||||
|
stream.readFully(new byte[1]);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStreamRealData() throws IOException {
|
public void testStreamRealData() throws IOException {
|
||||||
ImageInputStream stream = new JPEGSegmentImageInputStream(ImageIO.createImageInputStream(getClassLoaderResource("/jpeg/invalid-icc-duplicate-sequence-numbers-rgb-internal-kodak-srgb-jfif.jpg")));
|
ImageInputStream stream = new JPEGSegmentImageInputStream(ImageIO.createImageInputStream(getClassLoaderResource("/jpeg/invalid-icc-duplicate-sequence-numbers-rgb-internal-kodak-srgb-jfif.jpg")));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user