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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
_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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
AnchorMatrix's offset array size was multiplied in unsigned arithmetic.
A small vertex with 46341 rows could therefore be accepted as a
46341-column matrix, leading to excessive work and allocation during
subtable splitting. PairPosFormat2 had the same problem on 32-bit
platforms.
Use the existing size_t saturating multiply helper and compare against
the payload length after checking the header. This preserves the width
of PairPosFormat2's size computation and avoids overflow in the header
addition as well.
Add bounded internal vertex tests for wrapping dimensions, exact valid
sizes, truncated payloads and headers, and empty matrices. The anchor
regression fails against the unchanged code without large allocations.
Discovered by Anthropic's OSS Scanner, as vulnerability
ANT-2026-7E6A2QQS.
Testing: meson compile -C build -j4; meson test -C build
(all 274 tests passed).
Assisted-by: OpenAI Codex
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
Discover GSUB/GPOS 1.2 lookups through LookupList2 and treat the
32-bit lookup-list link like other wide graph roots. Also preserve
parent multiplicity when identical lookup subtables are promoted to a
shared extension wrapper.
Add coverage for 1.2 extension promotion and repeated subtable links.
Assisted-by: OpenAI Codex <codex@openai.com>
None of the traversals require DFS order so BFS can be used instead which eliminates the possibility of stack overflow. For the queue we re-use the existing ordering_scratch_ space to avoid allocating any additional memory. As a bonus this fixes a bug in find_32bit_roots() that was the result of DFS traversal order.
All of the directed traversal methods are unified to a single common implementation.
* [subset-repack] fix potential out of bounds accesses
make sure we create a deep copy of the object before we mutate
* [subset-repack] fix is_shared(): only check real parents
* [subset-repack] add tests
* [subset-repack] apply AI proposed change
* address review comments
* [subset-repack] no need to duplicate shared liga_sets beforehand
Since we now would create a memory copy of the object before mutating
it, I think checking and duplicating shared liga_sets is not needed.
* [subset-repack] fix potential out of bounds accesses
make sure we create a deep copy of the object before we mutate
* [subset-repack] fix is_shared(): only check real parents
* [subset-repack] add tests
* [subset-repack] apply AI proposed change
* address review comments
* [subset-repack] no need to duplicate shared liga_sets beforehand
Since we now would create a memory copy of the object before mutating
it, I think checking and duplicating shared liga_sets is not needed.
Prior to this change the object id for a vertex in the repacker graph is it's position in the topological ordering. As a result after each sorting the object ids change. This decouples the topological sorting from the object id assignments. A separate ordering list is retained. This simplifies handling around object ids which no longer needs to account for them shifting, and improves performance by eliminating the step of reassigned link object ids after each sort.
When attempting to fix overflows nodes that have incoming edges from more than one parent can be duplicated. However, if all of these incoming links are virtual except for one duplicating it will effectively orphan it (one of the copies will be pointed to only by virtual links). Since parent book keeping is expensive we don't want to separately track virtual/real parents so instead just don't duplicate nodes that have at least one incoming virtual link.
Replaces a check for an exact match on the final serialized bytes. The previous check enforced equivalent topological sorting between result and expected, but we only really care that the graph's are equivalent and don't overflow.