Apply "default unsafe" annotation across webputils

Import bounds_safety.h across all of webputils, with one exception being
dsp.h, since it's imported by webputils.h in one place. Also prepend
WEBP_ASSUME_UNSAFE_INDEXABLE_ABI to every webputil file to indicate to
the compiler that every pointer should be treated as __unsafe_indexable.

We also need to replace memcpy/memset/memmove with the unsafe variants
WEBP_UNSAFE_*, as memcpy/memset/memmove require bounded/sized pointers.

With this change, all of libwebputils (and libwebp) should build with
-DWEBP_ENABLE_FBOUNDS_SAFETY=true

Change-Id: Iad87be0455182d534c074ef6dc1a30fa66b74b6c
This commit is contained in:
mxms
2025-07-31 23:06:07 +00:00
committed by Max Shavrick
parent 44257cb826
commit ff87eeecc9
29 changed files with 130 additions and 29 deletions

View File

@@ -17,10 +17,13 @@
#include <stdlib.h>
#include <string.h>
#include "src/utils/bounds_safety.h"
#include "src/utils/utils.h"
#include "src/webp/format_constants.h"
#include "src/webp/types.h"
WEBP_ASSUME_UNSAFE_INDEXABLE_ABI
// -----------------------------------------------------------------------------
// Util function to optimize the symbol map for RLE coding
@@ -228,7 +231,8 @@ static void GenerateOptimalTree(const uint32_t* const histogram,
break;
}
}
memmove(tree + (k + 1), tree + k, (tree_size - k) * sizeof(*tree));
WEBP_UNSAFE_MEMMOVE(tree + (k + 1), tree + k,
(tree_size - k) * sizeof(*tree));
tree[k].total_count = count;
tree[k].value = -1;
@@ -408,7 +412,7 @@ void VP8LCreateHuffmanTree(uint32_t* const histogram, int tree_depth_limit,
uint8_t* const buf_rle, HuffmanTree* const huff_tree,
HuffmanTreeCode* const huff_code) {
const int num_symbols = huff_code->num_symbols;
memset(buf_rle, 0, num_symbols * sizeof(*buf_rle));
WEBP_UNSAFE_MEMSET(buf_rle, 0, num_symbols * sizeof(*buf_rle));
OptimizeHuffmanForRle(num_symbols, buf_rle, histogram);
GenerateOptimalTree(histogram, num_symbols, huff_tree, tree_depth_limit,
huff_code->code_lengths);