1 #include "hb-fuzzer.hh"
10 trySubset (hb_face_t *face,
11 const hb_codepoint_t text[],
17 hb_subset_input_t *input = hb_subset_input_create_or_fail ();
18 hb_subset_input_set_drop_hints (input, drop_hints);
19 hb_subset_input_set_drop_layout (input, drop_layout);
20 hb_subset_input_set_retain_gids (input, retain_gids);
21 hb_set_t *codepoints = hb_subset_input_unicode_set (input);
23 for (int i = 0; i < text_length; i++)
25 hb_set_add (codepoints, text[i]);
28 hb_face_t *result = hb_subset (face, input);
29 hb_face_destroy (result);
31 hb_subset_input_destroy (input);
35 trySubset (hb_face_t *face,
36 const hb_codepoint_t text[],
38 const uint8_t flags[1])
40 bool drop_hints = flags[0] & (1 << 0);
41 bool drop_layout = flags[0] & (1 << 1);
42 bool retain_gids = flags[0] & (1 << 2);
43 trySubset (face, text, text_length,
44 drop_hints, drop_layout, retain_gids);
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 uint8_t flags[1] = {0};
59 const hb_codepoint_t text[] =
61 'A', 'B', 'C', 'D', 'E', 'X', 'Y', 'Z', '1', '2',
62 '3', '@', '_', '%', '&', ')', '*', '$', '!'
65 trySubset (face, text, sizeof (text) / sizeof (hb_codepoint_t), flags);
67 hb_codepoint_t text_from_data[16];
68 if (size > sizeof(text_from_data) + sizeof(flags)) {
69 memcpy (text_from_data,
70 data + size - sizeof(text_from_data),
71 sizeof(text_from_data));
74 data + size - sizeof(text_from_data) - sizeof(flags),
76 unsigned int text_size = sizeof (text_from_data) / sizeof (hb_codepoint_t);
78 trySubset (face, text_from_data, text_size, flags);
81 hb_face_destroy (face);
82 hb_blob_destroy (blob);