update_distances() checked the vector's error state after resize(), but
left the return value unchecked, triggering Coverity CID 506917.
Check resize() directly and return ALLOCATION_FAILURE on failure. This
preserves the existing allocation failure behavior.
Tested with meson compile -C build -j 6 and meson test -C build
(275 tests passed).
Assisted-by: OpenAI Codex
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>
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 <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>
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
The graph total is size_t, while the output vector allocation takes an
unsigned int. Check the total against the blob length limit before that
conversion, so the allocation and serialization context use the same
size. Totals above INT_MAX cannot produce a valid output blob anyway.
Add a public-API regression whose objects share their backing storage,
keeping its memory use small while exercising a large graph total.
Testing: meson test -C build (292 passed; check-symbols skipped on
macOS), plus test-subset-repacker with ASan and UBSan. The regression
reproduces the invalid write without the check and fails cleanly with it.
Discovered by Anthropic's OSS Scanner, as vulnerability
ANT-2026-4Q0YO46E.
Assisted-by: OpenAI Codex
The class-zero intersection loop skipped ranges starting at glyph 0
without advancing the last glyph, and consulted a separate iterator
instead of the range being visited. Probe only actual gaps and always
advance past each range, so unlisted glyphs retain class-zero rules.
Check all 256 glyph sets over eight glyphs against per-glyph class
lookup for empty, contiguous, gapped, and explicit class-zero ranges.
The regression fails on the old source. The full Meson suite passes
(293 tests), including shape and subset.
Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-K9HEP9ZU.
Assisted-by: OpenAI Codex
Overflow resolution can retry GSUB/GPOS specialization on an already
modified graph. Clear derived space and priority state before assigning
spaces again so retries do not accumulate stale space identifiers.
Use the full signed range available to the packed distance key instead
of saturating valid distances as the number of spaces grows.
Assisted-by: OpenAI Codex <codex@openai.com>
Initialize every selected root's incoming-edge count before traversing
their combined subgraph. This prevents later root initialization from
overwriting counts collected through an earlier root.
An overflow root still needs a new packing space when no duplication is
needed, so move already-isolated roots instead of treating that case as
an unsuccessful resolution attempt.
Assisted-by: OpenAI Codex <codex@openai.com>
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>
ClassDef format 3 stores startGlyphID, glyphCount, and each class value
as uint24. Use the medium integer type for the class array, select a
serializable format based on both glyph and class ranges, and keep the
subsetter size estimator in sync.
Test parsing and querying a class value above 65535, and test that the
serializer and size estimator select the matching format.
Testing: meson test -C build
Assisted-by: OpenAI Codex
Reconcile the beyond-64K table type changes with the dependency API,
graph result handling, and variation-budget updates from main. Preserve
the branch's wider table variants while adopting the new behavior.
Build and test with Meson (281 passed, 1 skipped).
Assisted-by: OpenAI Codex <noreply@openai.com>
The current build for v14.5.0 fails to compile on gcc 4.9.4 which is
used on embedded Kobo systems.
Ref: https://github.com/OGKevin/cadmus/pull/1005
Change-Id: 7a4bec5b5418bd0921b273d8d4a1e79b
Change-Id-Short: spvolnuouvyr
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.
Resolve conflicts by taking hb_barrier() additions from main for all
switch dispatchers (COLR, Coverage, CursivePos, SinglePos,
ReverseChainSingleSubst) while keeping the beyond-64k extended
format cases.
For GDEF.hh: take main's clean GDEFVersion1_2<Types> template union
approach (which already handles beyond-64k via GDEFVersion1_2<MediumTypes>)
and incorporate the LigCaretList<Types> templating from beyond-64k,
expanding get_lig_carets() and collect_variation_indices() to dispatch
directly per version.
For coverage-graph.hh: keep beyond-64k's <Types> template but add
main's const qualifier to the vertex parameter.
For gsubgpos-graph.hh: keep beyond-64k's delegation to
OT::GSUBGPOS::get_lookup_list_field_offset() since GSUBGPOS uses the
flat struct approach in this branch.
For hb-ot-cmap-table.hh: keep beyond-64k's find_variation_selector_subtable()
which handles both format 14 and format 15 (beyond-64k).
Also fix PaintGlyph<Types>::paint_glyph out-of-line template definition
to include the template parameter, incorporating the get_solid_color
optimization from main.
Assisted-by: GitHub Copilot
* [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.
Make the GSUB/GPOS v1.2 LookupList2 path use LookupList<MediumTypes>,
so the lookup count remains 16-bit while per-lookup offsets are widened
to 32 bits. Runtime lookup access now branches between the lower and
upper lookup-list layouts.
As of June 2026, the proposed GSUB/GPOS v1.2 spec points LookupList2 at
LookupList, which would leave per-lookup offsets at 16 bits. Note that
HarfBuzz intentionally widens those offsets because the proposed shape is
not suitable for beyond-64k fonts.
Keep the graph repacker on lower GSUB/GPOS tables for now, since it walks
the raw lookup-list object layout.
Testing: meson compile -C build util/hb-subset test-repacker
Testing: meson test -C build --suite shape --suite subset
Testing: build/util/hb-shape /tmp/fonttools-noto-sans-lookuplist2/NotoSans-merged.ttf 'test'
Testing: build/util/hb-shape /tmp/fonttools-noto-sans-lookuplist2/NotoSans-merged.ttf 'කොහොමද'
Testing: build/util/hb-shape /tmp/fonttools-noto-sans-lookuplist2/NotoSans-merged.ttf 'क्षि'
Assisted-by: OpenAI Codex
ClassDef format 3 extends the glyph ID and glyph count fields,
but class values remain uint16. Reading them through Types::HBUINT
made format 3 dense class arrays use a 24-bit stride, so class
lookups could return zero for valid glyphs.
Update the graph size estimator to use the same fixed value width
and compare concrete format sizes instead of using the old shortcut.
Tested with `meson test -C build`.
Assisted-by: OpenAI Codex <codex@openai.com>
Coverage format 3 and 4 widen their array counts, and coverage
range records also widen the coverage index value. Account for the
larger records in the graph size estimator.
Use 32-bit top-level offsets where the extended GSUB/GPOS/context
formats specify long offsets, while leaving nested offset arrays as
24-bit offsets. SequenceRuleSet2 is the exception where the rule-set
array offsets stay 16-bit and only the rule contents use extended
widths.
Tested with:
- meson compile -C build util/hb-shape
- git diff --check
Existing fontTools-generated Sinhala upper-case test fonts still lose
GSUB/GPOS script data and need follow-up debugging.
Assisted-by: OpenAI Codex <codex@openai.com>
Move SmallTypes, MediumTypes, and the dual table accelerator
helpers into hb-ot-dual.hh. Keep Layout cache aliases in Layout
common and update standalone users to include the shared header.
Testing: meson test -C build
Assisted-by: OpenAI Codex
Maintain the encoded ClassDef glyph set and range count as classes
are added instead of reconstructing them for every size estimate.
This avoids quadratic PairPos splitting on large class definitions.
Assisted-by: OpenAI Codex
The repacker graph sanitizer accepted non-v1 GSUB/GPOS roots
because GSUBGPOS::get_size() returns only the version field size
for unsupported major versions. Graph specialization then still
consulted the numeric version and could read the v1.2 lookupList2
field from a too-small fuzz object.
Require version major 1 before using GSUB/GPOS graph-specific
lookup discovery.
Testing: meson test -C build test-repacker test-classdef-graph
Testing: meson test -C build --suite subset
Testing: meson test -C build
Assisted-by: OpenAI Codex
The default build has HB_NO_BEYOND_64K enabled, so serializers reject
glyph IDs above 0xffff with an integer-overflow error. Keep the high
glyph ClassDef size checks for beyond-64k builds only.
Testing: meson test -C build
Assisted-by: OpenAI Codex
MarkBasePos, MarkLigPos, and MarkMarkPos format 2 use nested
MarkArray2, BaseArray2, LigatureArray2, and Mark2Array2 tables
with 24-bit counts and offsets in different combinations.
Template the shared mark records and anchor matrices so format 1
continues to use SmallTypes while format 2 uses the widths specified
for the beyond-64k layout forms. Keep the subset graph wrappers bound
to their existing 16-bit forms.
Testing: meson test -C build
Assisted-by: OpenAI Codex
Update graph splitter comments to document that 24-bit layout formats
are intentionally left unsplit because their relevant offsets are
already widened.
Testing: not run; comment-only change.
Assisted-by: OpenAI Codex
Update the ClassDef and Coverage size estimator used by graph
splitting to derive glyph and range widths from the included glyphs
instead of assuming 16-bit table formats. Keep ClassDef size selection
aligned with the serializer heuristic, including class breaks and the
fact that class zero is not encoded in ClassDef tables.
Add high-glyph test cases that compare the estimator against actual
24-bit ClassDef and Coverage serialization sizes.
Testing: meson test -C build
Assisted-by: OpenAI Codex
Template the graph Coverage sanitizers on the layout type width and
dispatch formats 3 and 4 through the MediumTypes variants. This lets
graph sanitization accept 24-bit Coverage tables instead of rejecting
those formats outright.
Testing: meson test -C build
Assisted-by: OpenAI Codex
Template the graph ClassDef format wrappers on the layout type width
and dispatch formats 3 and 4 through the MediumTypes variants. This
lets graph sanitization accept 24-bit ClassDef tables instead of
rejecting those formats outright.
Testing: meson test -C build
Assisted-by: OpenAI Codex
Move the GSUB/GPOS versioned header fields back into GSUBGPOS
and select the active ScriptList, FeatureList, and LookupList
offsets from the table version.
Version 1.2 now uses the spec's 32-bit offset2 fields when they
are present, while the common list internals remain the existing
16-bit layout structures.
Testing: meson test -C build
Assisted-by: OpenAI Codex
Two callers were still using vector.resize(0) to drop accumulated
data: graph/serialize.hh's overflow tracking and hb_bit_set_t's
clear() (via its own internal resize()). resize(0) on a vector
in error state short-circuits without zeroing length, leaving
stale entries that downstream code then walks as if valid.
Fix both:
- serialize.hh: call overflows->clear() instead.
- hb-bit-set.hh: reimplement clear() to zero length/population
unconditionally by calling pages.clear() / page_map.clear()
directly, bypassing the internal resize() that bails when
`successful` is false.
Mirrors the March clear() fix in hb-vector.hh (commit d134f88824).
Assisted-by: Claude <noreply@anthropic.com>