1 #include "hb-fuzzer.hh"
2
3 #include <hb-ot.h>
4 #include <string.h>
5
6 #define TEST_OT_FACE_NO_MAIN 1
7 #include "../api/test-ot-face.c"
8 #undef TEST_OT_FACE_NO_MAIN
9
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)10 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
11 {
12 hb_blob_t *blob = hb_blob_create ((const char *)data, size,
13 HB_MEMORY_MODE_READONLY, nullptr, nullptr);
14 hb_face_t *face = hb_face_create (blob, 0);
15 hb_font_t *font = hb_font_create (face);
16 hb_ot_font_set_funcs (font);
17 hb_font_set_scale (font, 12, 12);
18
19 {
20 const char text[] = "ABCDEXYZ123@_%&)*$!";
21 hb_buffer_t *buffer = hb_buffer_create ();
22 hb_buffer_add_utf8 (buffer, text, -1, 0, -1);
23 hb_buffer_guess_segment_properties (buffer);
24 hb_shape (font, buffer, nullptr, 0);
25 hb_buffer_destroy (buffer);
26 }
27
28 uint32_t text32[16] = {0};
29 unsigned int len = sizeof (text32);
30 if (size < len)
31 len = size;
32 memcpy(text32, data + size - len, len);
33
34 hb_buffer_t *buffer = hb_buffer_create ();
35 hb_buffer_add_utf32 (buffer, text32, sizeof (text32) / sizeof (text32[0]), 0, -1);
36 hb_buffer_guess_segment_properties (buffer);
37 hb_shape (font, buffer, nullptr, 0);
38 hb_buffer_destroy (buffer);
39
40 /* Misc calls on face. */
41 test_face (face, text32[15]);
42
43 hb_font_destroy (font);
44 hb_face_destroy (face);
45 hb_blob_destroy (blob);
46 return 0;
47 }
48