Closed pietroborrello closed 1 year ago
I did a quick analysis of file id_000154,sig_06,src_002783+000969,time_39921237,op_splice,rep_4,trial_1492432
(which also crashes a Windows Address Sanitizer build) as part of putting together PR #1297.
This crashes in a slightly different place than in issue #1289: the immediate cause within stbi__jpeg_huff_decode
is that
h->maxcode[k]
is supposed to be monotonic, but gets into a state where it isn't.
As a result, k steps past the end of h->maxcode
until it reaches some memory (at k == 31
) that
happens to satisfy the condition. This passes the k == 17
check at the end, and
crashes in the line
c = ((j->code_buffer >> (32 - k)) & stbi__bmask[k]) + h->delta[k];
However, this doesn't answer how h->maxcode[k] became non-monotonic by itself. This seems to be ultimately the same mechanism as in issue #1289! The sum of the sizes array is greater than 256, so we get writes past the end of huff_dc[*].values
or huff_ac[*].values
both in the "DHT - define huffman table" block and in stbi__build_huffman
.
Tested and confirmed fixed by Neil's changes, now in dev branch. Will be fixed in the next release.
Fixed in 2.28.
Describe the bug Several UBSAN violations possibly related to #1289 The zip attached contains the testcases that trigger the violation
To Reproduce Built stb according to the oss-fuzz script with
CXXFLAGS='-O1 -fsanitize=address -fsanitize=array-bounds,bool,builtin,enum,float-divide-by-zero,function,integer-divide-by-zero,null,object-size,return,returns-nonnull-attribute,shift,signed-integer-overflow,unreachable,vla-bound,vptr'
Sample output
Crashing files ubsan-out-of-bounds.zip