Martin Mirchev created IMAGING-396:
--------------------------------------
Summary: Unchecked exceptions instead of ImagingException for
malformed WBMP, PNG sCAL, XPM and IPTC input
Key: IMAGING-396
URL: https://issues.apache.org/jira/browse/IMAGING-396
Project: Commons Imaging
Issue Type: Bug
Reporter: Martin Mirchev
Several parsers throw undocumented unchecked exceptions on malformed input
instead of {{ImagingException}}, so callers that handle
{{ImagingException}}/{{IOException}} for untrusted files still crash. All four
go through public calls on small inputs:
||Format||Call||Exception||Cause||
|WBMP|{{getBufferedImage}}|{{IllegalArgumentException: Size must be equal or
greater than zero: -2147483648}}|{{rowLength * height}} overflows {{int}}
({{WbmpImageParser.readImage}})|
|PNG|{{Imaging.getImageInfo}}|{{ArrayIndexOutOfBoundsException: Index 0 out of
bounds for length 0}}|zero-length sCAL chunk ({{PngChunkScal}} constructor)|
|XPM|{{getBufferedImage}}|{{NullPointerException}}|{{BasicCParser.nextToken()}}
returns null at end of input ({{XpmImageParser.parseNextString}})|
|JPEG/IPTC|{{Imaging.getMetadata}}|{{ArrayIndexOutOfBoundsException}}|an APP13
IPTC block ends inside a record header ({{IptcParser}})|
For example, the XPM file {{/* XPM */ static char *x[] = {}} followed by end of
input gives the NPE, and a 1x1 PNG with an empty sCAL chunk gives the AIOOBE.
This is the same class of problem as IMAGING-301. A pull request follows that
rejects the WBMP size above {{Integer.MAX_VALUE}}, rejects an empty sCAL chunk,
checks the XPM token for null, and stops reading IPTC records when the record
header does not fit (as already done for other truncated IPTC data), with a
test for each case.
This issue was found by an LLM-Enhanced Static Analysis Engine and verified
manually.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)