harfbuzz/test/fuzzing/hb-fuzzer.hh

35 lines
693 B
C++
Raw Normal View History

#include <hb.h>
#include <stddef.h>
2020-08-12 00:00:33 +02:00
extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size);
2020-07-14 16:59:58 +02:00
#if defined(__GNUC__) && (__GNUC__ >= 4) || (__clang__)
#define HB_UNUSED __attribute__((unused))
#else
#define HB_UNUSED
#endif
2020-07-14 16:59:58 +02:00
#ifdef HB_IS_IN_FUZZER
2020-07-14 16:59:58 +02:00
/* See src/failing-alloc.c */
extern "C" int alloc_state;
2020-07-14 16:59:58 +02:00
#else
2020-07-14 16:59:58 +02:00
/* Just a dummy global variable */
static int HB_UNUSED alloc_state = 0;
2020-07-14 16:59:58 +02:00
#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;
}