Piotr Karwasz created IMAGING-403:
-------------------------------------
Summary: GIF and XPM decoders compute width × height in int,
failing with an unchecked exception
Key: IMAGING-403
URL: https://issues.apache.org/jira/browse/IMAGING-403
Project: Commons Imaging
Issue Type: Bug
Components: Format: GIF
Affects Versions: 1.0.0-alpha6
Reporter: Piotr Karwasz
Two decoders multiply the image dimensions in {{int}} before checking the
result against the {{Allocator}} limit, so large dimensions overflow to a
negative value that the single-argument {{Allocator.check}} accepts:
* {{GifImageParser.readImageDescriptor}} computes {{final int size = imageWidth
* imageHeight;}} and passes it to {{MyLzwDecompressor.decompress}}. For a 65535
× 65535 frame the size is -131071, and {{new
ByteArrayOutputStream(Allocator.checkByteArray(-131071))}} throws
{{IllegalArgumentException: Negative initial size: -131071}} from
{{Imaging.getBufferedImage}}, {{getImageInfo}} and {{getMetadata}}.
* {{XpmImageParser.readXpmImage}} calls {{Allocator.check(Integer.SIZE,
xpmHeader.width * xpmHeader.height)}}, with the arguments in the wrong order
and the product computed in {{int}}. For a 65535 × 65535 image the check passes
and {{Raster.createPackedRaster}} throws {{NegativeArraySizeException}}.
In both cases callers that catch only {{ImagingException}} / {{IOException}}
receive an undeclared {{RuntimeException}}.
Suggested fix: compute the size as {{(long) width * height}} and check it with
{{Allocator.check(long, int)}}, which rejects both cases with an
{{AllocationRequestException}}. The XPM part is also included in pull request
#401.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)