Tim Scheckenbach created IMAGING-383:
----------------------------------------
Summary: Imaging.getBufferedImage causes an
IllegalArgumentException "ColorSpace must be TYPE_RGB." on a greyscale PNG with
alpha and a grey ICC profile
Key: IMAGING-383
URL: https://issues.apache.org/jira/browse/IMAGING-383
Project: Commons Imaging
Issue Type: Bug
Components: Format: PNG
Affects Versions: 1.0.0-alpha7
Reporter: Tim Scheckenbach
Attachments: crash-0ba22b632ad08598e98c1b7fceb4863c6bc6c3b1
Calling
{code:java}
Imaging.getBufferedImage(new
File("crash-0ba22b632ad08598e98c1b7fceb4863c6bc6c3b1"));
{code}
on the attached PNG results in:
{code:java}
java.lang.IllegalArgumentException: ColorSpace must be TYPE_RGB.
at
java.desktop/java.awt.image.PackedColorModel.<init>(PackedColorModel.java:205)
at
java.desktop/java.awt.image.DirectColorModel.<init>(DirectColorModel.java:234)
at
org.apache.commons.imaging.ColorTools.deriveColorModel(ColorTools.java:258)
at
org.apache.commons.imaging.ColorTools.deriveColorModel(ColorTools.java:228)
at
org.apache.commons.imaging.ColorTools.deriveColorModel(ColorTools.java:215)
at
org.apache.commons.imaging.ColorTools.relabelColorSpace(ColorTools.java:317)
at
org.apache.commons.imaging.ColorTools.convertBetweenColorSpaces(ColorTools.java:66)
at
org.apache.commons.imaging.formats.png.PngImageParser.getBufferedImage(PngImageParser.java:313)
at
org.apache.commons.imaging.formats.png.PngImageParser.getBufferedImage(PngImageParser.java:75)
{code}
The image is a 1x1 PNG with IHDR colour type 4 (greyscale with alpha) and an
{{iCCP}} chunk
whose profile declares {{{}dataColorSpace = 'GRAY'{}}}.
After some investigation: for a greyscale image {*}with alpha{*},
{{SimpleBufferedImageFactory.getGrayscaleBufferedImage}} returns
{{{}TYPE_INT_ARGB{}}}, which is
backed by a {{{}DirectColorModel{}}}. {{PngImageParser:313}} then applies the
embedded profile,
which relabels the image and reaches the {{DirectColorModel}} branch of
{{ColorTools.deriveColorModel}} ({{{}ColorTools.java:250-258{}}}), calling
{{{}new DirectColorModel(cs, ...){}}}. {{PackedColorModel}} accepts only colour
spaces of type
{{{}TYPE_RGB{}}}, so the grey space is rejected. The pixel layout comes from
IHDR and the colour
space from {{{}iCCP{}}}, and nothing checks that the two are compatible.
{{Imaging.getBufferedImage}} is declared as {{{}throws ImagingException,
IOException{}}}, so
callers handling the documented exception types do not catch this one.
I have attached the image to the issue.
Found by the CISPA Fandango Team
--
This message was sent by Atlassian Jira
(v8.20.10#820010)