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

com.sun.imagio.plugins.tiff.TIFFID.java:326 uses stream.readFully incorrectly

    XMLWordPrintable

Details

    Description

      ADDITIONAL SYSTEM INFORMATION :
      OSX-11.4 and RHEL7

      A DESCRIPTION OF THE PROBLEM :
      TIFF files that are larger than 1024000 bytes hrow an out-of-bound exception.
      This may have been introduced in the patch at
      https://github.com/openjdk/jdk16/commit/151b6f14025150a6976a97bdd6ac52a0e5a0f560#

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Used a large TIFF file 1.8 MB in size.
      2. Try to read using ImageIO API (See source code for executable test case)

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      #### output below ####
      $ java /tmp/testImageIO.java
      1 Standard BMP Image Reader
      2 Standard JPEG Image Reader
      3 Standard WBMP Image Reader
      4 Standard GIF image reader
      5 Standard TIFF image reader
      6 Standard PNG image reader
      --> Image file read successfully
      ACTUAL -
      #### output below with out-of-bounds exception ####
      $ java /tmp/testImageIO.java
      1 Standard BMP Image Reader
      2 Standard JPEG Image Reader
      3 Standard WBMP Image Reader
      4 Standard GIF image reader
      5 Standard TIFF image reader
      6 Standard PNG image reader
      Exception in thread "main" java.lang.IndexOutOfBoundsException: off < 0 || len < 0 || off + len > b.length!
              at java.desktop/javax.imageio.stream.ImageInputStreamImpl.readFully(ImageInputStreamImpl.java:346)
              at java.desktop/com.sun.imageio.plugins.tiff.TIFFIFD.readFieldValue(TIFFIFD.java:326)
              at java.desktop/com.sun.imageio.plugins.tiff.TIFFIFD.initialize(TIFFIFD.java:1088)
              at java.desktop/com.sun.imageio.plugins.tiff.TIFFImageMetadata.initializeFromStream(TIFFImageMetadata.java:88)
              at java.desktop/com.sun.imageio.plugins.tiff.TIFFImageReader.readMetadata(TIFFImageReader.java:319)
              at java.desktop/com.sun.imageio.plugins.tiff.TIFFImageReader.seekToImage(TIFFImageReader.java:291)
              at java.desktop/com.sun.imageio.plugins.tiff.TIFFImageReader.prepareRead(TIFFImageReader.java:964)
              at java.desktop/com.sun.imageio.plugins.tiff.TIFFImageReader.read(TIFFImageReader.java:1140)
              at java.desktop/javax.imageio.ImageIO.read(ImageIO.java:1468)
              at java.desktop/javax.imageio.ImageIO.read(ImageIO.java:1315)
              at TestImageIO.main(testImageIO.java:23)


      ---------- BEGIN SOURCE ----------
      // File: /tmp/testImageIO.java
      // Imagefile under test: "/tmp/cmyk_image_alphaChannel.tif" is
      // ls -l /host-tmp/cmyk_image_alphaChannel.tif
      // -rw-r--r-- 1 username users 1838517 Jul 15 17:45 /tmp/cmyk_image_alphaChannel.tif

      import javax.imageio.spi.IIORegistry;
      import javax.imageio.spi.ImageReaderSpi;
      import javax.imageio.ImageIO;
      import java.awt.image.BufferedImage;
      import java.io.*;

      import java.util.Locale;

      class TestImageIO {
          static {
          var registry = IIORegistry.getDefaultInstance();
          int i = 0;
          var iter = registry.getServiceProviders(ImageReaderSpi.class, true);
              while (iter.hasNext()) {
                  System.out.println(++i + " " + iter.next().getDescription(Locale.ENGLISH));
              }
          }
          public static void main (String... args) {
             BufferedImage img=null;
             try {
               img = ImageIO.read(new File("/tmp/cmyk_image_alphaChannel.tif"));
               System.out.println("--> mage file read successfully");
             } catch (IOException e) {
               System.out.println(e);
             }
          }
      }


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

      CUSTOMER SUBMITTED WORKAROUND :
      "Disabling" the standard TIFF image reader and using the "jai-imageio-core-1.3.1.jar" on the classpath for tiff works. Please refer
      https://stackoverflow.com/questions/38190507/how-to-exclude-specific-tiff-reader-from-imageio

      FREQUENCY : always


      Attachments

        Issue Links

          Activity

            People

              pnarayanaswa Praveen Narayanaswamy
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: