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

ImageIO.read() throws IndexOutOfBoundsException on certain bad GIF file

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 6
    • client-libs

      FULL PRODUCT VERSION :
      java version "1.6.0_03"

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      ImageIO.read() throws an IndexOutOfBoundsException on a bad GIF file, when another result seems expected. See below for details.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and run the following program, passing the location of this GIF file:

      http://www.latavolacalda.co.uk/_blnk.gif

      I will try to attach it to the test case.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The image appears to indeed be a bad GIF. It reports a block size of 59 bytes, but the image file is only 56 bytes in length. It seems like the code should be prepared for this situation.

      Per ImageIO.read()'s contract, I would expect either a null return value since it could not be decoded by any reader, or at best, an IOException. I think a null is preferable but am not entirely sure on that.
      ACTUAL -
      Exception indicated below is thrown. Similar errors occur in different parts of the code if, for example, the ImageIO cache is used, or disabled. The

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.lang.IndexOutOfBoundsException
      at java.io.RandomAccessFile.readBytes(Native Method)
      at java.io.RandomAccessFile.read(RandomAccessFile.java:322)
      at javax.imageio.stream.FileImageInputStream.read(FileImageInputStream.java:101)
      at com.sun.imageio.plugins.gif.GIFImageReader.getCode(GIFImageReader.java:306)
      at com.sun.imageio.plugins.gif.GIFImageReader.read(GIFImageReader.java:881)
      at javax.imageio.ImageIO.read(ImageIO.java:1422)
      at javax.imageio.ImageIO.read(ImageIO.java:1282)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.imageio.ImageIO;
      import java.io.File;

      public class Test {
      public static void main(String[] args) throws Exception {
      ImageIO.read(new File(args[0]));
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      None, other than catching this exception and assuming that it's equivalent to receiving a null return value.

            jdv Jayathirth D V
            igor Igor Nekrestyanov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: