Martin Mirchev created IMAGING-394:
--------------------------------------
Summary: RGBE (HDR) decoder reads missing scan line bytes as 0xFF
and overruns on long runs
Key: IMAGING-394
URL: https://issues.apache.org/jira/browse/IMAGING-394
Project: Commons Imaging
Issue Type: Bug
Reporter: Martin Mirchev
{{RgbeInfo.decompress}}, the run-length decoder of Radiance HDR (RGBE) scan
lines, checks for the end of the stream only when reading a run's count byte.
The repeated value of a run and the bytes of a literal run are read with
{{in.read()}} and stored without checking for -1, so a file that ends inside a
run decodes without error, with the missing bytes set to 0xFF (for the exponent
channel, values about 2^119). It also does not check that a run fits in the
scan line, so a run longer than the rest of the scan line throws a raw
{{ArrayIndexOutOfBoundsException}}.
Reproducer (a 4x1 image whose scan line is cut off inside the last literal run):
{code:java}
byte[] header = "#?RADIANCE\nFORMAT=32-bit_rle_rgbe\n\n-Y 1 +X
4\n".getBytes(StandardCharsets.US_ASCII);
byte[] scanLine = { 2, 2, 0, 4, 4, 1, 2, 3, 4, 4, 1, 2, 3, 4, 4, 1, 2, 3, 4, 4,
(byte) 0x81, (byte) 0x81 }; // last 2 bytes missing
// header + scanLine: new RgbeImageParser().getBufferedImage(...) returns an
image, no exception
// with the scan line { 2, 2, 0, 4, (byte) (0x80 | 20), 1 }:
ArrayIndexOutOfBoundsException
{code}
Suggested fix: throw an ImagingException ("Error decompressing RGBE file", as
for a missing count byte) when a run's bytes are missing or a run exceeds the
scan line. A pull request with the fix and a test follows.
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)