1 #include "hb-fuzzer.hh"
11 trySubset (hb_face_t *face,
12 const hb_codepoint_t text[],
15 hb_subset_input_t *input)
19 hb_subset_input_set_flags (input, (hb_subset_flags_t) flag_bits);
21 hb_set_t *codepoints = hb_subset_input_unicode_set (input);
23 for (int i = 0; i < text_length; i++)
24 hb_set_add (codepoints, text[i]);
26 hb_face_t *result = hb_subset_or_fail (face, input);
29 hb_blob_t *blob = hb_face_reference_blob (result);
31 const char *data = hb_blob_get_data (blob, &length);
33 // Something not optimizable just to access all the blob data
34 unsigned int bytes_count = 0;
35 for (unsigned int i = 0; i < length; ++i)
36 if (data[i]) ++bytes_count;
37 assert (bytes_count || !length);
39 hb_blob_destroy (blob);
41 hb_face_destroy (result);
43 hb_subset_input_destroy (input);
46 extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size)
48 alloc_state = _fuzzing_alloc_state (data, size);
50 hb_blob_t *blob = hb_blob_create ((const char *) data, size,
51 HB_MEMORY_MODE_READONLY, nullptr, nullptr);
52 hb_face_t *face = hb_face_create (blob, 0);
54 /* Just test this API here quickly. */
55 hb_set_t *output = hb_set_create ();
56 hb_face_collect_unicodes (face, output);
57 hb_set_destroy (output);
59 unsigned flags = HB_SUBSET_FLAGS_DEFAULT;
60 const hb_codepoint_t text[] =
62 'A', 'B', 'C', 'D', 'E', 'X', 'Y', 'Z', '1', '2',
63 '3', '@', '_', '%', '&', ')', '*', '$', '!'
66 hb_subset_input_t *input = hb_subset_input_create_or_fail ();
69 hb_face_destroy (face);
70 hb_blob_destroy (blob);
73 trySubset (face, text, sizeof (text) / sizeof (hb_codepoint_t), flags, input);
76 hb_codepoint_t text_from_data[16];
77 if (size > sizeof (text_from_data) + sizeof (flags) + sizeof(num_axes)) {
78 hb_subset_input_t *input = hb_subset_input_create_or_fail ();
81 hb_face_destroy (face);
82 hb_blob_destroy (blob);
85 size -= sizeof (text_from_data);
86 memcpy (text_from_data,
88 sizeof (text_from_data));
90 size -= sizeof (flags);
95 size -= sizeof (num_axes);
100 if (num_axes > 0 && num_axes < 8 && size > num_axes * (sizeof(hb_tag_t) + sizeof(int)))
102 for (unsigned i = 0; i < num_axes; i++) {
105 size -= sizeof (tag);
109 size -= sizeof (value);
114 hb_subset_input_pin_axis_location(input,
123 unsigned int text_size = sizeof (text_from_data) / sizeof (hb_codepoint_t);
124 trySubset (face, text_from_data, text_size, flags, input);
127 hb_face_destroy (face);
128 hb_blob_destroy (blob);