Piotr Karwasz created IMAGING-398:
-------------------------------------

             Summary: RGBE decoder checks the pixel count instead of the byte 
size of its float buffer
                 Key: IMAGING-398
                 URL: https://issues.apache.org/jira/browse/IMAGING-398
             Project: Commons Imaging
          Issue Type: Bug
    Affects Versions: 1.0.0-alpha6
            Reporter: Piotr Karwasz


{{RgbeInfo.getPixelData()}} allocates its pixel buffer as {{new 
float[3][Allocator.check(width * height)]}}, where {{height}} is read from the 
{{-Y N +X M}} resolution line without a bound. Two problems follow:
# {{Allocator.check(int)}} compares the element count with the allocation 
limit, while the actual allocation is {{3 × width × height × 4}} bytes, up to 
12 times the limit. A header-only file declaring {{-Y 1000000000 +X 1}} passes 
the check and requests about 12 GB before any scan line is read.
# {{width * height}} is computed in {{int}}. For {{-Y 1073741824 +X 2}} it 
overflows to a negative value, which {{Allocator.check(int)}} accepts, and the 
allocation throws {{NegativeArraySizeException}}.

Suggested fix: use {{Allocator.check((long) width * height, 3 * Float.BYTES)}}, 
which rejects both cases with an {{AllocationRequestException}}. A pull request 
with the fix and tests follows.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to