From d134f8882458a84b672dc41f6e74b2ec7dc4213e Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 23 Mar 2026 20:26:18 -0600 Subject: [PATCH] [vector] Fix clear() when vector is in error state clear() called resize(0) which calls alloc(0), but alloc() bails immediately when the vector is in error state, so length was never zeroed. Under failing-malloc, a vector could enter error state from a failed push, making all subsequent clear() calls silently fail, leaving stale pointers. This caused a heap-use-after-free in hb_raster_paint_destroy(): render() released surfaces to surface_cache then called surface_stack.clear() which silently failed, so destroy() iterated the stale surface_stack pointers and double-freed images already in surface_cache. Fixes https://oss-fuzz.com/testcase?key=5078588000108544 Co-Authored-By: Claude Opus 4.6 (1M context) --- src/hb-vector.hh | 3 ++- ...se-minimized-hb-raster-fuzzer-5078588000108544 | Bin 0 -> 162 bytes 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-raster-fuzzer-5078588000108544 diff --git a/src/hb-vector.hh b/src/hb-vector.hh index 71c0c27a1..9536ab63d 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -577,7 +577,8 @@ struct hb_vector_t HB_ALWAYS_INLINE_VECTOR_ALLOCS void clear () { - resize (0); + if (!resize (0)) + length = 0; /* If resize fails (e.g. vector in error state), still clear length. */ } template diff --git a/test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-raster-fuzzer-5078588000108544 b/test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-raster-fuzzer-5078588000108544 new file mode 100644 index 0000000000000000000000000000000000000000..9eb51284dbe2fbaebcf1015d7b37e3892e46b529 GIT binary patch literal 162 zcmXwwK?;CC3tHT%?bYiP(PkBhH|j`dc5_fm-LU%yDZ(I~ literal 0 HcmV?d00001