2018-03-12 23:08:16 +00:00
|
|
|
#include "hb-fuzzer.hh"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "hb-subset.h"
|
|
|
|
|
2018-10-02 18:09:19 +00:00
|
|
|
static void
|
|
|
|
trySubset (hb_face_t *face,
|
|
|
|
const hb_codepoint_t text[],
|
|
|
|
int text_length,
|
|
|
|
bool drop_hints,
|
2019-01-30 23:23:19 +00:00
|
|
|
bool drop_layout,
|
|
|
|
bool retain_gids)
|
2018-03-12 23:08:16 +00:00
|
|
|
{
|
|
|
|
hb_subset_input_t *input = hb_subset_input_create_or_fail ();
|
2018-08-30 01:24:03 +00:00
|
|
|
hb_subset_input_set_drop_hints (input, drop_hints);
|
|
|
|
hb_subset_input_set_drop_layout (input, drop_layout);
|
2019-01-30 23:23:19 +00:00
|
|
|
hb_subset_input_set_retain_gids (input, retain_gids);
|
2018-03-12 23:08:16 +00:00
|
|
|
hb_set_t *codepoints = hb_subset_input_unicode_set (input);
|
|
|
|
|
2018-05-31 23:47:39 +00:00
|
|
|
for (int i = 0; i < text_length; i++)
|
2018-03-12 23:08:16 +00:00
|
|
|
{
|
|
|
|
hb_set_add (codepoints, text[i]);
|
|
|
|
}
|
|
|
|
|
2018-08-30 01:09:55 +00:00
|
|
|
hb_face_t *result = hb_subset (face, input);
|
2018-04-19 20:39:57 +00:00
|
|
|
hb_face_destroy (result);
|
2018-03-12 23:08:16 +00:00
|
|
|
|
|
|
|
hb_subset_input_destroy (input);
|
2018-05-31 23:47:39 +00:00
|
|
|
}
|
|
|
|
|
2018-10-02 18:09:19 +00:00
|
|
|
static void
|
|
|
|
trySubset (hb_face_t *face,
|
|
|
|
const hb_codepoint_t text[],
|
2019-01-30 23:23:19 +00:00
|
|
|
int text_length,
|
|
|
|
const uint8_t flags[1])
|
2018-06-07 21:39:03 +00:00
|
|
|
{
|
2019-01-30 23:23:19 +00:00
|
|
|
bool drop_hints = flags[0] & (1 << 0);
|
|
|
|
bool drop_layout = flags[0] & (1 << 1);
|
|
|
|
bool retain_gids = flags[0] & (1 << 2);
|
|
|
|
trySubset (face, text, text_length,
|
|
|
|
drop_hints, drop_layout, retain_gids);
|
2018-06-07 21:39:03 +00:00
|
|
|
}
|
|
|
|
|
2018-05-31 23:47:39 +00:00
|
|
|
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
|
|
|
{
|
|
|
|
hb_blob_t *blob = hb_blob_create ((const char *)data, size,
|
2018-10-02 18:09:19 +00:00
|
|
|
HB_MEMORY_MODE_READONLY, NULL, NULL);
|
2018-05-31 23:47:39 +00:00
|
|
|
hb_face_t *face = hb_face_create (blob, 0);
|
|
|
|
|
2018-10-11 21:08:12 +00:00
|
|
|
/* Just test this API here quickly. */
|
|
|
|
hb_set_t *output = hb_set_create();
|
|
|
|
hb_face_collect_unicodes (face, output);
|
|
|
|
hb_set_destroy (output);
|
|
|
|
|
2019-01-30 23:23:19 +00:00
|
|
|
uint8_t flags[1] = {0};
|
2018-05-31 23:47:39 +00:00
|
|
|
const hb_codepoint_t text[] =
|
|
|
|
{
|
2018-10-02 18:09:19 +00:00
|
|
|
'A', 'B', 'C', 'D', 'E', 'X', 'Y', 'Z', '1', '2',
|
|
|
|
'3', '@', '_', '%', '&', ')', '*', '$', '!'
|
2018-05-31 23:47:39 +00:00
|
|
|
};
|
|
|
|
|
2019-01-30 23:23:19 +00:00
|
|
|
trySubset (face, text, sizeof (text) / sizeof (hb_codepoint_t), flags);
|
2018-05-31 23:47:39 +00:00
|
|
|
|
|
|
|
hb_codepoint_t text_from_data[16];
|
2019-01-30 23:23:19 +00:00
|
|
|
if (size > sizeof(text_from_data) + sizeof(flags)) {
|
2018-10-02 18:09:19 +00:00
|
|
|
memcpy (text_from_data,
|
|
|
|
data + size - sizeof(text_from_data),
|
|
|
|
sizeof(text_from_data));
|
2019-01-30 23:23:19 +00:00
|
|
|
|
|
|
|
memcpy (flags,
|
|
|
|
data + size - sizeof(text_from_data) - sizeof(flags),
|
|
|
|
sizeof(flags));
|
2018-05-31 23:47:39 +00:00
|
|
|
unsigned int text_size = sizeof (text_from_data) / sizeof (hb_codepoint_t);
|
2019-01-30 23:23:19 +00:00
|
|
|
|
|
|
|
trySubset (face, text_from_data, text_size, flags);
|
2018-05-31 23:47:39 +00:00
|
|
|
}
|
|
|
|
|
2018-03-12 23:08:16 +00:00
|
|
|
hb_face_destroy (face);
|
|
|
|
hb_blob_destroy (blob);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|