1 #include "hb-fuzzer.hh"
10 trySubset (hb_face_t *face,
11 const hb_codepoint_t text[],
16 hb_subset_input_t *input = hb_subset_input_create_or_fail ();
17 hb_subset_input_set_drop_hints (input, drop_hints);
18 hb_subset_input_set_drop_layout (input, drop_layout);
19 hb_set_t *codepoints = hb_subset_input_unicode_set (input);
21 for (int i = 0; i < text_length; i++)
23 hb_set_add (codepoints, text[i]);
26 hb_face_t *result = hb_subset (face, input);
27 hb_face_destroy (result);
29 hb_subset_input_destroy (input);
33 trySubset (hb_face_t *face,
34 const hb_codepoint_t text[],
37 for (unsigned int drop_hints = 0; drop_hints < 2; drop_hints++)
39 for (unsigned int drop_layout = 0; drop_layout < 2; drop_layout++)
41 trySubset (face, text, text_length,
42 (bool) drop_hints, (bool) drop_layout);
47 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
49 hb_blob_t *blob = hb_blob_create ((const char *)data, size,
50 HB_MEMORY_MODE_READONLY, NULL, NULL);
51 hb_face_t *face = hb_face_create (blob, 0);
53 /* Just test this API here quickly. */
54 hb_set_t *output = hb_set_create();
55 hb_face_collect_unicodes (face, output);
56 hb_set_destroy (output);
58 const hb_codepoint_t text[] =
60 'A', 'B', 'C', 'D', 'E', 'X', 'Y', 'Z', '1', '2',
61 '3', '@', '_', '%', '&', ')', '*', '$', '!'
64 trySubset (face, text, sizeof (text) / sizeof (hb_codepoint_t));
66 hb_codepoint_t text_from_data[16];
67 if (size > sizeof(text_from_data)) {
68 memcpy (text_from_data,
69 data + size - sizeof(text_from_data),
70 sizeof(text_from_data));
71 unsigned int text_size = sizeof (text_from_data) / sizeof (hb_codepoint_t);
72 trySubset (face, text_from_data, text_size);
75 hb_face_destroy (face);
76 hb_blob_destroy (blob);