2016-12-21 02:52:50 +00:00
|
|
|
#include "hb-fuzzer.hh"
|
|
|
|
|
2015-11-06 07:08:50 +00:00
|
|
|
#include <hb-ot.h>
|
2016-01-11 18:31:04 +00:00
|
|
|
#include <string.h>
|
2015-10-12 21:39:52 +00:00
|
|
|
|
2020-02-25 16:37:25 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2018-11-04 07:47:34 +00:00
|
|
|
#define TEST_OT_FACE_NO_MAIN 1
|
|
|
|
#include "../api/test-ot-face.c"
|
|
|
|
#undef TEST_OT_FACE_NO_MAIN
|
|
|
|
|
2020-08-11 22:00:33 +00:00
|
|
|
extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size)
|
2016-12-21 02:52:50 +00:00
|
|
|
{
|
2020-07-29 03:39:08 +00:00
|
|
|
alloc_state = size; /* see src/failing-alloc.c */
|
|
|
|
|
2018-10-19 05:36:42 +00:00
|
|
|
hb_blob_t *blob = hb_blob_create ((const char *)data, size,
|
2019-06-03 08:00:25 +00:00
|
|
|
HB_MEMORY_MODE_READONLY, nullptr, nullptr);
|
2018-10-19 05:36:42 +00:00
|
|
|
hb_face_t *face = hb_face_create (blob, 0);
|
|
|
|
hb_font_t *font = hb_font_create (face);
|
|
|
|
hb_ot_font_set_funcs (font);
|
|
|
|
hb_font_set_scale (font, 12, 12);
|
2015-10-12 21:39:52 +00:00
|
|
|
|
2020-02-25 16:37:25 +00:00
|
|
|
unsigned num_coords = 0;
|
|
|
|
if (size) num_coords = data[size - 1];
|
|
|
|
num_coords = hb_ot_var_get_axis_count (face) > num_coords ? num_coords : hb_ot_var_get_axis_count (face);
|
|
|
|
int *coords = (int *) calloc (num_coords, sizeof (int));
|
|
|
|
if (size > num_coords + 1)
|
|
|
|
for (unsigned i = 0; i < num_coords; ++i)
|
|
|
|
coords[i] = ((int) data[size - num_coords + i - 1] - 128) * 10;
|
|
|
|
hb_font_set_var_coords_normalized (font, coords, num_coords);
|
|
|
|
free (coords);
|
|
|
|
|
2016-01-11 18:31:04 +00:00
|
|
|
{
|
|
|
|
const char text[] = "ABCDEXYZ123@_%&)*$!";
|
2018-10-19 05:36:42 +00:00
|
|
|
hb_buffer_t *buffer = hb_buffer_create ();
|
|
|
|
hb_buffer_add_utf8 (buffer, text, -1, 0, -1);
|
|
|
|
hb_buffer_guess_segment_properties (buffer);
|
2020-07-30 10:59:43 +00:00
|
|
|
hb_shape (font, buffer, nullptr, 0);
|
2018-10-19 05:36:42 +00:00
|
|
|
hb_buffer_destroy (buffer);
|
2016-01-11 18:31:04 +00:00
|
|
|
}
|
|
|
|
|
2018-11-08 00:11:43 +00:00
|
|
|
uint32_t text32[16] = {0};
|
|
|
|
unsigned int len = sizeof (text32);
|
|
|
|
if (size < len)
|
|
|
|
len = size;
|
2020-03-03 16:57:19 +00:00
|
|
|
if (len)
|
2020-06-19 20:32:50 +00:00
|
|
|
memcpy (text32, data + size - len, len);
|
|
|
|
|
|
|
|
/* Misc calls on font. */
|
|
|
|
text32[10] = test_font (font, text32[15]) % 256;
|
2015-10-12 21:39:52 +00:00
|
|
|
|
2018-11-08 00:11:43 +00:00
|
|
|
hb_buffer_t *buffer = hb_buffer_create ();
|
|
|
|
hb_buffer_add_utf32 (buffer, text32, sizeof (text32) / sizeof (text32[0]), 0, -1);
|
|
|
|
hb_buffer_guess_segment_properties (buffer);
|
2020-07-30 10:59:43 +00:00
|
|
|
hb_shape (font, buffer, nullptr, 0);
|
2018-11-08 00:11:43 +00:00
|
|
|
hb_buffer_destroy (buffer);
|
|
|
|
|
2018-10-19 05:36:42 +00:00
|
|
|
hb_font_destroy (font);
|
|
|
|
hb_face_destroy (face);
|
|
|
|
hb_blob_destroy (blob);
|
2015-10-12 21:39:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|