mirror of
https://github.com/webmproject/libwebp.git
synced 2025-07-03 17:44:29 +02:00
BuildHuffmanTable: add an assert for offset[] bounds
And provide a clear comment explaining why the index of offset[] is always checked within bounds. Bug:webp:622 Change-Id: Id9b973a804b74c53dfb291f1a9dae649c0daed9d
This commit is contained in:
parent
85e098e58d
commit
fa6f56496a
@ -124,6 +124,10 @@ static int BuildHuffmanTable(HuffmanCode* const root_table, int root_bits,
|
|||||||
const int symbol_code_length = code_lengths[symbol];
|
const int symbol_code_length = code_lengths[symbol];
|
||||||
if (code_lengths[symbol] > 0) {
|
if (code_lengths[symbol] > 0) {
|
||||||
if (sorted != NULL) {
|
if (sorted != NULL) {
|
||||||
|
assert(offset[symbol_code_length] < code_lengths_size);
|
||||||
|
// The following check is not redundant with the assert. It prevents a
|
||||||
|
// potential buffer overflow that the optimizer might not be able to
|
||||||
|
// rule out on its own.
|
||||||
if (offset[symbol_code_length] >= code_lengths_size) {
|
if (offset[symbol_code_length] >= code_lengths_size) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user