From f66f1ee95cd37bc68c934ea8a3e64b0825d74cce Mon Sep 17 00:00:00 2001 From: Arman Hasanzadeh Date: Tue, 19 Aug 2025 22:15:25 -0700 Subject: [PATCH] Add fbounds-safety annotations for `count`. Reasoning: The function `NextTableBitSize` is only called by `BuildHuffmanTable` (src/utils/huffman_utils.c:196). In `BuildHuffmanTable`, `count` is defined as a local array `int count[MAX_ALLOWED_CODE_LENGTH + 1]` (line 93). This array decays to a pointer when passed to `NextTableBitSize`. The maximum index accessed within `NextTableBitSize` is `MAX_ALLOWED_CODE_LENGTH - 1` (line 75, inside a loop where `len` starts <= `MAX_ALLOWED_CODE_LENGTH` and increments up to `MAX_ALLOWED_CODE_LENGTH`). Since the caller provides an array of size `MAX_ALLOWED_CODE_LENGTH + 1` and the accesses are within bounds, the `count` parameter in `NextTableBitSize` is annotated with `WEBP_COUNTED_BY(MAX_ALLOWED_CODE_LENGTH + 1)`. This resolves the compiler error. Bug: 432511821 Change-Id: I29a55dd7f09c04aa3a2394996cf0e123d985fcd0 --- src/utils/huffman_utils.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/utils/huffman_utils.c b/src/utils/huffman_utils.c index 8f12eac1..0c822164 100644 --- a/src/utils/huffman_utils.c +++ b/src/utils/huffman_utils.c @@ -68,8 +68,9 @@ static WEBP_INLINE void ReplicateValue(HuffmanCode* table, int step, int end, // Returns the table width of the next 2nd level table. count is the histogram // of bit lengths for the remaining symbols, len is the code length of the next // processed symbol -static WEBP_INLINE int NextTableBitSize(const int* const count, int len, - int root_bits) { +static WEBP_INLINE int NextTableBitSize( + const int* const WEBP_COUNTED_BY(MAX_ALLOWED_CODE_LENGTH + 1) count, + int len, int root_bits) { int left = 1 << (len - root_bits); while (len < MAX_ALLOWED_CODE_LENGTH) { left -= count[len];