src/java.desktop/share/classes/com/sun/imageio/plugins/png/PNGImageReader.java
changeset 52751 abed2967ec3a
parent 52750 6bdbd601d31c
equal deleted inserted replaced
52750:6bdbd601d31c 52751:abed2967ec3a
   747 
   747 
   748         try {
   748         try {
   749             loop: while (true) {
   749             loop: while (true) {
   750                 int chunkLength = stream.readInt();
   750                 int chunkLength = stream.readInt();
   751                 int chunkType = stream.readInt();
   751                 int chunkType = stream.readInt();
   752                 int chunkCRC;
   752                 // Initialize chunkCRC, value assigned has no significance
       
   753                 int chunkCRC = -1;
   753 
   754 
   754                 // verify the chunk length
   755                 // verify the chunk length
   755                 if (chunkLength < 0) {
   756                 if (chunkLength < 0) {
   756                     throw new IIOException("Invalid chunk length " + chunkLength);
   757                     throw new IIOException("Invalid chunk length " + chunkLength);
   757                 };
   758                 };
   758 
   759 
   759                 try {
   760                 try {
   760                     stream.mark();
   761                     /*
   761                     stream.seek(stream.getStreamPosition() + chunkLength);
   762                      * As per PNG specification all chunks should have
   762                     chunkCRC = stream.readInt();
   763                      * 4 byte CRC. But there are some images where
   763                     stream.reset();
   764                      * CRC is not present/corrupt for IEND chunk.
       
   765                      * And these type of images are supported by other
       
   766                      * decoders. So as soon as we hit chunk type
       
   767                      * for IEND chunk stop reading metadata.
       
   768                      */
       
   769                     if (chunkType != IEND_TYPE) {
       
   770                         stream.mark();
       
   771                         stream.seek(stream.getStreamPosition() + chunkLength);
       
   772                         chunkCRC = stream.readInt();
       
   773                         stream.reset();
       
   774                     }
   764                 } catch (IOException e) {
   775                 } catch (IOException e) {
   765                     throw new IIOException("Invalid chunk length " + chunkLength);
   776                     throw new IIOException("Invalid chunk length " + chunkLength);
   766                 }
   777                 }
   767 
   778 
   768                 switch (chunkType) {
   779                 switch (chunkType) {