mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-22 23:41:03 +01:00
[repacker] Count null offsets when splitting ligatures (#6476)
Ligature split points skipped null offsets while the ranges used to clone and shrink subtables counted every slot. Advance the split index for null offsets too, so both stages refer to the same ligatures. Also reject an inverted range after narrowing it to the remaining links, before calculating the number of ligatures to allocate. Add a regression that compares the split graph with the expected subtables when one ligature set has trailing null offsets. Testing: meson test -C build (292 passed; check-symbols skipped on macOS), plus the repacker test and shared-ligature font check with ASan and UBSan. Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-9C9WB0KM. Assisted-by: OpenAI Codex
This commit is contained in:
1 parent
8f115ee233
commit
d8347f079e
2 files changed
+107
-3
No files matched your search
@@ -149,7 +149,9 @@ struct LigatureSubstFormat1 : public OT::Layout::GSUB_impl::LigatureSubstFormat1
|
||||
// all links
|
||||
TRY_ASSIGN (auto index_to_id, ligature_index_to_object_id (liga_set));
|
||||
|
||||
for (unsigned j = 0; j < liga_set.table->ligature.len; j++)
|
||||
// Split points and liga_counts () must count the same offset slots,
|
||||
// including null offsets.
|
||||
for (unsigned j = 0; j < liga_set.table->ligature.len; j++, ligature_index++)
|
||||
{
|
||||
const unsigned liga_id = index_to_id[j];
|
||||
if (liga_id == HB_GRAPH_INVALID) continue; // no outgoing link, ignore
|
||||
@@ -168,8 +170,6 @@ struct LigatureSubstFormat1 : public OT::Layout::GSUB_impl::LigatureSubstFormat1
|
||||
OT::Layout::GSUB_impl::LigatureSet<SmallTypes>::min_size + // for liga set subtable
|
||||
liga_size; // for liga sub table
|
||||
}
|
||||
|
||||
ligature_index++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -340,6 +340,9 @@ struct LigatureSubstFormat1 : public OT::Layout::GSUB_impl::LigatureSubstFormat1
|
||||
// a new liga set sub table and move the intersecting ligas to it.
|
||||
unsigned start_index = hb_max(start, current_start) - count;
|
||||
unsigned end_index = hb_min(end, current_end) - count;
|
||||
// Narrowing to the remaining links may leave an inverted range.
|
||||
if (unlikely (end_index < start_index))
|
||||
return Err(INVALID_ARGUMENT);
|
||||
unsigned liga_count = end_index - start_index;
|
||||
TRY_ASSIGN (auto result, new_liga_set(c, liga_count));
|
||||
liga_set_prime_id = result.first;
|
||||
|
||||
@@ -1853,6 +1853,83 @@ populate_serializer_with_large_liga_overlapping_clone_result (hb_serialize_conte
|
||||
c->end_serialize();
|
||||
}
|
||||
|
||||
static void
|
||||
populate_serializer_with_large_liga_null_offsets (hb_serialize_context_t* c, bool split)
|
||||
{
|
||||
std::string large_string(100000, 'a');
|
||||
c->start_serialize<char> ();
|
||||
|
||||
constexpr unsigned liga_size = 30000;
|
||||
const char null_offsets[6] = {0};
|
||||
|
||||
unsigned liga[3];
|
||||
unsigned liga_subst[2];
|
||||
unsigned liga_set[2];
|
||||
unsigned liga_subst_count = split ? 2 : 1;
|
||||
unsigned coverage;
|
||||
|
||||
if (split) {
|
||||
// LigaSubst 2
|
||||
coverage = add_coverage(1, 1, c);
|
||||
start_object (large_string.c_str(), liga_size, c);
|
||||
add_virtual_offset(coverage, c);
|
||||
liga[2] = c->pop_pack (false);
|
||||
|
||||
add_liga_set_header(1, c);
|
||||
add_virtual_offset(coverage, c);
|
||||
add_offset(liga[2], c);
|
||||
liga_set[0] = c->pop_pack(false);
|
||||
|
||||
add_liga_header(coverage, 1, c);
|
||||
add_offset(liga_set[0], c);
|
||||
liga_subst[1] = c->pop_pack(false);
|
||||
}
|
||||
|
||||
// LigaSubst 1
|
||||
coverage = add_coverage(0, 1, c);
|
||||
for (int i = split ? 1 : 2; i >= 0; i--) {
|
||||
start_object (large_string.c_str(), liga_size, c);
|
||||
add_virtual_offset(coverage, c);
|
||||
liga[i] = c->pop_pack (false);
|
||||
}
|
||||
|
||||
add_liga_set_header(split ? 1 : 2, c);
|
||||
add_virtual_offset(coverage, c);
|
||||
add_offset(liga[1], c);
|
||||
if (!split)
|
||||
add_offset(liga[2], c);
|
||||
liga_set[1] = c->pop_pack(false);
|
||||
|
||||
// One liga followed by three null offsets.
|
||||
add_liga_set_header(4, c);
|
||||
add_virtual_offset(coverage, c);
|
||||
add_offset(liga[0], c);
|
||||
extend(null_offsets, 6, c);
|
||||
liga_set[0] = c->pop_pack(false);
|
||||
|
||||
add_liga_header(coverage, 2, c);
|
||||
add_offset(liga_set[0], c);
|
||||
add_offset(liga_set[1], c);
|
||||
liga_subst[0] = c->pop_pack(false);
|
||||
|
||||
for (int l = liga_subst_count - 1; l >= 0; l--) {
|
||||
liga_subst[l] = add_extension(liga_subst[l], 4, c);
|
||||
}
|
||||
|
||||
start_lookup (7, liga_subst_count, c);
|
||||
for (unsigned l = 0; l < liga_subst_count; l++) {
|
||||
add_offset(liga_subst[l], c);
|
||||
}
|
||||
|
||||
unsigned lookup = finish_lookup (c);
|
||||
|
||||
unsigned lookup_list = add_lookup_list (&lookup, 1, c);
|
||||
|
||||
add_gsubgpos_header (lookup_list, c);
|
||||
|
||||
c->end_serialize();
|
||||
}
|
||||
|
||||
template<unsigned liga_subst_count,
|
||||
unsigned liga_set_count,
|
||||
unsigned liga_per_set_count,
|
||||
@@ -2622,6 +2699,29 @@ static void test_resolve_with_liga_split_overlapping_clone ()
|
||||
free (expected_buffer);
|
||||
}
|
||||
|
||||
static void test_resolve_with_liga_split_null_offsets ()
|
||||
{
|
||||
size_t buffer_size = 400000;
|
||||
void* buffer = malloc (buffer_size);
|
||||
hb_always_assert (buffer);
|
||||
hb_serialize_context_t c (buffer, buffer_size);
|
||||
populate_serializer_with_large_liga_null_offsets(&c, false);
|
||||
|
||||
void* expected_buffer = malloc (buffer_size);
|
||||
hb_always_assert (expected_buffer);
|
||||
hb_serialize_context_t e (expected_buffer, buffer_size);
|
||||
populate_serializer_with_large_liga_null_offsets(&e, true);
|
||||
|
||||
run_resolve_overflow_test ("test_resolve_with_liga_split_null_offsets",
|
||||
c,
|
||||
e,
|
||||
20,
|
||||
true,
|
||||
HB_TAG('G', 'S', 'U', 'B'));
|
||||
free (buffer);
|
||||
free (expected_buffer);
|
||||
}
|
||||
|
||||
static void test_resolve_with_liga_split_shared_table ()
|
||||
{
|
||||
size_t buffer_size = 400000;
|
||||
@@ -3041,6 +3141,7 @@ main (int argc, char **argv)
|
||||
test_resolve_with_liga_split_move ();
|
||||
test_dont_duplicate_virtual ();
|
||||
test_resolve_with_liga_split_overlapping_clone ();
|
||||
test_resolve_with_liga_split_null_offsets ();
|
||||
test_resolve_with_liga_split_shared_table ();
|
||||
test_resolve_with_liga_split_shared_coverage ();
|
||||
test_deep_graph_traversal ();
|
||||
|
||||
Reference in new issue
Block a user