From ddabb66f23f21538174c5abf4a0c067cc13bf70a Mon Sep 17 00:00:00 2001 From: Arman Hasanzadeh Date: Tue, 19 Aug 2025 22:33:39 -0700 Subject: [PATCH] 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 --- src/utils/quant_levels_utils.c | 4 ++-- src/utils/quant_levels_utils.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/utils/quant_levels_utils.c b/src/utils/quant_levels_utils.c index 71401647..5c1c767b 100644 --- a/src/utils/quant_levels_utils.c +++ b/src/utils/quant_levels_utils.c @@ -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}; diff --git a/src/utils/quant_levels_utils.h b/src/utils/quant_levels_utils.h index 43eecf2a..e2e4486d 100644 --- a/src/utils/quant_levels_utils.h +++ b/src/utils/quant_levels_utils.h @@ -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"