From c8e9f14fd371f0ce97d4b5a49680087e13c627a5 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 30 Oct 2026 14:43:19 -0600 Subject: [PATCH 1/8] [repacker] Reject link positions that wrap near UINT_MAX graph_t::vertex_t::link_positions_valid() computed a link's last byte as start + width - 1 in 32-bit arithmetic, so a caller-supplied position near UINT_MAX wrapped to a small value and passed the bounds test; the defense-in-depth guard in serialize_link_of_type() summed link.position + link.width the same way. A graph with a link at position 0xFFFFFFFF was therefore accepted by hb_subset_serialize_or_fail() and the serializer stored the offset field about 4 GiB past the output buffer (SIGSEGV on 64-bit). Reject the link when end < start (width is already confined to 2..4 at that point, so this means start + width wrapped), and rewrite the serializer guard as position > size || size - position < width, the no-sum idiom used elsewhere for range checks. Only a caller that computes its own bad link position reaches this; the subsetter's own graphs always take positions from inside the object, so no font, text or subsetting request leads here. Valid graphs are unaffected and there is no public API/ABI change. A regression test, test_invalid_link_position(), is added next to the existing invalid-link tests; it crashes on the unpatched code. Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-GREQ3M7K. Co-Authored-By: Claude Opus 4.8 --- src/graph/graph.hh | 3 ++- src/graph/serialize.hh | 3 ++- src/test-repacker.cc | 24 ++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/graph/graph.hh b/src/graph/graph.hh index d944bf357..65ad05a79 100644 --- a/src/graph/graph.hh +++ b/src/graph/graph.hh @@ -185,7 +185,8 @@ struct graph_t return Err(INVALID_ARGUMENT); } - if (unlikely (end >= table_size ())) + // end < start means start + width wrapped around. + if (unlikely (end < start || end >= table_size ())) { DEBUG_MSG (SUBSET_REPACK, nullptr, "Invalid graph. Link position is out of bounds."); diff --git a/src/graph/serialize.hh b/src/graph/serialize.hh index fc25b76a7..6a7bdf7c8 100644 --- a/src/graph/serialize.hh +++ b/src/graph/serialize.hh @@ -188,7 +188,8 @@ serialize_link_of_type (const hb_serialize_context_t::object_t::link_t& link, hb_serialize_context_t* c) { // A link must never write outside the bounds of its parent object. - if (unlikely (link.position + link.width > size)) + // Compare without summing so a large position can't wrap around. + if (unlikely (link.position > size || size - link.position < link.width)) { c->err (HB_SERIALIZE_ERROR_OTHER); return; diff --git a/src/test-repacker.cc b/src/test-repacker.cc index f1803c66d..bcaa023fb 100644 --- a/src/test-repacker.cc +++ b/src/test-repacker.cc @@ -3150,6 +3150,29 @@ static void test_pair_pos_format_2_sanitize_size_overflow () hb_always_assert (!pair_pos->sanitize (vertex).is_ok ()); } +static void test_invalid_link_position () +{ + size_t buffer_size = 100; + void* buffer = malloc (buffer_size); + hb_serialize_context_t c (buffer, buffer_size); + populate_serializer_simple (&c); + + graph_t graph = graph_t::create (c.object_graph ()).value (); + + // Poison a link position so that position + width wraps around in + // 32 bit arithmetic. Serialization must reject it rather than write + // outside of the output buffer. + auto links = graph.vertices_[graph.root_idx ()].real_links_writer(); + links->position = (unsigned) -1; + hb_always_assert (!graph::serialize (graph).is_ok ()); + + // The same poisoned link must be rejected when building the graph. + c.object_graph ().tail ()->real_links[0].position = (unsigned) -1; + hb_always_assert (!graph_t::create (c.object_graph ()).is_ok ()); + + free (buffer); +} + // TODO(garretrieger): update will_overflow tests to check the overflows array. // TODO(garretrieger): add tests for priority raising. @@ -3160,6 +3183,7 @@ main (int argc, char **argv) test_pair_pos_format_2_sanitize_size_overflow (); test_invalid_link_objidx (); test_invalid_link_add_and_move (); + test_invalid_link_position (); test_serialize (); test_sort_shortest (); test_will_overflow_1 (); From 9fec0b2ca54277d1f1830101706099f63bd6be59 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 30 Oct 2026 14:47:36 -0600 Subject: [PATCH 2/8] [serialize] Keep push() pushing while only an overflow error is pending pop_discard() and pop_pack() deliberately keep popping while the only error is an INT/ARRAY/OFFSET overflow, but push() bailed on any error, so any push/pop pair opened in that state popped the enclosing object. GPOS mark-attachment subsetting reaches this when instancing overflows an anchor coordinate and AnchorMatrix/LigatureArray/MarkArray report success anyway: the serializer stack slips one level and hb_subset_or_fail() aborts on the revert() assertion (or, without assertions, dereferences a NULL current). A crafted 344-byte variable font instanced with e.g. --variations=wght=900 triggers it. Give push() the same in_error () && !only_overflow () guard as the two pops. Objects pushed in that state stay empty (allocate_size() refuses while in error), pop_pack() returns 0 for them and pop_discard() releases them, so pairs stay balanced. The object-pool-exhaustion branch now records the error directly with err(), since check_success(false) is a no-op once an error is already pending and the matching pop would again pop the parent. A unit test, test_push_pop_after_overflow(), is added to test-serialize.cc; it fails on the unpatched header. Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-GB4R872E. Co-Authored-By: Claude Opus 4.8 --- src/hb-serialize.hh | 6 ++++-- src/test-serialize.cc | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/hb-serialize.hh b/src/hb-serialize.hh index 7b2bbb59f..64404121f 100644 --- a/src/hb-serialize.hh +++ b/src/hb-serialize.hh @@ -332,11 +332,13 @@ struct hb_serialize_context_t __attribute__((returns_nonnull)) Type *push () { - if (unlikely (in_error ())) return start_embed (); + // Keep pushing when we've error'd out on int overflows, since pop_discard() + // and pop_pack() keep popping; otherwise they would pop the parent object. + if (unlikely (in_error () && !only_overflow ())) return start_embed (); object_t *obj = object_pool.alloc (); if (unlikely (!obj)) - check_success (false); + err (HB_SERIALIZE_ERROR_OTHER); else { obj->head = head; diff --git a/src/test-serialize.cc b/src/test-serialize.cc index 8eb8a1e82..ca25c3266 100644 --- a/src/test-serialize.cc +++ b/src/test-serialize.cc @@ -363,6 +363,31 @@ test_failed_class_mapping () hb_always_assert (glyph_and_klass[0].second == 1); } +static void +test_push_pop_after_overflow () +{ + char buf[32]; + hb_serialize_context_t s (buf, sizeof (buf)); + s.start_serialize (); + s.push (); + auto snap = s.snapshot (); + s.err (HB_SERIALIZE_ERROR_INT_OVERFLOW); + + /* Objects opened while only an overflow is pending must not pop their parent. */ + s.push (); + s.pop_discard (); + hb_always_assert (s.snapshot ().current == snap.current); + s.push (); + hb_always_assert (!s.pop_pack ()); + hb_always_assert (s.snapshot ().current == snap.current); + + s.revert (snap); + hb_always_assert (!s.in_error ()); + s.pop_discard (); + s.end_serialize (); + hb_always_assert (!s.in_error ()); +} + int main (int argc, char **argv) { @@ -374,6 +399,7 @@ main (int argc, char **argv) test_medium_chain_rule (); test_device_only_value (); test_failed_class_mapping (); + test_push_pop_after_overflow (); char buf[16384]; From 9179b64235f60521328733fa24258cfef46c93d4 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 30 Oct 2026 14:51:55 -0600 Subject: [PATCH 3/8] [repacker] Propagate the vertex limit error during overflow resolution HB_REPACKER_MAX_VERTICES is enforced inside graph_t::duplicate() by returning LIMIT_EXCEEDED, but since the hb_result_t conversion the two callers that drive overflow resolution threw that error away: duplicate_subgraph() recorded it in a local and returned Ok, and _resolve_shared_overflow() mapped every error to Ok(false) ("couldn't duplicate, try something else"). hb_resolve_graph_overflows() then kept iterating over a graph that could no longer grow: a 53 KB font with 150 MarkBasePos subtables sharing one 8400-anchor BaseArray ran one core for ~705 s before failing, instead of ~37 s. duplicate_subgraph() now returns the recorded error with TRY(result). _resolve_shared_overflow() treats only INVALID_ARGUMENT (the node genuinely cannot be duplicated here) as "not resolved" and propagates LIMIT_EXCEEDED/ALLOCATION_FAILURE/OUT_OF_BOUNDS, restoring the pre-conversion behaviour where the sticky error ended the loop; this is the same error-discrimination idiom already used for SANITIZE_FAILURE in hb-repacker.hh and ORPHANED_NODES in graph.hh. Two regression tests are added to test-repacker.cc, each failing without its hunk. Behaviour change: reaching the vertex limit now fails promptly as before 14.5.0; no public API/ABI change. Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-I0BMRXN4. Co-Authored-By: Claude Opus 4.8 --- src/graph/graph.hh | 1 + src/hb-repacker.hh | 11 +++++-- src/test-repacker.cc | 75 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 2 deletions(-) diff --git a/src/graph/graph.hh b/src/graph/graph.hh index 65ad05a79..099a93e41 100644 --- a/src/graph/graph.hh +++ b/src/graph/graph.hh @@ -1338,6 +1338,7 @@ public: index_map.set (child, *r); return true; })); + TRY (result); return graph_result_t::from(index_map, ALLOCATION_FAILURE); } diff --git a/src/hb-repacker.hh b/src/hb-repacker.hh index d7903a897..845d66b1c 100644 --- a/src/hb-repacker.hh +++ b/src/hb-repacker.hh @@ -262,7 +262,7 @@ graph_result_t _resolve_shared_overflow(const hb_vector_t 2) { + if (result.is_err () && result.error () == graph::INVALID_ARGUMENT && parents.get_population() > 2) { // All links to the child are overflowing, so we can't include all // in the duplication. Remove one parent from the duplication. // Remove the lowest index parent, which will be the closest to the child. @@ -270,7 +270,14 @@ graph_result_t _resolve_shared_overflow(const hb_vector_t 1) { // If the duplicated node has more than one parent pre-emptively raise it's priority to the maximum. diff --git a/src/test-repacker.cc b/src/test-repacker.cc index bcaa023fb..ef70af045 100644 --- a/src/test-repacker.cc +++ b/src/test-repacker.cc @@ -2984,6 +2984,79 @@ test_deep_graph_traversal () free (buffer); } +static void +test_duplicate_subgraph_vertex_limit () +{ + size_t buffer_size = 100; + void* buffer = malloc (buffer_size); + hb_serialize_context_t c (buffer, buffer_size); + + c.start_serialize (); + unsigned leaf = add_object ("leaf", 4, &c); + start_object ("root", 4, &c); + add_offset (leaf, &c); + c.pop_pack (false); + c.end_serialize (); + + graph_t graph = graph_t::create (c.object_graph ()).value (); + while (graph.vertices_.length < HB_REPACKER_MAX_VERTICES - 1) + hb_always_assert (graph.new_node (nullptr, nullptr).is_ok ()); + + // There's only room left for one of the two nodes, the failure must be reported. + hb_map_t index_map; + auto result = graph.duplicate_subgraph (graph.root_idx (), index_map); + hb_always_assert (result.is_err ()); + hb_always_assert (result.error () == graph::LIMIT_EXCEEDED); + + free (buffer); +} + +static void +test_resolve_shared_overflow_vertex_limit () +{ + size_t buffer_size = 100; + void* buffer = malloc (buffer_size); + hb_serialize_context_t c (buffer, buffer_size); + + c.start_serialize (); + unsigned leaf = add_object ("leaf", 4, &c); + + start_object ("a", 4, &c); + add_offset (leaf, &c); + unsigned a = c.pop_pack (false); + + start_object ("b", 4, &c); + add_offset (leaf, &c); + unsigned b = c.pop_pack (false); + + start_object ("root", 4, &c); + add_offset (a, &c); + add_offset (b, &c); + c.pop_pack (false); + c.end_serialize (); + + graph_t graph = graph_t::create (c.object_graph ()).value (); + while (graph.vertices_.length < HB_REPACKER_MAX_VERTICES) + hb_always_assert (graph.new_node (nullptr, nullptr).is_ok ()); + + // 'a' (1) is not shared so it can't be duplicated, other resolution options may be tried. + hb_vector_t overflows; + overflows.push (graph::overflow_record_t {3, 1}); + auto result = _resolve_shared_overflow (overflows, 0, graph); + hb_always_assert (result.is_ok ()); + hb_always_assert (!*result); + + // 'leaf' (0) is shared by 'a' (1) and 'b' (2), but there's no room left to duplicate it. + // The limit must be reported instead of continuing the overflow resolution. + overflows.reset (); + overflows.push (graph::overflow_record_t {1, 0}); + result = _resolve_shared_overflow (overflows, 0, graph); + hb_always_assert (result.is_err ()); + hb_always_assert (result.error () == graph::LIMIT_EXCEEDED); + + free (buffer); +} + static void test_32bit_roots_traversal () { @@ -3227,6 +3300,8 @@ main (int argc, char **argv) test_resolve_with_liga_split_shared_table (); test_resolve_with_liga_split_shared_coverage (); test_deep_graph_traversal (); + test_duplicate_subgraph_vertex_limit (); + test_resolve_shared_overflow_vertex_limit (); test_32bit_roots_traversal (); // TODO(grieger): have run overflow tests compare graph equality not final packed binary. From 7e28f358ae500b6a314fcb68aa8a6bb7656e32d3 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 30 Oct 2026 14:54:11 -0600 Subject: [PATCH 4/8] [repacker] De-duplicate overflow records without an overflow_record_t hash map will_overflow() de-duplicated (parent, child) overflow records through an hb_hashmap_t keyed by overflow_record_t, whose hash() collapses to 2654435761 * (31 * parent + child). With dense vertex ids, a graph where many consecutive vertices link the same children puts all records into a handful of equal-hash chains, so the map degenerates into quadratic probing and repeated over-growth in every resolution round: a crafted 60 KB GDEF font with a LigCaretList of overlapping LigGlyphs took ~65 s of CPU and ~520 MiB before failing. graph.ordering_ is a permutation of the vertices, so every parent is visited exactly once and a duplicate record can only come from two links of the same parent to the same child. A per-parent hb_set_t of the children already recorded, cleared when moving to the next parent, yields exactly the same records in the same order with no hashing of records at all. The now-unused operator==/!=/hash() on overflow_record_t are removed (the struct is only used in vectors elsewhere). A regression test, test_will_overflow_records(), asserts one record per overflowing (parent, child) pair when a parent links the same child twice. The attack font drops to ~1.3 s CPU and 133 MiB, the remaining cost being the 1.8 million links the sanitizer budget admits; no public API/ABI change. Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-QNM0BP56. Co-Authored-By: Claude Opus 4.8 --- src/graph/serialize.hh | 30 +++++++++-------------------- src/test-repacker.cc | 43 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 21 deletions(-) diff --git a/src/graph/serialize.hh b/src/graph/serialize.hh index 6a7bdf7c8..a4c64c974 100644 --- a/src/graph/serialize.hh +++ b/src/graph/serialize.hh @@ -35,23 +35,6 @@ struct overflow_record_t { unsigned parent; unsigned child; - - bool operator != (const overflow_record_t o) const - { return !(*this == o); } - - inline bool operator == (const overflow_record_t& o) const - { - return parent == o.parent && - child == o.child; - } - - inline uint32_t hash () const - { - uint32_t current = 0; - current = current * 31 + hb_hash (parent); - current = current * 31 + hb_hash (child); - return current; - } }; inline @@ -113,10 +96,15 @@ will_overflow (graph_t& graph, if (overflows) overflows->clear (); graph.update_positions (); - hb_hashmap_t record_set; + // Each parent is visited once (ordering_ is a permutation of the vertices), + // so duplicate records can only come from two links of the same parent to the + // same child. A per-parent set of children avoids hashing (parent, child) + // records, whose hash a font can make collide. + hb_set_t overflowing_children; const auto& vertices = graph.vertices_; for (unsigned parent_idx : graph.ordering_) { + overflowing_children.clear (); // Don't need to check virtual links for overflow for (const auto& link : vertices.arrayZ[parent_idx].obj ().real_links) { @@ -129,14 +117,14 @@ will_overflow (graph_t& graph, overflow_record_t r; r.parent = parent_idx; r.child = link.objidx; - if (record_set.has(r)) continue; // don't keep duplicate overflows. + if (overflowing_children.has (r.child)) continue; // don't keep duplicate overflows. overflows->push (r); - record_set.set (r, true); + overflowing_children.add (r.child); } } - TRY (graph_result_t::from (record_set, ALLOCATION_FAILURE)); + TRY (graph_result_t::from (overflowing_children, ALLOCATION_FAILURE)); if (overflows) TRY (graph_result_t::from (*overflows, ALLOCATION_FAILURE)); diff --git a/src/test-repacker.cc b/src/test-repacker.cc index ef70af045..48fb7c54a 100644 --- a/src/test-repacker.cc +++ b/src/test-repacker.cc @@ -2187,6 +2187,48 @@ static void test_will_overflow_3 () free (buffer); } +static void test_will_overflow_records () +{ + size_t buffer_size = 160000; + void* buffer = malloc (buffer_size); + hb_serialize_context_t c (buffer, buffer_size); + + std::string large_string(70000, 'a'); + c.start_serialize (); + + unsigned obj_leaf = add_object ("d", 1, &c); + unsigned obj_large = add_object (large_string.c_str(), 70000, &c); + + start_object ("c", 1, &c); + add_offset (obj_leaf, &c); + add_offset (obj_leaf, &c); + unsigned obj_c = c.pop_pack (false); + + start_object ("b", 1, &c); + add_offset (obj_leaf, &c); + add_offset (obj_leaf, &c); + unsigned obj_b = c.pop_pack (false); + + start_object ("a", 1, &c); + add_offset (obj_b, &c); + add_offset (obj_c, &c); + add_offset (obj_large, &c); + c.pop_pack (false); + + c.end_serialize(); + + graph_t graph = graph_t::create (c.object_graph ()).value (); + + // One record per overflowing (parent, child) pair, even if linked more than once. + hb_vector_t overflows; + hb_always_assert (graph::will_overflow (graph, &overflows).value ()); + hb_always_assert (overflows.length == 2); + hb_always_assert (overflows[0].parent != overflows[1].parent); + hb_always_assert (overflows[0].child == overflows[1].child); + + free (buffer); +} + static void test_resolve_overflows_via_sort () { size_t buffer_size = 160000; @@ -3262,6 +3304,7 @@ main (int argc, char **argv) test_will_overflow_1 (); test_will_overflow_2 (); test_will_overflow_3 (); + test_will_overflow_records (); test_resolve_overflows_via_sort (); test_resolve_overflows_via_duplication (); test_resolve_overflows_via_multiple_duplications (); From 6a2f8c6b4258f52a4558d997949a084c3f075dfc Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 30 Oct 2026 14:56:53 -0600 Subject: [PATCH 5/8] [repacker] Record a parent in priority_bumped_parents even when nothing was raised _process_overflows() calls raise_childrens_priority() (linear in the parent's links) at most once per parent per round, using priority_bumped_parents as the memo, but it recorded the parent only when a priority actually changed. Once every child of a parent sits at the maximum priority the call returns false and is repeated for every remaining overflow record of that parent, making a round cost overflows x links for up to 2 x 32 rounds; a crafted 71 KB font with one ~70 KB GPOS BaseArray pointing at ~11k distinct anchors cost hb-subset ~30 s of CPU. Add the parent to the set unconditionally. Within a round priorities only increase and a successful duplication ends the round, so a second call for the same parent can never raise anything: the return value and the set of changes are unchanged, only the redundant re-walks are removed. The attack font drops to ~0.2 s. A regression test, test_unresolvable_priority_overflow(), builds the same graph shape and asserts the repacker gives up; no public API/ABI change. Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-BFHIZ6ID. Co-Authored-By: Claude Opus 4.8 --- src/hb-repacker.hh | 7 +++--- src/test-repacker.cc | 52 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/src/hb-repacker.hh b/src/hb-repacker.hh index 845d66b1c..e3eda74d9 100644 --- a/src/hb-repacker.hh +++ b/src/hb-repacker.hh @@ -334,10 +334,11 @@ graph_result_t _process_overflows (const hb_vector_tend_serialize(); } +static void +populate_serializer_with_unresolvable_priority_overflow (hb_serialize_context_t* c) +{ + // One parent larger than 64kb with thousands of distinct leaf children, a few of which + // are shared with a small parent that packs before it. No 16 bit offset from the large + // parent can reach past it, so this can't be packed; but it shouldn't take long to find + // that out. + std::string large_string(70000, 'a'); + c->start_serialize (); + + constexpr unsigned num_leaves = 10000; + constexpr unsigned num_shared = 40; + hb_vector_t leaves; + for (unsigned i = 0; i < num_leaves; i++) { + char leaf[3] = {'l', (char) (i >> 8), (char) i}; + leaves.push (add_object (leaf, 3, c)); + } + + start_object ("s", 1, c); + for (unsigned i = 0; i < num_shared; i++) + add_offset (leaves[i], c); + unsigned small_parent = c->pop_pack (false); + + start_object (large_string.c_str (), 70000, c); + for (unsigned i = 0; i < num_leaves; i++) + add_offset (leaves[i], c); + unsigned large_parent = c->pop_pack (false); + + start_object ("r", 1, c); + add_offset (small_parent, c); + add_offset (large_parent, c); + c->pop_pack (false); + + c->end_serialize(); +} + static void populate_serializer_with_isolation_overflow (hb_serialize_context_t* c) { @@ -2869,6 +2905,21 @@ static void test_resolve_overflows_via_priority () free (expected_buffer); } +static void test_unresolvable_priority_overflow () +{ + size_t buffer_size = 300000; + void* buffer = malloc (buffer_size); + hb_serialize_context_t c (buffer, buffer_size); + populate_serializer_with_unresolvable_priority_overflow (&c); + + // Once every child of the large parent is at max priority further overflows + // from it must not re-walk all of its links, in every round. + hb_blob_t* out = hb_resolve_overflows (c.object_graph (), HB_TAG_NONE); + hb_always_assert (!out); + + free (buffer); +} + static void test_virtual_link () { @@ -3309,6 +3360,7 @@ main (int argc, char **argv) test_resolve_overflows_via_duplication (); test_resolve_overflows_via_multiple_duplications (); test_resolve_overflows_via_priority (); + test_unresolvable_priority_overflow (); test_resolve_overflows_via_space_assignment (); test_resolve_overflows_via_isolation (); test_resolve_overflows_via_isolation_with_recursive_duplication (); From 95086deff119b893e9e5135ce2fff39e3aeabe66 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 30 Oct 2026 14:59:27 -0600 Subject: [PATCH 6/8] [repacker] Count wide parents of all space roots in one pass isolate_subgraph() called wide_parents() once per 32-bit space root, and each call walked the complete real_links list of every parent of that root, so a parent with M wide links to M roots (a FeatureVariations ConditionSet with thousands of Offset32s) was walked M times: N*M^2 work that no repacker limit bounds. A crafted 223 KB font with 150 overlapping ConditionSets kept hb-subset busy ~45-60 s. wide_parents() now takes the whole roots set and the subgraph count map: it seeds every root with count 0, collects the union of the roots' parents, then walks each parent's links once, incrementing the count of any root a wide unsigned link targets. The per-root counts and the 'parents' set are identical to before, so the subsets emitted are byte-identical; only the work drops to the sum of the parents' link counts. wide_parents() is private to graph_t with no other callers. A regression test, test_isolate_subgraph_shared_wide_parents(), builds the shared-wide-parent shape and checks isolate_subgraph() duplicates exactly the one leaf with an outside 16-bit edge. The attack font drops to ~1.1 s; no public API/ABI change. Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-8FR2M4SS. Co-Authored-By: Claude Opus 4.8 --- src/graph/graph.hh | 44 ++++++++++++++++++---------- src/test-repacker.cc | 69 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 15 deletions(-) diff --git a/src/graph/graph.hh b/src/graph/graph.hh index 099a93e41..ef49531a0 100644 --- a/src/graph/graph.hh +++ b/src/graph/graph.hh @@ -1016,12 +1016,7 @@ public: // incoming edges to root_idx should be all 32 bit in length so we don't need to de-dup these // set the subgraph incoming edge count to match all of root_idx's incoming edges hb_set_t parents; - for (unsigned root_idx : roots) - { - if (unlikely (root_idx >= vertices_.length)) - return Err(OUT_OF_BOUNDS); - subgraph.set (root_idx, wide_parents (root_idx, parents)); - } + TRY (wide_parents (roots, subgraph, parents)); for (unsigned root_idx : roots) { TRY (find_subgraph (root_idx, subgraph)); @@ -1771,26 +1766,45 @@ public: } /* - * Returns the numbers of incoming edges that are 24 or 32 bits wide. + * For each node in nodes, sets counts[node] to the number of incoming edges that + * are 24 or 32 bits wide. The sources of those edges are added to parents. + * counts is expected to be empty. */ - unsigned wide_parents (unsigned node_idx, hb_set_t& parents) const + graph_result_t wide_parents (const hb_set_t& nodes, + hb_map_t& counts, + hb_set_t& parents) const { - unsigned count = 0; - for (unsigned p : vertices_[node_idx].parents_iter ()) + // A single parent may link to many of the nodes (eg. a ConditionSet with + // thousands of 32 bit offsets), so collect the parents first and walk the + // links of each one only once. + hb_set_t all_parents; + for (unsigned node_idx : nodes) + { + if (unlikely (node_idx >= vertices_.length)) + return Err(OUT_OF_BOUNDS); + counts.set (node_idx, 0); + for (unsigned p : vertices_[node_idx].parents_iter ()) + all_parents.add (p); + } + TRY (graph_result_t::from (all_parents, ALLOCATION_FAILURE)); + TRY (graph_result_t::from (counts, ALLOCATION_FAILURE)); + + for (unsigned p : all_parents) { // Only real links can be wide for (const auto& l : vertices_[p].obj().real_links) { - if (l.objidx == node_idx - && (l.width == 3 || l.width == 4) - && !l.is_signed) + hb_codepoint_t *count; + if ((l.width == 3 || l.width == 4) + && !l.is_signed + && counts.has (l.objidx, &count)) { - count++; + (*count)++; parents.add (p); } } } - return count; + return graph_result_t::from (parents, ALLOCATION_FAILURE); } public: diff --git a/src/test-repacker.cc b/src/test-repacker.cc index 682713aec..47425d109 100644 --- a/src/test-repacker.cc +++ b/src/test-repacker.cc @@ -3220,6 +3220,74 @@ test_32bit_roots_traversal () free (buffer); } +static void +test_isolate_subgraph_shared_wide_parents () +{ + // Several parents each have 32 bit links to the same set of leaves, as + // FeatureVariations ConditionSets do. One leaf also has a 16 bit link from + // outside the subgraph, so isolating the leaves must duplicate that leaf only. + // + // root -16-> p1, p2, p3 + // root -16-> l1 + // p1, p2, p3 -32-> l1, l2, l3 + constexpr unsigned num_parents = 3; + constexpr unsigned num_leaves = 3; + + size_t buffer_size = 1000; + void* buffer = malloc (buffer_size); + hb_serialize_context_t c (buffer, buffer_size); + + c.start_serialize (); + unsigned leaves[num_leaves]; + for (unsigned i = 0; i < num_leaves; i++) + leaves[i] = add_object ("leaf", 4, &c); + + unsigned parents[num_parents]; + for (unsigned i = 0; i < num_parents; i++) + { + start_object ("parent", 6, &c); + for (unsigned j = 0; j < num_leaves; j++) + add_wide_offset (leaves[j], &c); + parents[i] = c.pop_pack (false); + } + + start_object ("root", 4, &c); + for (unsigned i = 0; i < num_parents; i++) + add_offset (parents[i], &c); + add_offset (leaves[0], &c); + c.pop_pack (false); + c.end_serialize (); + + graph_t graph = graph_t::create (c.object_graph ()).value (); + unsigned num_vertices = graph.vertices_.length; + hb_always_assert (num_vertices == 1 + num_parents + num_leaves); + + hb_set_t roots; + for (unsigned i = 0; i < num_leaves; i++) + roots.add (leaves[i] - 1); + + // leaves[0] has an incoming 16 bit edge from root, so it's duplicated. + hb_always_assert (graph.isolate_subgraph (roots).value ()); + hb_always_assert (graph.vertices_.length == num_vertices + 1); + hb_always_assert (roots.get_population () == num_leaves); + hb_always_assert (!roots.has (leaves[0] - 1)); + hb_always_assert (roots.has (num_vertices)); + for (unsigned i = 1; i < num_leaves; i++) + hb_always_assert (roots.has (leaves[i] - 1)); + + hb_always_assert (graph.update_parents ().is_ok ()); + hb_always_assert (graph.vertices_[leaves[0] - 1].incoming_edges () == 1); + hb_always_assert (graph.vertices_[num_vertices].incoming_edges () == num_parents); + for (unsigned i = 1; i < num_leaves; i++) + hb_always_assert (graph.vertices_[leaves[i] - 1].incoming_edges () == num_parents); + + // Now that all incoming edges to the roots are 32 bit, nothing is left to isolate. + hb_always_assert (!graph.isolate_subgraph (roots).value ()); + hb_always_assert (graph.vertices_.length == num_vertices + 1); + + free (buffer); +} + static void test_invalid_link_objidx () { size_t buffer_size = 100; @@ -3398,6 +3466,7 @@ main (int argc, char **argv) test_duplicate_subgraph_vertex_limit (); test_resolve_shared_overflow_vertex_limit (); test_32bit_roots_traversal (); + test_isolate_subgraph_shared_wide_parents (); // TODO(grieger): have run overflow tests compare graph equality not final packed binary. // TODO(grieger): split test where multiple subtables in one lookup are split to test link ordering. From c9a8620c0059f56ac591420e5e965fc85649898d Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 30 Oct 2026 15:03:42 -0600 Subject: [PATCH 7/8] [graph] Keep the Coverage range count of class_def_size_estimator_t incremental add_class_def_size() rebuilt the Coverage size estimate by walking every range of included_glyphs (num_glyph_ranges()) each time a class added a glyph, so PairPosFormat2::split_subtables() did O(classes^2) next_range() calls per subtable; a 131 KB font with 65535 single-glyph classes numbered out of glyph order took minutes in hb_subset_or_fail(). The ClassDef half of the estimator was already made incremental in 19de83dad and #6212 skips the recount when a class adds no glyph, but every class that does add a glyph still triggered a full recount. Do the same for the Coverage half: a coverage_range_count member (zeroed in reset()) is updated from the ranges of the newly added class alone, adding one per range and subtracting one for each already included neighbour (start-1, end+1) it merges with. This is exact because every glyph belongs to exactly one class, so the new glyphs are never already included; the population-unchanged shortcut therefore becomes redundant and num_glyph_ranges() is removed. A regression test is added to test-classdef-graph.cc whose classes extend and bridge already-included ranges. Output is byte-identical; the 8-subtable reproducer drops from >100 s to ~1 s; no public API/ABI change. This is the Coverage-estimation half left open by PR #6212. Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-ZUWZMWMD. Co-Authored-By: Claude Opus 4.8 --- src/graph/classdef-graph.hh | 32 +++++++++++++++++--------------- src/graph/test-classdef-graph.cc | 26 ++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 15 deletions(-) diff --git a/src/graph/classdef-graph.hh b/src/graph/classdef-graph.hh index 19826ce44..4c32adeab 100644 --- a/src/graph/classdef-graph.hh +++ b/src/graph/classdef-graph.hh @@ -193,6 +193,7 @@ struct class_def_size_estimator_t included_glyphs.clear(); included_class_def_glyphs.clear(); included_classes.clear(); + coverage_range_count = 0; class_def_range_count = 0; class_max = 0; coverage_size_val = compute_coverage_size (); @@ -210,12 +211,23 @@ struct class_def_size_estimator_t if (!included_classes.has(klass)) { hb_set_t* glyphs = nullptr; if (glyphs_per_class.has(klass, &glyphs)) { - unsigned num_glyphs = included_glyphs.get_population(); + // Each glyph belongs to exactly one class, so none of these glyphs are + // included yet. Keep the coverage range count incremental (recounting + // the ranges of included_glyphs for every class is quadratic): each new + // range adds one, and merges with each already included neighbour. + hb_codepoint_t start = HB_SET_VALUE_INVALID; + hb_codepoint_t end = HB_SET_VALUE_INVALID; + while (glyphs->next_range (&start, &end)) + { + coverage_range_count++; + if (start && included_glyphs.has (start - 1)) coverage_range_count--; + if (included_glyphs.has (end + 1)) coverage_range_count--; + } + included_glyphs.union_(*glyphs); if (klass) included_class_def_glyphs.union_(*glyphs); - if (num_glyphs != included_glyphs.get_population()) - coverage_size_val = compute_coverage_size (); + coverage_size_val = compute_coverage_size (); } if (klass) @@ -230,17 +242,6 @@ struct class_def_size_estimator_t return class_def_size (); } - unsigned num_glyph_ranges (const hb_set_t &glyphs) const { - hb_codepoint_t start = HB_SET_VALUE_INVALID; - hb_codepoint_t end = HB_SET_VALUE_INVALID; - - unsigned count = 0; - while (glyphs.next_range (&start, &end)) { - count++; - } - return count; - } - private: graph_result_t to_result() const { @@ -266,7 +267,7 @@ struct class_def_size_estimator_t unsigned coverage_base_size = OT::HBUINT16::static_size + glyph_size; unsigned range_size = 3 * glyph_size; unsigned format1_size = coverage_base_size + glyph_size * included_glyphs.get_population(); - unsigned format2_size = coverage_base_size + range_size * num_glyph_ranges (included_glyphs); + unsigned format2_size = coverage_base_size + range_size * coverage_range_count; return hb_min(format1_size, format2_size); } @@ -306,6 +307,7 @@ struct class_def_size_estimator_t hb_set_t included_classes; hb_set_t included_glyphs; hb_set_t included_class_def_glyphs; + unsigned coverage_range_count; unsigned class_def_range_count; unsigned class_max; unsigned coverage_size_val; diff --git a/src/graph/test-classdef-graph.cc b/src/graph/test-classdef-graph.cc index d82ffc3e9..4ec03eda8 100644 --- a/src/graph/test-classdef-graph.cc +++ b/src/graph/test-classdef-graph.cc @@ -327,6 +327,31 @@ static void test_running_class_size_estimates_with_locally_consecutive_glyphs () hb_always_assert(check_add_class_def_size(estimator, map, 3, {2, 3})); } +static void test_running_coverage_size_estimates_with_interleaved_glyphs () { + gid_and_class_list_t map = { + {0, 2}, + {1, 1}, + {2, 1}, + {3, 1}, + {4, 2}, + {5, 1}, + {6, 1}, + {7, 1}, + {8, 2}, + {10, 3}, + }; + + // Class 2 extends and joins the coverage ranges of class 1. + graph::class_def_size_estimator_t estimator = *graph::class_def_size_estimator_t::create (map.iter()); + hb_always_assert(check_add_class_def_size(estimator, map, 1, {1})); + hb_always_assert(check_add_class_def_size(estimator, map, 2, {1, 2})); + hb_always_assert(check_add_class_def_size(estimator, map, 3, {1, 2, 3})); + + estimator.reset(); + hb_always_assert(check_add_class_def_size(estimator, map, 2, {2})); + hb_always_assert(check_add_class_def_size(estimator, map, 1, {1, 2})); +} + static void test_class_def_intersects_class () { @@ -371,6 +396,7 @@ main (int argc, char **argv) test_class_and_coverage_size_estimates (); test_running_class_and_coverage_size_estimates (); test_running_class_size_estimates_with_locally_consecutive_glyphs (); + test_running_coverage_size_estimates_with_interleaved_glyphs (); #ifndef HB_NO_BEYOND_64K test_class_def_format_3_values (); #endif From 636e97026e85d35c8aea65a5a1aa988348d7a80a Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 30 Oct 2026 15:10:50 -0600 Subject: [PATCH 8/8] [repacker] Split PairPos and MarkArray subtables in linear time When the repacker splits an oversized GPOS subtable, the splitters resolved and re-homed the subtable's links one at a time with graph_t::index_for_offset() and graph_t::move_child(), each of which scans the vertex's link list from the start, so a split was quadratic in the number of links and no repacker limit counted that work. A crafted 131 KB font with 20 PairPosFormat1 subtables of 65,534 PairSets took ~45 s of CPU in hb-subset. Use the graph's existing tools the way ligature-graph.hh already does: - PairPosFormat1::split_subtables() builds position_to_index_map() once and looks each PairSet up in it; clone_range() sorts the links by position and moves the whole [start, end) offset range with one move_children() call, which keeps the moved and remaining links in order. - PairPosFormat2::clone_class1_records() now moves the class1 record byte range (whose only links are device tables) with one move_children() call, folding in the former transfer_device_tables() and dropping its move_child()-per-value-record loop and the re-sort of the whole link list after each record. - MarkArray::clone() adds the new mark-anchor links directly and removes the old ones in a single pass, the pattern AnchorMatrix::clone_rows() already uses. The now-unused pair_set_graph_index() helper and split_context_t fields are dropped. The reproducer drops to ~1.5 s; a new test, test_resolve_with_shared_pair_set_pair_pos_1_split, checks the split keeps PairSets in order; no public API/ABI change. Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-PQL6ZZ89. Co-Authored-By: Claude Opus 4.8 --- src/graph/markbasepos-graph.hh | 30 +++++++-- src/graph/pairpos-graph.hh | 109 +++++++++---------------------- src/test-repacker.cc | 114 +++++++++++++++++++++++++++++++++ 3 files changed, 169 insertions(+), 84 deletions(-) diff --git a/src/graph/markbasepos-graph.hh b/src/graph/markbasepos-graph.hh index 45b69d6ae..4a70449de 100644 --- a/src/graph/markbasepos-graph.hh +++ b/src/graph/markbasepos-graph.hh @@ -201,16 +201,34 @@ struct MarkArray : public OT::Layout::GPOS_impl::MarkArray unsigned offset_pos = (char*) &((*this)[mark].markAnchor) - (char*) this; unsigned* anchor_index; if (pos_to_index.has (offset_pos, &anchor_index)) - TRY (c.graph.move_child (this_index, - &((*this)[mark].markAnchor), - prime_id, - &((*prime)[i].markAnchor))); + TRY (c.graph.add_link (&((*prime)[i].markAnchor), + prime_id, + *anchor_index)); i++; } - // Restore correct ordering of the vertex links which are disturbed by move_child. - c.graph.vertices_[this_index].sort_real_links (); + // Finding the link for a single mark is O(n) so to avoid O(n^2), remove + // the old links of all of the moved marks in one pass. + auto& v = c.graph.vertices_[this_index]; + const auto& o = v.obj (); + int num_links = o.real_links.length; + for (int j = 0; j < num_links; j++) + { + const auto& link = o.real_links[j]; + unsigned mark = (link.position - MarkArray::min_size) / + OT::Layout::GPOS_impl::MarkRecord::static_size; + if (!marks.has (mark)) continue; + + c.graph.vertices_[link.objidx].remove_parent (this_index); + + v.remove_real_link_unordered (j); + num_links--; + j--; + } + + // Restore correct ordering after the above removes, which mess up link ordering. + v.sort_real_links (); return Ok(prime_id); } diff --git a/src/graph/pairpos-graph.hh b/src/graph/pairpos-graph.hh index 9b4cb06ea..62900ed07 100644 --- a/src/graph/pairpos-graph.hh +++ b/src/graph/pairpos-graph.hh @@ -61,11 +61,18 @@ struct PairPosFormat1 : public OT::Layout::GPOS_impl::PairPosFormat1_3 split_points; + + // Finding the object id associated with an array index is O(n) + // so to avoid O(n^2), precompute the mapping. + TRY_ASSIGN (auto pair_sets, c.graph.vertices_[this_index].position_to_index_map ()); for (unsigned i = 0; i < pairSet.len; i++) { - TRY_ASSIGN (unsigned pair_set_index, pair_set_graph_index (c, this_index, i)); + unsigned pair_set_position = (const char*) &pairSet[i] - (const char*) this; + unsigned* pair_set_index; + if (unlikely (!pair_sets.has (pair_set_position, &pair_set_index))) + return Err(INVALID_ARGUMENT); unsigned accumulated_delta = - c.graph.find_subgraph_size (pair_set_index, visited).value_or (0) + + c.graph.find_subgraph_size (*pair_set_index, visited).value_or (0) + SmallTypes::size; // for PairSet offset. partial_coverage_size += OT::HBUINT16::static_size; @@ -164,17 +171,18 @@ struct PairPosFormat1 : public OT::Layout::GPOS_impl::PairPosFormat1_3valueFormat[1] = this->valueFormat[1]; pair_pos_prime->pairSet.len = num_pair_sets; - for (unsigned i = start; i < end; i++) - { - TRY (c.graph.move_child<> (this_index, - &pairSet[i], - pair_pos_prime_id, - &pair_pos_prime->pairSet[i - start])); - } - - // Restore correct ordering of the vertex links which are disturbed by move_child. + // Moving the PairSets one at a time is O(n) per PairSet, so move the whole + // range in one pass. move_children keeps the links in the order it finds + // them, so sort by position first to keep the PairSets in array order. c.graph.vertices_[this_index].sort_real_links (); + const unsigned pair_sets_position = (const char*) pairSet.arrayZ - (const char*) this; + TRY (c.graph.move_children (this_index, + pair_sets_position + start * SmallTypes::size, + pair_sets_position + end * SmallTypes::size, + pair_pos_prime_id, + pair_sets_position)); + TRY_ASSIGN (unsigned coverage_id, c.graph.index_for_offset (this_index, &coverage)); TRY (Coverage::clone_coverage (c, coverage_id, @@ -184,13 +192,6 @@ struct PairPosFormat1 : public OT::Layout::GPOS_impl::PairPosFormat1_3 pair_set_graph_index (gsubgpos_graph_context_t& c, unsigned this_index, unsigned i) const - { - return c.graph.index_for_offset (this_index, &pairSet[i]); - } }; struct PairPosFormat2 : public OT::Layout::GPOS_impl::PairPosFormat2_4 @@ -296,12 +297,8 @@ struct PairPosFormat2 : public OT::Layout::GPOS_impl::PairPosFormat2_4& device_tables; const hb_vector_t& format1_device_table_indices; const hb_vector_t& format2_device_table_indices; @@ -444,59 +437,19 @@ struct PairPosFormat2 : public OT::Layout::GPOS_impl::PairPosFormat2_4 transfer_device_tables (split_context_t& split_context, - unsigned pair_pos_prime_id, - const hb_vector_t& device_table_indices, - unsigned old_value_record_index, - unsigned new_value_record_index) const - { - PairPosFormat2* pair_pos_prime = - (PairPosFormat2*) split_context.c.graph.object (pair_pos_prime_id).head; - - for (unsigned i : device_table_indices) - { - OT::Offset16* record = (OT::Offset16*) &values[old_value_record_index + i]; - unsigned record_position = ((char*) record) - ((char*) this); - if (!split_context.device_tables.has (record_position)) continue; - - TRY (split_context.c.graph.move_child ( - split_context.this_index, - record, - pair_pos_prime_id, - (OT::Offset16*) &pair_pos_prime->values[new_value_record_index + i])); - } - - // Restore correct ordering of the vertex links which are disturbed by move_child. - split_context.c.graph.vertices_[split_context.this_index].sort_real_links (); - - return Ok(); + const unsigned values_position = (const char*) &values[0] - (const char*) this; + return graph.move_children (split_context.this_index, + values_position + start * split_context.class1_record_size, + values_position + end * split_context.class1_record_size, + pair_pos_prime_id, + values_position); } graph_result_t shrink (split_context_t& split_context, diff --git a/src/test-repacker.cc b/src/test-repacker.cc index 47425d109..56ed8ab25 100644 --- a/src/test-repacker.cc +++ b/src/test-repacker.cc @@ -1588,6 +1588,56 @@ populate_serializer_with_large_pair_pos_1 (hb_serialize_context_t* c, c->end_serialize(); } +// One PairPosFormat1 with num_pair_set PairSet offsets which all point at one +// of num_shared small PairSets. PairSet i points at shared PairSet i % num_shared. +template +static void +populate_serializer_with_shared_pair_pos_1 (hb_serialize_context_t* c) +{ + c->start_serialize (); + + unsigned pair_set[num_shared]; + for (int i = num_shared - 1; i >= 0; i--) + { + char pair_set_table[] = { + 0, 1, // count + 0, (char) i, // second glyph + }; + pair_set[i] = add_object (pair_set_table, 4, c); + } + + unsigned coverage = add_coverage (0, num_pair_set - 1, c); + + char format[] = { + 0, 1 + }; + start_object (format, 2, c); + add_offset (coverage, c); + + char value_format[] = { + 0, 0, + 0, 0, + (char) ((num_pair_set >> 8) & 0xFF), + (char) (num_pair_set & 0xFF), + }; + extend (value_format, 6, c); + + for (int i = 0; i < num_pair_set; i++) + add_offset (pair_set[i % num_shared], c); + + unsigned pair_pos_1 = c->pop_pack (false); + + start_lookup (2, 1, c); + add_offset (pair_pos_1, 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 static void populate_serializer_with_large_pair_pos_2 (hb_serialize_context_t* c, @@ -2616,6 +2666,69 @@ static void test_resolve_with_extension_pair_pos_1_split () free (expected_buffer); } +static void test_resolve_with_shared_pair_set_pair_pos_1_split () +{ + // A PairPosFormat1 whose offset array alone is over the 16 bit limit, so it + // has to be split, and whose PairSets are all shared. Splitting must keep + // the PairSets in order and must not be quadratic in the number of PairSets. + constexpr int num_pair_set = 40000; + constexpr int num_shared = 4; + + size_t buffer_size = 200000; + void* buffer = malloc (buffer_size); + hb_always_assert (buffer); + hb_serialize_context_t c (buffer, buffer_size); + populate_serializer_with_shared_pair_pos_1 (&c); + + graph_t graph = graph_t::create (c.object_graph ()).value (); + auto context = graph::gsubgpos_graph_context_t::create (HB_TAG ('G', 'P', 'O', 'S'), + graph).value (); + hb_always_assert (context.lookups.get_population () == 1); + unsigned lookup_index = *context.lookups.keys (); + graph::Lookup* lookup = context.lookups.get (lookup_index); + hb_always_assert (lookup->split_subtables_if_needed (context, lookup_index).is_ok ()); + + const auto& lookup_vertex = graph.vertices_[lookup_index]; + const char* lookup_table = lookup_vertex.obj ().head; + unsigned subtable_count = *(const OT::HBUINT16*) (lookup_table + 4); + hb_always_assert (subtable_count > 1); + hb_always_assert (lookup_vertex.obj ().real_links.length == subtable_count); + auto subtables = lookup_vertex.position_to_index_map ().value (); + + unsigned pair_set_count = 0; + for (unsigned i = 0; i < subtable_count; i++) + { + unsigned subtable_position = 6 + 2 * i; + hb_always_assert (subtables.has (subtable_position)); + unsigned subtable_index = subtables.get (subtable_position); + + const auto& subtable_vertex = graph.vertices_[subtable_index]; + const char* subtable = subtable_vertex.obj ().head; + hb_always_assert (subtable_vertex.table_size () >= 10); + hb_always_assert (*(const OT::HBUINT16*) subtable == 1); // format + unsigned count = *(const OT::HBUINT16*) (subtable + 8); // pairSetCount + hb_always_assert (count > 0); + hb_always_assert (subtable_vertex.table_size () == 10 + 2 * count); + // coverage + one link per PairSet + hb_always_assert (subtable_vertex.obj ().real_links.length == count + 1); + + auto pair_sets = subtable_vertex.position_to_index_map ().value (); + hb_always_assert (pair_sets.has (2)); // coverage + for (unsigned j = 0; j < count; j++) + { + unsigned pair_set_position = 10 + 2 * j; + hb_always_assert (pair_sets.has (pair_set_position)); + const auto& pair_set = graph.object (pair_sets.get (pair_set_position)); + hb_always_assert (pair_set.tail - pair_set.head == 4); + hb_always_assert (pair_set.head[3] == (char) ((pair_set_count + j) % num_shared)); + } + pair_set_count += count; + } + hb_always_assert (pair_set_count == num_pair_set); + + free (buffer); +} + static void test_resolve_with_basic_pair_pos_2_split () { size_t buffer_size = 300000; @@ -3451,6 +3564,7 @@ main (int argc, char **argv) test_resolve_with_repeated_extension_promotion (); test_resolve_with_basic_pair_pos_1_split (); test_resolve_with_extension_pair_pos_1_split (); + test_resolve_with_shared_pair_set_pair_pos_1_split (); test_resolve_with_basic_pair_pos_2_split (); test_resolve_with_pair_pos_2_split_with_device_tables (); test_resolve_with_close_to_limit_pair_pos_2_split ();