Add fbounds-safety annotations for data.

Reasoning:

The `data` parameter in `QuantizeLevels` (defined in
`src/utils/quant_levels_utils.c` line 33) was causing bounds safety
errors because it was accessed using array subscripts (e.g., `data[n]`
at lines 60-63 and 137) but was typed as a single pointer. The size of
the buffer pointed to by `data` is determined by the `width` and
`height` parameters, calculated as `data_size = height * width` at
line 39. The loops accessing `data` iterate up to `data_size`. To fix
this, the `data` parameter in both the function definition and its
declaration (`src/utils/quant_levels_utils.h` line 30) was annotated
with `WEBP_COUNTED_BY((size_t)width * height)`.

Bug: 432511821
Change-Id: Idfe8810eaaf1239d86e38eb661a1a987d817127c
This commit is contained in:
Arman Hasanzadeh
2025-08-19 22:33:39 -07:00
parent f2061209d0
commit ddabb66f23
2 changed files with 4 additions and 4 deletions

View File

@@ -30,8 +30,8 @@ WEBP_ASSUME_UNSAFE_INDEXABLE_ABI
// -----------------------------------------------------------------------------
// Quantize levels.
int QuantizeLevels(uint8_t* const data, int width, int height, int num_levels,
uint64_t* const sse) {
int QuantizeLevels(uint8_t* const WEBP_COUNTED_BY((size_t)width* height) data,
int width, int height, int num_levels, uint64_t* const sse) {
int freq[NUM_SYMBOLS] = {0};
int q_level[NUM_SYMBOLS] = {0};
double inv_q_level[NUM_SYMBOLS] = {0};

View File

@@ -29,8 +29,8 @@ extern "C" {
// quantized values. If not NULL, 'sse' will contain the sum of squared error.
// Valid range for 'num_levels' is [2, 256].
// Returns false in case of error (data is NULL, or parameters are invalid).
int QuantizeLevels(uint8_t* const data, int width, int height, int num_levels,
uint64_t* const sse);
int QuantizeLevels(uint8_t* const WEBP_COUNTED_BY((size_t)width* height) data,
int width, int height, int num_levels, uint64_t* const sse);
#ifdef __cplusplus
} // extern "C"