|
|
|
@ -328,6 +328,93 @@ populate_serializer_spaces (hb_serialize_context_t* c, bool with_overflow) |
|
|
|
|
c->end_serialize(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void |
|
|
|
|
populate_serializer_spaces_16bit_connection (hb_serialize_context_t* c) |
|
|
|
|
{ |
|
|
|
|
std::string large_string(70000, 'a'); |
|
|
|
|
c->start_serialize<char> (); |
|
|
|
|
|
|
|
|
|
unsigned obj_g = add_object ("g", 1, c); |
|
|
|
|
unsigned obj_h = add_object ("h", 1, c); |
|
|
|
|
|
|
|
|
|
start_object (large_string.c_str (), 40000, c); |
|
|
|
|
add_offset (obj_g, c); |
|
|
|
|
unsigned obj_e = c->pop_pack (false); |
|
|
|
|
|
|
|
|
|
start_object (large_string.c_str (), 40000, c); |
|
|
|
|
add_offset (obj_h, c); |
|
|
|
|
unsigned obj_f = c->pop_pack (false); |
|
|
|
|
|
|
|
|
|
start_object ("c", 1, c); |
|
|
|
|
add_offset (obj_e, c); |
|
|
|
|
unsigned obj_c = c->pop_pack (false); |
|
|
|
|
|
|
|
|
|
start_object ("d", 1, c); |
|
|
|
|
add_offset (obj_f, c); |
|
|
|
|
unsigned obj_d = c->pop_pack (false); |
|
|
|
|
|
|
|
|
|
start_object ("b", 1, c); |
|
|
|
|
add_offset (obj_e, c); |
|
|
|
|
add_offset (obj_h, c); |
|
|
|
|
unsigned obj_b = c->pop_pack (false); |
|
|
|
|
|
|
|
|
|
start_object ("a", 1, c); |
|
|
|
|
add_offset (obj_b, c); |
|
|
|
|
add_wide_offset (obj_c, c); |
|
|
|
|
add_wide_offset (obj_d, c); |
|
|
|
|
c->pop_pack (false); |
|
|
|
|
|
|
|
|
|
c->end_serialize(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void |
|
|
|
|
populate_serializer_spaces_16bit_connection_expected (hb_serialize_context_t* c) |
|
|
|
|
{ |
|
|
|
|
std::string large_string(70000, 'a'); |
|
|
|
|
c->start_serialize<char> (); |
|
|
|
|
|
|
|
|
|
unsigned obj_g_prime = add_object ("g", 1, c); |
|
|
|
|
|
|
|
|
|
start_object (large_string.c_str (), 40000, c); |
|
|
|
|
add_offset (obj_g_prime, c); |
|
|
|
|
unsigned obj_e_prime = c->pop_pack (false); |
|
|
|
|
|
|
|
|
|
start_object ("c", 1, c); |
|
|
|
|
add_offset (obj_e_prime, c); |
|
|
|
|
unsigned obj_c = c->pop_pack (false); |
|
|
|
|
|
|
|
|
|
unsigned obj_h_prime = add_object ("h", 1, c); |
|
|
|
|
|
|
|
|
|
start_object (large_string.c_str (), 40000, c); |
|
|
|
|
add_offset (obj_h_prime, c); |
|
|
|
|
unsigned obj_f = c->pop_pack (false); |
|
|
|
|
|
|
|
|
|
start_object ("d", 1, c); |
|
|
|
|
add_offset (obj_f, c); |
|
|
|
|
unsigned obj_d = c->pop_pack (false); |
|
|
|
|
|
|
|
|
|
unsigned obj_g = add_object ("g", 1, c); |
|
|
|
|
|
|
|
|
|
start_object (large_string.c_str (), 40000, c); |
|
|
|
|
add_offset (obj_g, c); |
|
|
|
|
unsigned obj_e = c->pop_pack (false); |
|
|
|
|
|
|
|
|
|
unsigned obj_h = add_object ("h", 1, c); |
|
|
|
|
|
|
|
|
|
start_object ("b", 1, c); |
|
|
|
|
add_offset (obj_e, c); |
|
|
|
|
add_offset (obj_h, c); |
|
|
|
|
unsigned obj_b = c->pop_pack (false); |
|
|
|
|
|
|
|
|
|
start_object ("a", 1, c); |
|
|
|
|
add_offset (obj_b, c); |
|
|
|
|
add_wide_offset (obj_c, c); |
|
|
|
|
add_wide_offset (obj_d, c); |
|
|
|
|
c->pop_pack (false); |
|
|
|
|
|
|
|
|
|
c->end_serialize (); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void |
|
|
|
|
populate_serializer_complex_1 (hb_serialize_context_t* c) |
|
|
|
|
{ |
|
|
|
@ -770,6 +857,40 @@ static void test_resolve_overflows_via_isolation_with_recursive_duplication () |
|
|
|
|
free (out_buffer); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void test_resolve_overflows_via_isolating_16bit_space () |
|
|
|
|
{ |
|
|
|
|
size_t buffer_size = 160000; |
|
|
|
|
void* buffer = malloc (buffer_size); |
|
|
|
|
hb_serialize_context_t c (buffer, buffer_size); |
|
|
|
|
populate_serializer_spaces_16bit_connection (&c); |
|
|
|
|
graph_t graph (c.object_graph ()); |
|
|
|
|
|
|
|
|
|
void* out_buffer = malloc (buffer_size); |
|
|
|
|
hb_serialize_context_t out (out_buffer, buffer_size); |
|
|
|
|
|
|
|
|
|
assert (c.offset_overflow ()); |
|
|
|
|
hb_resolve_overflows (c.object_graph (), HB_TAG ('G', 'S', 'U', 'B'), &out, 0); |
|
|
|
|
assert (!out.offset_overflow ()); |
|
|
|
|
hb_bytes_t result = out.copy_bytes (); |
|
|
|
|
|
|
|
|
|
void* expected_buffer = malloc (buffer_size); |
|
|
|
|
hb_serialize_context_t e (expected_buffer, buffer_size); |
|
|
|
|
assert (!e.offset_overflow ()); |
|
|
|
|
populate_serializer_spaces_16bit_connection_expected (&e); |
|
|
|
|
hb_bytes_t expected_result = e.copy_bytes (); |
|
|
|
|
|
|
|
|
|
assert (result.length == expected_result.length); |
|
|
|
|
for (unsigned i = 0; i < result.length; i++) |
|
|
|
|
assert (result[i] == expected_result[i]); |
|
|
|
|
|
|
|
|
|
result.fini (); |
|
|
|
|
expected_result.fini (); |
|
|
|
|
free (buffer); |
|
|
|
|
free (expected_buffer); |
|
|
|
|
free (out_buffer); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void test_resolve_overflows_via_isolation_spaces () |
|
|
|
|
{ |
|
|
|
|
size_t buffer_size = 160000; |
|
|
|
@ -814,6 +935,7 @@ main (int argc, char **argv) |
|
|
|
|
test_resolve_overflows_via_isolation (); |
|
|
|
|
test_resolve_overflows_via_isolation_with_recursive_duplication (); |
|
|
|
|
test_resolve_overflows_via_isolation_spaces (); |
|
|
|
|
test_resolve_overflows_via_isolating_16bit_space (); |
|
|
|
|
test_duplicate_leaf (); |
|
|
|
|
test_duplicate_interior (); |
|
|
|
|
} |
|
|
|
|