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

ComponentSampleModel throws IllegalArgumentException on valid images

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 8u40
    • client-libs
    • 2d
    • x86_64
    • linux

      FULL PRODUCT VERSION :
      robo@roberto-d2:~$ java -version
      java version "1.8.0_40"
      Java(TM) SE Runtime Environment (build 1.8.0_40-b25)
      Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Debian testing.

      robo@roberto-d2:~$ uname -a
      Linux roberto-d2 3.16-1-amd64 #1 SMP Debian 3.16.2-3 (2014-09-13) x86_64 GNU/Linux
      robo@roberto-d2:~$ lsb_release -a
      No LSB modules are available.
      Distributor ID: Debian
      Description: Debian GNU/Linux 8.0 (jessie)
      Release: 8.0
      Codename: jessie


      A DESCRIPTION OF THE PROBLEM :
      Calling ImageIO.read on large png or jpeg images causes ComponentSampleModel to throw exceptions even though the image is valid.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1) Create a large image I used the convert program from imagemagick:
      convert -size 30000x30000 -colors 256 canvas:khaki canvas_khaki.png

      2) Compile the ImageReadTest (from the source code field)
      javac ImageReadTest

      3) Run the program on the generated image
      java ImageReadTest canvas_khaki.png


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      No errors
      ACTUAL -
      An exception is thrown.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.lang.IllegalArgumentException: Invalid scanline stride
      at java.awt.image.ComponentSampleModel.getBufferSize(ComponentSampleModel.java:274)
      at java.awt.image.ComponentSampleModel.verify(ComponentSampleModel.java:252)
      at java.awt.image.ComponentSampleModel.<init>(ComponentSampleModel.java:170)
      at java.awt.image.PixelInterleavedSampleModel.<init>(PixelInterleavedSampleModel.java:87)
      at java.awt.image.PixelInterleavedSampleModel.createCompatibleSampleModel(PixelInterleavedSampleModel.java:144)
      at javax.imageio.ImageTypeSpecifier.getSampleModel(ImageTypeSpecifier.java:1039)
      at javax.imageio.ImageTypeSpecifier.createBufferedImage(ImageTypeSpecifier.java:1072)
      at javax.imageio.ImageReader.getDestination(ImageReader.java:2892)
      at com.sun.imageio.plugins.png.PNGImageReader.readImage(PNGImageReader.java:1309)
      at com.sun.imageio.plugins.png.PNGImageReader.read(PNGImageReader.java:1606)
      at javax.imageio.ImageIO.read(ImageIO.java:1448)
      at javax.imageio.ImageIO.read(ImageIO.java:1352)
      at ImageReadTest.main(ImageReadTest.java:10)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.image.*;
      import javax.imageio.*;
      import java.io.*;

      public class ImageReadTest {
          public static void main (String[] args) throws Exception {
      for (String a : args) {
      File f = new File (a);
      FileInputStream fis = new FileInputStream (f);
      BufferedImage bi = ImageIO.read (fis);
      bi.flush ();
      fis.close ();
      }
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Split large images into smaller images.

            prr Philip Race
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: