2018-03-13 00:08:16 +01:00
|
|
|
#include "hb-fuzzer.hh"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2019-07-10 11:58:06 +02:00
|
|
|
#include <assert.h>
|
2018-03-13 00:08:16 +01:00
|
|
|
|
|
|
|
#include "hb-subset.h"
|
|
|
|
|
2018-10-02 20:09:19 +02:00
|
|
|
static void
|
|
|
|
trySubset (hb_face_t *face,
|
|
|
|
const hb_codepoint_t text[],
|
|
|
|
int text_length,
|
2023-02-22 21:54:20 +01:00
|
|
|
unsigned flag_bits,
|
|
|
|
hb_subset_input_t *input)
|
2018-03-13 00:08:16 +01:00
|
|
|
{
|
2020-07-15 07:24:32 +02:00
|
|
|
if (!input) return;
|
2018-03-13 00:08:16 +01:00
|
|
|
|
2021-07-30 00:25:41 +02:00
|
|
|
hb_subset_input_set_flags (input, (hb_subset_flags_t) flag_bits);
|
2021-07-29 20:52:14 +02:00
|
|
|
|
|
|
|
hb_set_t *codepoints = hb_subset_input_unicode_set (input);
|
2019-05-18 00:30:01 +02:00
|
|
|
|
2018-06-01 01:47:39 +02:00
|
|
|
for (int i = 0; i < text_length; i++)
|
2018-03-13 00:08:16 +01:00
|
|
|
hb_set_add (codepoints, text[i]);
|
|
|
|
|
2021-06-23 22:38:47 +02:00
|
|
|
hb_face_t *result = hb_subset_or_fail (face, input);
|
|
|
|
if (result)
|
2019-07-10 11:58:06 +02:00
|
|
|
{
|
|
|
|
hb_blob_t *blob = hb_face_reference_blob (result);
|
|
|
|
unsigned int length;
|
|
|
|
const char *data = hb_blob_get_data (blob, &length);
|
|
|
|
|
|
|
|
// Something not optimizable just to access all the blob data
|
|
|
|
unsigned int bytes_count = 0;
|
|
|
|
for (unsigned int i = 0; i < length; ++i)
|
|
|
|
if (data[i]) ++bytes_count;
|
2019-07-11 12:01:55 +02:00
|
|
|
assert (bytes_count || !length);
|
2019-07-10 11:58:06 +02:00
|
|
|
|
|
|
|
hb_blob_destroy (blob);
|
|
|
|
}
|
2018-04-19 22:39:57 +02:00
|
|
|
hb_face_destroy (result);
|
2018-03-13 00:08:16 +01:00
|
|
|
|
|
|
|
hb_subset_input_destroy (input);
|
2018-06-01 01:47:39 +02:00
|
|
|
}
|
|
|
|
|
2020-08-12 00:00:33 +02:00
|
|
|
extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size)
|
2018-06-01 01:47:39 +02:00
|
|
|
{
|
2022-07-01 20:11:15 +02:00
|
|
|
alloc_state = _fuzzing_alloc_state (data, size);
|
2020-07-14 16:59:58 +02:00
|
|
|
|
2020-08-12 00:00:33 +02:00
|
|
|
hb_blob_t *blob = hb_blob_create ((const char *) data, size,
|
2019-06-03 10:00:25 +02:00
|
|
|
HB_MEMORY_MODE_READONLY, nullptr, nullptr);
|
2018-06-01 01:47:39 +02:00
|
|
|
hb_face_t *face = hb_face_create (blob, 0);
|
|
|
|
|
2018-10-11 23:08:12 +02:00
|
|
|
/* Just test this API here quickly. */
|
2020-08-12 00:00:33 +02:00
|
|
|
hb_set_t *output = hb_set_create ();
|
2018-10-11 23:08:12 +02:00
|
|
|
hb_face_collect_unicodes (face, output);
|
|
|
|
hb_set_destroy (output);
|
|
|
|
|
2021-07-30 00:25:41 +02:00
|
|
|
unsigned flags = HB_SUBSET_FLAGS_DEFAULT;
|
2018-06-01 01:47:39 +02:00
|
|
|
const hb_codepoint_t text[] =
|
|
|
|
{
|
2018-10-02 20:09:19 +02:00
|
|
|
'A', 'B', 'C', 'D', 'E', 'X', 'Y', 'Z', '1', '2',
|
|
|
|
'3', '@', '_', '%', '&', ')', '*', '$', '!'
|
2018-06-01 01:47:39 +02:00
|
|
|
};
|
|
|
|
|
2023-02-22 21:54:20 +01:00
|
|
|
hb_subset_input_t *input = hb_subset_input_create_or_fail ();
|
2023-03-13 20:50:28 +01:00
|
|
|
if (!input)
|
|
|
|
{
|
|
|
|
hb_face_destroy (face);
|
|
|
|
hb_blob_destroy (blob);
|
|
|
|
return 0;
|
|
|
|
}
|
2023-02-22 21:54:20 +01:00
|
|
|
trySubset (face, text, sizeof (text) / sizeof (hb_codepoint_t), flags, input);
|
2018-06-01 01:47:39 +02:00
|
|
|
|
2023-02-22 21:54:20 +01:00
|
|
|
unsigned num_axes;
|
2018-06-01 01:47:39 +02:00
|
|
|
hb_codepoint_t text_from_data[16];
|
2023-02-22 21:54:20 +01:00
|
|
|
if (size > sizeof (text_from_data) + sizeof (flags) + sizeof(num_axes)) {
|
|
|
|
hb_subset_input_t *input = hb_subset_input_create_or_fail ();
|
2023-03-13 20:50:28 +01:00
|
|
|
if (!input)
|
|
|
|
{
|
|
|
|
hb_face_destroy (face);
|
|
|
|
hb_blob_destroy (blob);
|
|
|
|
return 0;
|
|
|
|
}
|
2023-02-22 21:54:20 +01:00
|
|
|
size -= sizeof (text_from_data);
|
2018-10-02 20:09:19 +02:00
|
|
|
memcpy (text_from_data,
|
2023-02-22 21:54:20 +01:00
|
|
|
data + size,
|
2020-08-12 00:00:33 +02:00
|
|
|
sizeof (text_from_data));
|
2019-01-31 00:23:19 +01:00
|
|
|
|
2023-02-22 21:54:20 +01:00
|
|
|
size -= sizeof (flags);
|
2021-07-29 20:52:14 +02:00
|
|
|
memcpy (&flags,
|
2023-02-22 21:54:20 +01:00
|
|
|
data + size,
|
2020-08-12 00:00:33 +02:00
|
|
|
sizeof (flags));
|
2019-01-31 00:23:19 +01:00
|
|
|
|
2023-02-22 21:54:20 +01:00
|
|
|
size -= sizeof (num_axes);
|
|
|
|
memcpy (&num_axes,
|
|
|
|
data + size,
|
|
|
|
sizeof (num_axes));
|
|
|
|
|
2023-02-28 23:31:45 +01:00
|
|
|
if (num_axes > 0 && num_axes < 8 && size > num_axes * (sizeof(hb_tag_t) + sizeof(int)))
|
2023-02-22 21:54:20 +01:00
|
|
|
{
|
|
|
|
for (unsigned i = 0; i < num_axes; i++) {
|
|
|
|
hb_tag_t tag;
|
|
|
|
int value;
|
|
|
|
size -= sizeof (tag);
|
|
|
|
memcpy (&tag,
|
|
|
|
data + size,
|
|
|
|
sizeof (tag));
|
|
|
|
size -= sizeof (value);
|
|
|
|
memcpy (&value,
|
|
|
|
data + size,
|
|
|
|
sizeof (value));
|
|
|
|
|
|
|
|
hb_subset_input_pin_axis_location(input,
|
|
|
|
face,
|
|
|
|
tag,
|
|
|
|
(float) value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
unsigned int text_size = sizeof (text_from_data) / sizeof (hb_codepoint_t);
|
|
|
|
trySubset (face, text_from_data, text_size, flags, input);
|
2018-06-01 01:47:39 +02:00
|
|
|
}
|
|
|
|
|
2018-03-13 00:08:16 +01:00
|
|
|
hb_face_destroy (face);
|
|
|
|
hb_blob_destroy (blob);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|