Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6945174

IndexOutOfBoundsException calling ImageIO.read() on malformed PNG

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • 9
    • 6u10, 8, 9
    • client-libs
    • b15
    • x86
    • windows_xp

    Description

      FULL PRODUCT VERSION :
      java version "1.6.0_18"
      Java(TM) SE Runtime Environment (build 1.6.0_18-b07)
      Java HotSpot(TM) Client VM (build 16.0-b13, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Windows XP SP3

      A DESCRIPTION OF THE PROBLEM :
      Attempting to read a certain malformed PNG with ImageIO.read() results in an IndexOutOfBoundException.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Download http://www.crappycomic.com/stuff/test.png
      2. Attempt to open it using ImageIO.read()

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      An IOException, since a problem occurred while reading the file.
      ACTUAL -
      An IndexOutOfBoundsException. Stack trace below.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.lang.IndexOutOfBoundsException: pos < flushedPos!
      at javax.imageio.stream.FileImageInputStream.seek(Unknown Source)
      at javax.imageio.stream.ImageInputStreamImpl.skipBytes(Unknown Source)
      at com.sun.imageio.plugins.png.PNGImageReader.readMetadata(Unknown Source)
      at com.sun.imageio.plugins.png.PNGImageReader.readImage(Unknown Source)
      at com.sun.imageio.plugins.png.PNGImageReader.read(Unknown Source)
      at javax.imageio.ImageIO.read(Unknown Source)
      at javax.imageio.ImageIO.read(Unknown Source)
      at PNGTest.main(PNGTest.java:10)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.io.File;
      import java.io.IOException;

      import javax.imageio.ImageIO;

      public class PNGTest
      {
         public static void main(String[] args) throws IOException
         {
            ImageIO.read(new File("c:/test.png"));
         }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      It's not hard to catch the exception and wrap it, but it's touchy, in case something else throws a similar exception for a different reason.

      Attachments

        Activity

          People

            bae Andrew Brygin
            igor Igor Nekrestyanov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: