2015-10-12 23:39:52 +02:00
|
|
|
#include <stddef.h>
|
2015-11-06 08:08:50 +01:00
|
|
|
#include <hb.h>
|
|
|
|
#include <hb-ot.h>
|
2016-01-11 19:31:04 +01:00
|
|
|
#include <string.h>
|
2015-10-12 23:39:52 +02:00
|
|
|
|
|
|
|
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
|
|
|
|
|
|
|
hb_blob_t *blob = hb_blob_create((const char *)data, size,
|
|
|
|
HB_MEMORY_MODE_READONLY, NULL, NULL);
|
|
|
|
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);
|
|
|
|
|
2016-01-11 19:31:04 +01:00
|
|
|
{
|
|
|
|
const char text[] = "ABCDEXYZ123@_%&)*$!";
|
|
|
|
hb_buffer_t *buffer = hb_buffer_create();
|
|
|
|
hb_buffer_add_utf8(buffer, text, -1, 0, -1);
|
|
|
|
hb_buffer_guess_segment_properties(buffer);
|
|
|
|
hb_shape(font, buffer, NULL, 0);
|
|
|
|
hb_buffer_destroy(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t text32[16];
|
|
|
|
if (size > sizeof(text32)) {
|
|
|
|
memcpy(text32, data + size - sizeof(text32), sizeof(text32));
|
|
|
|
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);
|
|
|
|
hb_shape(font, buffer, NULL, 0);
|
2016-12-05 05:28:38 +01:00
|
|
|
|
|
|
|
unsigned int len = hb_buffer_get_length (buffer);
|
|
|
|
hb_glyph_info_t *infos = hb_buffer_get_glyph_infos (buffer, NULL);
|
|
|
|
//hb_glyph_position_t *positions = hb_buffer_get_glyph_positions (buffer, NULL);
|
|
|
|
for (unsigned int i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
hb_glyph_info_t info = infos[i];
|
|
|
|
//hb_glyph_position_t pos = positions[i];
|
|
|
|
|
|
|
|
hb_glyph_extents_t extents;
|
|
|
|
hb_font_get_glyph_extents (font, info.codepoint, &extents);
|
|
|
|
}
|
|
|
|
|
2016-01-11 19:31:04 +01:00
|
|
|
hb_buffer_destroy(buffer);
|
|
|
|
}
|
2015-10-12 23:39:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
hb_font_destroy(font);
|
|
|
|
hb_face_destroy(face);
|
|
|
|
hb_blob_destroy(blob);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef MAIN
|
|
|
|
#include <iostream>
|
|
|
|
#include <iterator>
|
|
|
|
#include <fstream>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
std::string FileToString(const std::string &Path) {
|
2016-02-19 09:12:16 +01:00
|
|
|
/* TODO This silently passes if file does not exist. Fix it! */
|
2015-10-12 23:39:52 +02:00
|
|
|
std::ifstream T(Path.c_str());
|
|
|
|
return std::string((std::istreambuf_iterator<char>(T)),
|
|
|
|
std::istreambuf_iterator<char>());
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
for (int i = 1; i < argc; i++) {
|
|
|
|
std::string s = FileToString(argv[i]);
|
|
|
|
std::cout << argv[i] << std::endl;
|
|
|
|
LLVMFuzzerTestOneInput((const unsigned char*)s.data(), s.size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|