JDK-8316797 : ArrayIndexOutOfBoundsException during image rendering
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 11,17,21,22
  • Priority: P3
  • Status: New
  • Resolution: Unresolved
  • OS: generic
  • CPU: generic
  • Submitted: 2023-09-21
  • Updated: 2023-09-26
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Description
ADDITIONAL SYSTEM INFORMATION :
Identification: JOSM/1.5 (18837 SVN en) Mac OS X 13.5.2
OS Build number: macOS 13.5.2 (22G91)
Memory Usage: 847 MB / 2048 MB (170 MB allocated, but free)
Java version: 21+35, Azul Systems, Inc., OpenJDK 64-Bit Server VM
Look and Feel: com.apple.laf.AquaLookAndFeel
Screen: Display 188945233 1920×1080 (scaling 1.00×1.00) Display 188945231 1920×1080 (scaling 1.00×1.00) Display 69733382 1680×1050 (scaling 2.00×2.00)
Maximum Screen Size: 1920×1080
Best cursor sizes: 16×16→16×16, 32×32→32×32
System property file.encoding: UTF-8
System property sun.jnu.encoding: UTF-8
Locale info: en_US

A DESCRIPTION OF THE PROBLEM :
Java cannot properly load tiffs from NOAA.

Test file from https://www.ncei.noaa.gov/maps/grid-extract/ EMAG2v3_Sealevel dataset, AOI is -77.38, 36.17, -75.55, 37.26

Test file: https://gis.ngdc.noaa.gov/arcgis/rest/services/EMAG2v3/ImageServer/exportImage?bbox=-77.40000,36.20000,-75.56667,37.26667&bboxSR=4326&size=55,32&imageSR=4326&format=tiff&pixelType=F32&interpolation=+RSP_NearestNeighbor&compression=LZ77&nodata=-999&mosaicRule={%22where%22:%22Name=%27EMAG2_V3_20170530_SeaLevel%27%22}&f=image

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Download an AOI from NOAA from the EMAG2v3_SeaLevel dataset; other datasets may trigger this bug, but that is what was tested.
2. Load the tiff using ImageIO
3. Attempt to paint the tiff via a Graphics object
4. Crash

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
TIFF to be properly loaded and painted
ACTUAL -
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -65469464
	at java.awt.image.ComponentColorModel.getRGBComponent(ComponentColorModel.java:903)
	at java.awt.image.ComponentColorModel.getRed(ComponentColorModel.java:944)
	at java.awt.image.ComponentColorModel.getRGB(ComponentColorModel.java:1135)
	at sun.java2d.loops.OpaqueCopyAnyToArgb.Blit(CustomComponent.java:145)
	at sun.java2d.pipe.DrawImage.blitSurfaceData(DrawImage.java:959)
	at sun.java2d.pipe.DrawImage.renderImageCopy(DrawImage.java:577)
	at sun.java2d.pipe.DrawImage.copyImage(DrawImage.java:67)
	at sun.java2d.pipe.DrawImage.copyImage(DrawImage.java:1014)
	at sun.java2d.pipe.ValidatePipe.copyImage(ValidatePipe.java:186)
	at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:3325)
	at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:3303)
	at Scratch.main(scratch_10.java:15)


---------- BEGIN SOURCE ----------
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URI;
import java.text.MessageFormat;

import javax.imageio.ImageIO;

class Scratch {
    public static void main(String[] args) throws IOException {
        // If this stops working, download and read a file from https://www.ncei.noaa.gov/maps/grid-extract/
        // This test case is from the EMAG2v3_SeaLevel dataset with an AOI of -77.38, 36.17, -75.55, 37.26
        Image image = ImageIO.read(URI.create("https://gis.ngdc.noaa.gov/arcgis/rest/services/EMAG2v3/ImageServer/exportImage?bbox=-77.40000,36.20000,-75.56667,37.26667&bboxSR=4326&size=55,32&imageSR=4326&format=tiff&pixelType=F32&interpolation=+RSP_NearestNeighbor&compression=LZ77&nodata=-999&mosaicRule=%7B%22where%22:%22Name=%27EMAG2_V3_20170530_SeaLevel%27%22%7D&f=image").toURL());
        Image paint = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
        System.out.println(MessageFormat.format("Image: {0}x{1}", image.getWidth(null), image.getHeight(null)));
        paint.getGraphics().drawImage(image, 0, 0, null);
        System.out.println("It worked");
    }
}
---------- END SOURCE ----------

FREQUENCY : always



Comments
Observed this exception with the latest mainline code with both Metal and OpenGL pipelines on macOS. This indicates the exception is pipeline agnostic.
26-09-2023

"In jdk8, jdk8u381 neither image loaded nor exception observed for both sample.tiff and exportImage.tiff" No surprise there, TIFF reading wasn't added until JDK 9. But this doesn't seem to be a TIFF loading issue, the exception is long after the tiff was decoded and during rendering of the decoded image.
24-09-2023

Checked with attached testcase(LoadImageApp.java) in Windows 10, macOS Ventura 13.5.2 issue could not be reproduced with other tiff(sample.tiff) Observed below exception with the tiff (downloaded exportImage.tiff) from the test link. jdk11.0.20 jdk17.0.8 jdk21 jdk22ea16 Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: Index -65469464 out of bounds for length 65536 at java.desktop/java.awt.image.ComponentColorModel.getRGBComponent(ComponentColorModel.java:893) at java.desktop/java.awt.image.ComponentColorModel.getRed(ComponentColorModel.java:934) at java.desktop/java.awt.image.ComponentColorModel.getRGB(ComponentColorModel.java:1125) at java.desktop/sun.java2d.loops.OpaqueCopyAnyToArgb.Blit(CustomComponent.java:145) at java.desktop/sun.java2d.loops.GraphicsPrimitive.convertFrom(GraphicsPrimitive.java:571) at java.desktop/sun.java2d.loops.GraphicsPrimitive.convertFrom(GraphicsPrimitive.java:552) at java.desktop/sun.java2d.loops.MaskBlit$General.MaskBlit(MaskBlit.java:190) at java.desktop/sun.java2d.loops.Blit$GeneralMaskBlit.Blit(Blit.java:205) at java.desktop/sun.java2d.pipe.DrawImage.blitSurfaceData(DrawImage.java:986) at java.desktop/sun.java2d.pipe.DrawImage.renderImageCopy(DrawImage.java:583) at java.desktop/sun.java2d.pipe.DrawImage.copyImage(DrawImage.java:88) at java.desktop/sun.java2d.pipe.DrawImage.copyImage(DrawImage.java:1057) at java.desktop/sun.java2d.pipe.ValidatePipe.copyImage(ValidatePipe.java:196) at java.desktop/sun.java2d.SunGraphics2D.copyImage(SunGraphics2D.java:3336) at java.desktop/sun.java2d.pipe.DrawImage.makeBufferedImage(DrawImage.java:359) at java.desktop/sun.java2d.pipe.DrawImage.renderImageXform(DrawImage.java:470) at java.desktop/sun.java2d.pipe.DrawImage.transformImage(DrawImage.java:266) at java.desktop/sun.java2d.pipe.DrawImage.copyImage(DrawImage.java:78) at java.desktop/sun.java2d.pipe.DrawImage.copyImage(DrawImage.java:1041) at java.desktop/sun.java2d.pipe.ValidatePipe.copyImage(ValidatePipe.java:186) at java.desktop/sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:3429) at java.desktop/sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:3405) at LoadImageApp.paint(LoadImageApp.java:16) at java.desktop/javax.swing.JComponent.paintChildren(JComponent.java:975) at java.desktop/javax.swing.JComponent.paint(JComponent.java:1137) at java.desktop/javax.swing.JComponent.paintChildren(JComponent.java:961) at java.desktop/javax.swing.JComponent.paint(JComponent.java:1137) at java.desktop/javax.swing.JLayeredPane.paint(JLayeredPane.java:586) at java.desktop/javax.swing.JComponent.paintChildren(JComponent.java:961) at java.desktop/javax.swing.JComponent.paintToOffscreen(JComponent.java:5325) at java.desktop/javax.swing.RepaintManager$PaintManager.paintDoubleBufferedFPScales(RepaintManager.java:1720) at java.desktop/javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1629) at java.desktop/javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1569) at java.desktop/javax.swing.RepaintManager.paint(RepaintManager.java:1336) at java.desktop/javax.swing.JComponent.paint(JComponent.java:1114) at java.desktop/java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:39) at java.desktop/sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:75) at java.desktop/sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:112) at java.desktop/java.awt.Container.paint(Container.java:2005) at java.desktop/java.awt.Window.paint(Window.java:3959) at java.desktop/javax.swing.RepaintManager$4.run(RepaintManager.java:889) at java.desktop/javax.swing.RepaintManager$4.run(RepaintManager.java:861) at java.base/java.security.AccessController.doPrivileged(AccessController.java:400) at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:87) at java.desktop/javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:861) at java.desktop/javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:834) at java.desktop/javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:784) at java.desktop/javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1897) at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318) at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:773) at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:720) at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:714) at java.base/java.security.AccessController.doPrivileged(AccessController.java:400) at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:87) at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742) at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203) at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124) at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113) at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109) at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90) In jdk8, jdk8u381 neither image loaded nor exception observed for both sample.tiff and exportImage.tiff
24-09-2023