Closed 0xdd96 closed 1 year ago
Thanks! The reason was It triggers integer overflow. I have fixed it by using int64 to calculate (max - min + 1)
and add negative value check.
Thank you for your timely response! But the fix for this bug is incomplete, and the original poc can still trigger the vulnerability.
I did a simple analysis, it appears that the compiler optimizes the check for negative numbers (line 5787).
Since the compiler assumes that the program has no undefined behavior (e.g., integer overflow), when exr_header->data_window.max_y
>=exr_header->data_window.min_y
(bypassing line 5778), the compiler considers exr_header->data_window.max_y - exr_header->data_window.min_y
is impossible to be negative, so the negative check is optimized away.
Oh, confirmed the issue still happens in gcc 9.4(I've been using clang 14 for ASAN testing). It looks gcc does not upcast int32 expression to int64 implicitly.
I did further fix to apply explicit int64 cast to the expression (max - min + 1)
here: https://github.com/syoyo/tinyexr/commit/2a4dd61afc62d35348df75fc1cbd7142cf331041
Now test_tinyexr
should report
Load EXR err: data height too large.(code -4)
both for gcc(9.4) and clang(14.0)
If you still see the issue, please describe the compiler and its version you are using.
Describe the issue
requested allocation size 0x3fffffffe0000008 (0x3fffffffe0001008 after adjustments for alignment, red zones etc.) exceeds maximum supported size of 0x10000000000
To Reproduce
Environment
poc: poc
Steps to reproduce the behavior:
Expected behavior
Here is the trace reported by gdb:
Vulnerability analysis The value of the
exr_header->data_window
structure is as below, which allows the program to bypass the checks on lines 5760 and 5761 of tinyexr.h, reach line 5766 and causedata_height
to be-2147483631
. Although line 5775 tries to check the value ofdata_height
to avoid it being too large, this check is a signed comparison, and the current poc can still bypass this check. https://github.com/syoyo/tinyexr/blob/41cc1405bbc7ab05e99bd0d581f72aa6d2c190c7/tinyexr.h#L5760-L5779These two incomplete checks made the
num_blocks
calculated in line 5822 very large (576460752236314624), which eventually led to a memory error. https://github.com/syoyo/tinyexr/blob/41cc1405bbc7ab05e99bd0d581f72aa6d2c190c7/tinyexr.h#L5822-L5829