Repository navigation
stb_vorbis: fix codebook integer overflows in lookup_type 2 and pre-expansion - #2028
TristanInSec wants to merge 1 commit into
Conversation
…xpansion Two independent integer overflow bugs in the Vorbis codebook setup: 1. lookup_type 2: `c->lookup_values = c->entries * c->dimensions` multiplies two int values (24-bit entries, 16-bit dimensions) that can exceed INT_MAX, causing signed overflow (UB). The wrapped value leads to undersized multiplicands allocation and OOB read at decode time. Add overflow check and compute in uint32. 2. lookup_type 1 pre-expansion: the index `j*c->dimensions + k` overflows as int*int for large codebook parameters, causing OOB write into the multiplicands array during setup. Add overflow bounds check on entries*dimensions before allocation, and cast the index arithmetic to unsigned int to avoid signed overflow UB.
|
See comments for previous PR. We now enforce a much tighter limit for dimension*entries (at most As for 2), in that loop, All these fixes are already in the dev branch and will be in the next release. |
|
Agreed, the codebook entry limit is the right approach -- eliminates the overflow class entirely. Thanks for the explanation on the dev branch changes. |
Summary
Two independent integer overflow bugs in the Vorbis codebook setup path:
1. lookup_type 2:
entries * dimensionsoverflow (line 3860)c->lookup_values = c->entries * c->dimensionsmultiplies twointvalues (24-bit entries from bitstream, 16-bit dimensions) that can exceedINT_MAX, causing signed integer overflow (undefined behavior). The wrapped result leads to an undersizedmultiplicandsallocation, and OOB heap reads at decode time whenz *= c->dimensionsindexes past the array.2. lookup_type 1 pre-expansion: index overflow (line 3889)
The index expression
j * c->dimensions + kis computed asint * int + int. For large codebook parameters (e.g.j >= 32768withdimensions = 65535), the product exceedsINT_MAX, causing signed overflow. The wrapped index causes OOB writes into themultiplicandsheap allocation during codebook setup.Fix
entries * dimensionsbefore storing tolookup_values, and compute inuint32arithmetic.entries * dimensionsbounds checks before the pre-expansion allocation (both sparse and non-sparse paths).unsigned intto avoid signed overflow UB.