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

NumberOverflow in class MemoryCache

XMLWordPrintable

    • b17
    • generic
    • generic
    • Not verified

      ADDITIONAL SYSTEM INFORMATION :
      generic

      A DESCRIPTION OF THE PROBLEM :
      The issue was oberserved first in JDK 8 u242. However the code is still the same in JDK 12.
      When reading hugh images with the MemoryCacheImageInputStream it happens that following exception is thrown:

      java.lang.ArrayIndexOutOfBoundsException
          at javax.imageio.stream.MemoryCache.read(MemoryCache.java:327)
          at javax.imageio.stream.MemoryCacheImageInputStream.read(MemoryCacheImageInputStream.java:115)
          at javax.imageio.stream.ImageInputStreamImpl.readShort(ImageInputStreamImpl.java:228)
          at javax.imageio.stream.ImageInputStreamImpl.readUnsignedShort(ImageInputStreamImpl.java:242)
          at it.geosolutions.imageioimpl.plugins.tiff.TIFFIFD.initialize(TIFFIFD.java:237)
          at it.geosolutions.imageioimpl.plugins.tiff.TIFFImageMetadata.initializeFromStream(TIFFImageMetadata.java:148)
          at it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReader.readMetadata(TIFFImageReader.java:911)
          at it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReader.seekToImage(TIFFImageReader.java:864)
          at it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReader.seekToImage(TIFFImageReader.java:822)
          at it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReader.getWidth(TIFFImageReader.java:1080)

      This is due to the line 323 (line 336 in JDK 12) i the class MemoryCache Line 323:

      int offset = (int)pos % BUFFER_LENGTH;
      This results for the specific use case in offset being -8184

      I think the line should actually be
      int offset = (int)(pos % BUFFER_LENGTH);
      This way offset will be 8.

      The image is readable when explicitly a FileCacheImageInputStream is used.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Read an Image via the class MemoryCacheImageInputStream.

      More specifically, using ImageIO.createImageInputStream(imageStream) will use a MemoryCacheImageInputStream e.g. if the image (e.g Tiff) is an entry within in zip file and big enough 32768x32768 pixel. But also other input streams should do.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The image should be read and no exception should occur.
      ACTUAL -
      java.lang.ArrayIndexOutOfBoundsException
          at javax.imageio.stream.MemoryCache.read(MemoryCache.java:327)
          at javax.imageio.stream.MemoryCacheImageInputStream.read(MemoryCacheImageInputStream.java:115)
          at javax.imageio.stream.ImageInputStreamImpl.readShort(ImageInputStreamImpl.java:228)
          at javax.imageio.stream.ImageInputStreamImpl.readUnsignedShort(ImageInputStreamImpl.java:242)
          at it.geosolutions.imageioimpl.plugins.tiff.TIFFIFD.initialize(TIFFIFD.java:237)
          at it.geosolutions.imageioimpl.plugins.tiff.TIFFImageMetadata.initializeFromStream(TIFFImageMetadata.java:148)
          at it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReader.readMetadata(TIFFImageReader.java:911)
          at it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReader.seekToImage(TIFFImageReader.java:864)
          at it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReader.seekToImage(TIFFImageReader.java:822)
          at it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReader.getWidth(TIFFImageReader.java:1080)


      CUSTOMER SUBMITTED WORKAROUND :
      The image is readable when explicitly a FileCacheImageInputStream is used.

      FREQUENCY : always


            jdv Jayathirth D V
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: