mirror of
https://github.com/webmproject/libwebp.git
synced 2025-08-29 07:12:05 +02:00
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:
@@ -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};
|
||||
|
@@ -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"
|
||||
|
Reference in New Issue
Block a user