2020-02-06 22:02:58 +01:00
|
|
|
#include "hb-fuzzer.hh"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "hb.h"
|
|
|
|
|
2021-01-26 00:57:42 +01:00
|
|
|
// Only allow ~5,000 set values between the two input sets.
|
Fix various typos
Found via `codespell -q 3 -S ./perf/texts -L actualy,ba,beng,fo,gir,inout,nd,ot,pres,ro,te,teh,timne`
2022-01-16 13:00:53 +01:00
|
|
|
// Arbitrarily long input sets do not trigger any meaningful
|
2021-01-26 00:57:42 +01:00
|
|
|
// differences in behaviour so there's no benefit from allowing
|
|
|
|
// the fuzzer to create super large sets.
|
|
|
|
#define MAX_INPUT_SIZE 20000
|
|
|
|
|
2020-02-06 22:02:58 +01:00
|
|
|
enum set_operation_t : uint8_t
|
|
|
|
{
|
2020-02-11 21:25:57 +01:00
|
|
|
INTERSECT = 0,
|
|
|
|
UNION = 1,
|
|
|
|
SUBTRACT = 2,
|
|
|
|
SYMMETRIC_DIFFERENCE = 3
|
2020-02-06 22:02:58 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct instructions_t
|
|
|
|
{
|
|
|
|
set_operation_t operation;
|
|
|
|
uint32_t first_set_size;
|
|
|
|
};
|
|
|
|
|
2020-02-12 16:55:10 +01:00
|
|
|
static hb_set_t *create_set (const uint32_t *value_array, int count)
|
2020-02-06 22:02:58 +01:00
|
|
|
{
|
2020-02-12 16:55:10 +01:00
|
|
|
hb_set_t *set = hb_set_create ();
|
|
|
|
for (int i = 0; i < count; i++)
|
2020-02-06 22:02:58 +01:00
|
|
|
hb_set_add (set, value_array[i]);
|
|
|
|
return set;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size)
|
|
|
|
{
|
2022-07-01 20:11:15 +02:00
|
|
|
alloc_state = _fuzzing_alloc_state (data, size);
|
2020-07-14 16:59:58 +02:00
|
|
|
|
2020-02-12 13:11:22 +01:00
|
|
|
if (size < sizeof (instructions_t))
|
2020-02-06 22:02:58 +01:00
|
|
|
return 0;
|
|
|
|
|
2021-01-26 00:57:42 +01:00
|
|
|
if (size > MAX_INPUT_SIZE)
|
|
|
|
return 0;
|
|
|
|
|
2020-07-04 21:26:10 +02:00
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
|
2020-02-12 16:55:10 +01:00
|
|
|
const instructions_t &instructions = reinterpret_cast<const instructions_t &> (data);
|
2020-07-04 21:26:10 +02:00
|
|
|
#pragma GCC diagnostic pop
|
2020-02-12 13:11:22 +01:00
|
|
|
data += sizeof (instructions_t);
|
|
|
|
size -= sizeof (instructions_t);
|
2020-02-06 22:02:58 +01:00
|
|
|
|
2020-02-12 16:55:10 +01:00
|
|
|
const uint32_t *values = reinterpret_cast<const uint32_t *> (data);
|
2020-02-12 13:11:22 +01:00
|
|
|
size = size / sizeof (uint32_t);
|
2020-02-06 22:02:58 +01:00
|
|
|
|
2020-02-12 16:55:10 +01:00
|
|
|
if (size < instructions.first_set_size)
|
2020-02-06 22:02:58 +01:00
|
|
|
return 0;
|
|
|
|
|
2020-02-12 16:55:10 +01:00
|
|
|
hb_set_t *set_a = create_set (values, instructions.first_set_size);
|
2020-02-06 22:02:58 +01:00
|
|
|
|
2020-02-12 16:55:10 +01:00
|
|
|
values += instructions.first_set_size;
|
|
|
|
size -= instructions.first_set_size;
|
|
|
|
hb_set_t *set_b = create_set (values, size);
|
2020-02-06 22:02:58 +01:00
|
|
|
|
2020-02-12 16:55:10 +01:00
|
|
|
switch (instructions.operation)
|
2020-02-06 22:02:58 +01:00
|
|
|
{
|
2020-02-12 16:55:10 +01:00
|
|
|
case INTERSECT:
|
|
|
|
hb_set_intersect (set_a, set_b);
|
|
|
|
break;
|
|
|
|
case UNION:
|
|
|
|
hb_set_union (set_a, set_b);
|
|
|
|
break;
|
|
|
|
case SUBTRACT:
|
|
|
|
hb_set_subtract (set_a, set_b);
|
|
|
|
break;
|
|
|
|
case SYMMETRIC_DIFFERENCE:
|
|
|
|
hb_set_symmetric_difference (set_a, set_b);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2020-02-06 22:02:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
hb_set_destroy (set_a);
|
|
|
|
hb_set_destroy (set_b);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|