Merge pull request #1567 from googlefonts/fuzzer

[subset] Update the subset fuzzer to get  options to use from test case.
This commit is contained in:
Behdad Esfahbod 2019-01-30 18:36:57 -05:00 committed by GitHub
commit d14d2c20b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 13 deletions

View File

@ -11,11 +11,13 @@ trySubset (hb_face_t *face,
const hb_codepoint_t text[], const hb_codepoint_t text[],
int text_length, int text_length,
bool drop_hints, bool drop_hints,
bool drop_layout) bool drop_layout,
bool retain_gids)
{ {
hb_subset_input_t *input = hb_subset_input_create_or_fail (); hb_subset_input_t *input = hb_subset_input_create_or_fail ();
hb_subset_input_set_drop_hints (input, drop_hints); hb_subset_input_set_drop_hints (input, drop_hints);
hb_subset_input_set_drop_layout (input, drop_layout); hb_subset_input_set_drop_layout (input, drop_layout);
hb_subset_input_set_retain_gids (input, retain_gids);
hb_set_t *codepoints = hb_subset_input_unicode_set (input); hb_set_t *codepoints = hb_subset_input_unicode_set (input);
for (int i = 0; i < text_length; i++) for (int i = 0; i < text_length; i++)
@ -32,16 +34,14 @@ trySubset (hb_face_t *face,
static void static void
trySubset (hb_face_t *face, trySubset (hb_face_t *face,
const hb_codepoint_t text[], const hb_codepoint_t text[],
int text_length) int text_length,
const uint8_t flags[1])
{ {
for (unsigned int drop_hints = 0; drop_hints < 2; drop_hints++) bool drop_hints = flags[0] & (1 << 0);
{ bool drop_layout = flags[0] & (1 << 1);
for (unsigned int drop_layout = 0; drop_layout < 2; drop_layout++) bool retain_gids = flags[0] & (1 << 2);
{ trySubset (face, text, text_length,
trySubset (face, text, text_length, drop_hints, drop_layout, retain_gids);
(bool) drop_hints, (bool) drop_layout);
}
}
} }
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
@ -55,21 +55,27 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
hb_face_collect_unicodes (face, output); hb_face_collect_unicodes (face, output);
hb_set_destroy (output); hb_set_destroy (output);
uint8_t flags[1] = {0};
const hb_codepoint_t text[] = const hb_codepoint_t text[] =
{ {
'A', 'B', 'C', 'D', 'E', 'X', 'Y', 'Z', '1', '2', 'A', 'B', 'C', 'D', 'E', 'X', 'Y', 'Z', '1', '2',
'3', '@', '_', '%', '&', ')', '*', '$', '!' '3', '@', '_', '%', '&', ')', '*', '$', '!'
}; };
trySubset (face, text, sizeof (text) / sizeof (hb_codepoint_t)); trySubset (face, text, sizeof (text) / sizeof (hb_codepoint_t), flags);
hb_codepoint_t text_from_data[16]; hb_codepoint_t text_from_data[16];
if (size > sizeof(text_from_data)) { if (size > sizeof(text_from_data) + sizeof(flags)) {
memcpy (text_from_data, memcpy (text_from_data,
data + size - sizeof(text_from_data), data + size - sizeof(text_from_data),
sizeof(text_from_data)); sizeof(text_from_data));
memcpy (flags,
data + size - sizeof(text_from_data) - sizeof(flags),
sizeof(flags));
unsigned int text_size = sizeof (text_from_data) / sizeof (hb_codepoint_t); unsigned int text_size = sizeof (text_from_data) / sizeof (hb_codepoint_t);
trySubset (face, text_from_data, text_size);
trySubset (face, text_from_data, text_size, flags);
} }
hb_face_destroy (face); hb_face_destroy (face);