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

IndexOutOfBoundsException when reading indexed color BMP

XMLWordPrintable

    • b01
    • x86_64
    • generic

        FULL PRODUCT VERSION :
        java version "1.8.0_131"
        Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
        Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

        ADDITIONAL OS VERSION INFORMATION :
        Microsoft Windows [version 6.1.7601]

        A DESCRIPTION OF THE PROBLEM :
        When loading a BMP image using indexed color model (palette), an java.lang.IndexOutOfBoundsException occurs.


        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Create a 8BPP indexed color BMP (I have used GIMP for windows)
        Try to load it using ImageIO.read method.


        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        a BufferedImage with the BMP content
        ACTUAL -
        A nice java.lang.IndexOutOfBoundsException: off < 0 || len < 0 || off + len > b.length!

        ERROR MESSAGES/STACK TRACES THAT OCCUR :
        Exception in thread "main" java.lang.IndexOutOfBoundsException: off < 0 || len < 0 || off + len > b.length!
        at javax.imageio.stream.ImageInputStreamImpl.readFully(ImageInputStreamImpl.java:346)
        at com.sun.imageio.plugins.bmp.BMPImageReader.read8Bit(BMPImageReader.java:1160)
        at com.sun.imageio.plugins.bmp.BMPImageReader.read(BMPImageReader.java:923)
        at javax.imageio.ImageIO.read(ImageIO.java:1448)
        ...

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        ImageInputStream is = new FileImageInputStream(new File("indexed.bmp"));
        BufferedImage img = ImageIO.read(is);

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

        CUSTOMER SUBMITTED WORKAROUND :
        None.
        The bug is in BMPImageReader.read(int imageIndex, ImageReadParam param) method, at line 918.
        A "break" is missing in the switch case VERSION_4_4_BIT, the reader also execute the next case (VERSION_4_8_BIT) that cause the IndexOutOfBoundsException.
        I have tested with a copy of this class, by adding a break at line 918 and it fixes the problem.

              fmatte Fairoz Matte
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: