diff options
Diffstat (limited to 'test/fuzzing/hb-fuzzer.hh')
-rw-r--r-- | test/fuzzing/hb-fuzzer.hh | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/test/fuzzing/hb-fuzzer.hh b/test/fuzzing/hb-fuzzer.hh index 52e00dd0e..b7090a94a 100644 --- a/test/fuzzing/hb-fuzzer.hh +++ b/test/fuzzing/hb-fuzzer.hh @@ -10,9 +10,25 @@ extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size); #endif #ifdef HB_IS_IN_FUZZER + /* See src/failing-alloc.c */ extern "C" int alloc_state; + #else + /* Just a dummy global variable */ static int HB_UNUSED alloc_state = 0; + #endif + +static inline int +_fuzzing_alloc_state (const uint8_t *data, size_t size) +{ + /* https://github.com/harfbuzz/harfbuzz/pull/2764#issuecomment-1172589849 */ + + /* In 50% of the runs, don't fail the allocator. */ + if (size && data[size - 1] < 0x80) + return 0; + + return size; +} |