< prev index next >
src/java.desktop/share/classes/com/sun/imageio/plugins/png/PNGImageReader.java
Print this page
@@ -747,22 +747,33 @@
try {
loop: while (true) {
int chunkLength = stream.readInt();
int chunkType = stream.readInt();
- int chunkCRC;
+ // Initialize chunkCRC, value assigned has no significance
+ int chunkCRC = -1;
// verify the chunk length
if (chunkLength < 0) {
throw new IIOException("Invalid chunk length " + chunkLength);
};
try {
+ /*
+ * As per PNG specification all chunks should have
+ * 4 byte CRC. But there are some images where
+ * CRC is not present/corrupt for IEND chunk.
+ * And these type of images are supported by other
+ * decoders. So as soon as we hit chunk type
+ * for IEND chunk stop reading metadata.
+ */
+ if (chunkType != IEND_TYPE) {
stream.mark();
stream.seek(stream.getStreamPosition() + chunkLength);
chunkCRC = stream.readInt();
stream.reset();
+ }
} catch (IOException e) {
throw new IIOException("Invalid chunk length " + chunkLength);
}
switch (chunkType) {
< prev index next >