[fuzzer] In 50% of runs don't fail the allocator
This commit is contained in:
parent
14b018124c
commit
b8c7c0a0e6
|
@ -118,7 +118,7 @@ static void misc_calls_for_gid (hb_face_t *face, hb_font_t *font, hb_set_t *set,
|
||||||
|
|
||||||
extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size)
|
extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size)
|
||||||
{
|
{
|
||||||
alloc_state = size; /* see src/failing-alloc.c */
|
alloc_state = _fuzzing_alloc_state (data, size);
|
||||||
|
|
||||||
hb_blob_t *blob = hb_blob_create ((const char *) data, size,
|
hb_blob_t *blob = hb_blob_create ((const char *) data, size,
|
||||||
HB_MEMORY_MODE_READONLY, nullptr, nullptr);
|
HB_MEMORY_MODE_READONLY, nullptr, nullptr);
|
||||||
|
|
|
@ -10,9 +10,25 @@ extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HB_IS_IN_FUZZER
|
#ifdef HB_IS_IN_FUZZER
|
||||||
|
|
||||||
/* See src/failing-alloc.c */
|
/* See src/failing-alloc.c */
|
||||||
extern "C" int alloc_state;
|
extern "C" int alloc_state;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
/* Just a dummy global variable */
|
/* Just a dummy global variable */
|
||||||
static int HB_UNUSED alloc_state = 0;
|
static int HB_UNUSED alloc_state = 0;
|
||||||
|
|
||||||
#endif
|
#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;
|
||||||
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ static hb_set_t *create_set (const uint32_t *value_array, int count)
|
||||||
|
|
||||||
extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size)
|
extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size)
|
||||||
{
|
{
|
||||||
alloc_state = size; /* see src/failing-alloc.c */
|
alloc_state = _fuzzing_alloc_state (data, size);
|
||||||
|
|
||||||
if (size < sizeof (instructions_t))
|
if (size < sizeof (instructions_t))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size)
|
extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size)
|
||||||
{
|
{
|
||||||
alloc_state = size; /* see src/failing-alloc.c */
|
alloc_state = _fuzzing_alloc_state (data, size);
|
||||||
|
|
||||||
hb_blob_t *blob = hb_blob_create ((const char *)data, size,
|
hb_blob_t *blob = hb_blob_create ((const char *)data, size,
|
||||||
HB_MEMORY_MODE_READONLY, nullptr, nullptr);
|
HB_MEMORY_MODE_READONLY, nullptr, nullptr);
|
||||||
|
|
|
@ -45,7 +45,7 @@ trySubset (hb_face_t *face,
|
||||||
|
|
||||||
extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size)
|
extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size)
|
||||||
{
|
{
|
||||||
alloc_state = size; /* see src/failing-alloc.c */
|
alloc_state = _fuzzing_alloc_state (data, size);
|
||||||
|
|
||||||
hb_blob_t *blob = hb_blob_create ((const char *) data, size,
|
hb_blob_t *blob = hb_blob_create ((const char *) data, size,
|
||||||
HB_MEMORY_MODE_READONLY, nullptr, nullptr);
|
HB_MEMORY_MODE_READONLY, nullptr, nullptr);
|
||||||
|
|
Loading…
Reference in New Issue