Set fuzz-seconds to 300 instead of 600 to shorten pull-request feedback.
Validation: actionlint and git diff --check. Tests were not rerun for
this CI-only duration change.
Assisted-by: OpenAI Codex
Group pull-request runs by workflow and PR number so new commits cancel
older queued or running checks. Give non-PR runs unique groups, leaving
main-branch builds and tag releases independent.
Validation: actionlint; workflow concurrency assertions;
meson test -C build (302 passed, one skipped).
Assisted-by: OpenAI Codex
Linux and Rust shared a cache key, while Valgrind used the unscoped
default. Include the workflow name in cache keys consistently and give
Linux and Rust 1G each, since their 500MB caches were full in PR #6637.
Validation: actionlint; meson test -C build
(302 passed, one skipped).
Assisted-by: OpenAI Codex
Setting CC and CXX prevents Meson from automatically enabling ccache.
Wrap both compilers explicitly and isolate each sanitizer's cache.
Validation: actionlint; standalone Meson ASan/UBSan C/C++ build and
cache hits on rebuild; meson test -C build
(302 passed, one skipped).
Assisted-by: OpenAI Codex
Install the native ccache package for each MSYSTEM and persist its
workspace cache separately for MINGW64 and CLANG64. Check compiler
contents across package updates and report compiler-cache statistics.
Validation: actionlint; YAML assertions; meson test -C build
(302 passed, one skipped). Native MSYS2 validation remains in CI.
Assisted-by: OpenAI Codex
Disable Cairo and dependency tests for GLib and libffi. Keep GLib so
HarfBuzz's API tests, including DirectWrite, still build and run under
MSVC. MSYS2 continues to cover the Cairo integration on Windows.
Validation: actionlint; meson test -C build
(302 passed, one skipped). Native MSVC validation remains in CI.
Assisted-by: OpenAI Codex
Meson does not automatically prepend ccache to compilers selected in a
cross file. Generate a CI-only overlay with explicit compiler wrappers
and isolate the cache by target architecture. Keep the regular cross
files usable without ccache installed.
Validation: actionlint; C/C++ Meson cross-builds for i686 and x86_64,
including cache hits on rebuild; meson test -C build
(302 passed, one skipped).
Assisted-by: OpenAI Codex
The cross-build only runs HarfBuzz's test suite, but Pixman still builds
its own tests and demos by default. Disable both, including their shared
test utilities, while retaining the libraries used by Cairo.
Validation: Pixman 0.43.4 Meson setup and target introspection;
bash -n .ci/build-win.sh; meson test -C build
(302 passed, one skipped).
Assisted-by: OpenAI Codex
Remove the three-job limit left over from CircleCI. The Windows cross
build now runs on GitHub Actions and can use Meson's default parallelism.
Validation: bash -n .ci/build-win.sh; meson test -C build
(302 passed, one skipped).
Assisted-by: OpenAI Codex
In a well-formed gvar the per-glyph data ranges [offset[i],
offset[i+1]) are disjoint, so the retained glyphs' data add up to at
most the table. gvar::subset()'s avar2 culling pass used the offsets
as they are, so malformed offsets (0, D, 0, D, ...) could point
thousands of glyphs at one 128 KB block; the pass parsed, rewrote and
kept a heap copy of it once per glyph, repeated on each of the
serializer's buffer-doubling retries (26 s and 1.3 GiB from a 251 KB
font before it was rejected).
Restore the invariant where the pass is driven: charge each retained
glyph's byte length to a budget equal to the source blob length with
hb_budget_spend(), and on exhaustion raise HB_SERIALIZE_ERROR_OTHER
so _hb_subset_table_try() does not retry. A spec-conforming table
can never reach the limit, so there is no tuning constant and valid
fonts subset byte-identically; a font whose retained glyphs' gvar
ranges overlap by more than the table length now fails avar2 partial
instancing.
Adds test_avar2_culling_aliased_gvar_data to test/api/test-subset-avar2.c.
The non-avar2 instantiate() branch trusts the same offsets and is
not touched here.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-NJZQ4XFP.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
* [subset] Budget the glyf points a plan keeps for partial instancing
For partial instancing the subset plan decodes every retained glyph
through Glyph::get_all_points_without_var() and keeps all the points in
plan->new_gid_contour_points_map until the plan is destroyed. That
caller passed no work budget, and nothing capped the total. A simple
glyph of repeated flags declares ~65536 points in ~526 bytes, and a
loca whose offsets alias one another lets many glyph ids share those
bytes, so a 25 KB font drove plan creation to 2.2 GB.
PR #6256 added a charge-before-allocate budget to
SimpleGlyph::get_contour_points() and passed it from the draw/extents
path, but left this subsetter caller unbudgeted. Give the loop one
plan-wide budget, the larger of HB_BUDGET_SUBSET_CONTOUR_POINTS and the
source glyf length, and charge each glyph's decoded points after it is
decoded. One glyph's decode is bounded by the format (about 786 KB),
so the transient is proportional to the input; the budget bounds what
the plan retains. Exhausting it fails plan creation, the same outcome
as any other decode failure in this loop. Ordinary glyph data carries
at least one byte per point, so the size-derived bound does not
constrain well-formed fonts.
Adds an API regression test (test_subset_gvar_shared_glyph_data) with
an aliased loca over a 65536-point simple and composite glyph.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-O2ZFVVUI.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* [subset] Budget the avar2 reachable-range computation
_compute_avar2_reachable_ranges() bounded only the breakpoint grid
(MAX_GRID = 16384 vertices), while its real work is
axes x vertices x active row columns x tents. A delta-set row may list
the same region tens of thousands of times, and a clamped
DeltaSetIndexMap lets every fvar axis share that one row, so a 50 KB
font cost about two minutes of CPU per hb_subset_plan_create_or_fail().
Charge one shared allowance per plan, HB_BUDGET_SUBSET_AVAR2_RANGES, at
the three places the work is created: scanning the row's columns into
the active set, collecting each active region's tents, and the exact
grid enumeration (charged up front as grid_size x (active + tents)).
Degradation reuses states the surrounding code already handles: an axis
whose exact enumeration does not fit takes the existing
interval-arithmetic bounds (still conservative, so the instance stays
correct), and once the allowance is gone the remaining axes are left
unconstrained. The hostile fonts now finish in well under a second;
real avar2 fonts use a small fraction of the budget and their
output is unchanged.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-3VDGZ019.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* [subset] Guard against null glyf blob in contour-point budget
get_instance_glyphs_contour_points() sizes its op budget from the
source glyf table length. When head.glyphDataFormat (or
indexToLocFormat) is out of range the glyf accelerator is disabled and
reference_glyf_table() returns no blob, so hb_blob_get_length() then
dereferenced a null pointer and crashed during partial instancing.
Take the length only when the blob is non-null. Add a regression test
that builds a variable font with an invalid glyphDataFormat and plans a
partial instance.
Reported by Anthropic's OSS Scanner.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* [subset] Document that the avar2 range budget fallback is safe
Running out of HB_BUDGET_SUBSET_AVAR2_RANGES returns early from
_compute_avar2_reachable_ranges() and records nothing for the
remaining axes. That does not produce a wrongly instanced font:
avar2_reachable_ranges is only used to cull variation data that
cannot be reached, and an axis without a range is never culled
(_hb_avar2_region_is_dead() skips it, the same as the VARC path that
resets the map). A pinned axis that is not detected as
self-contained stays in fvar as a hidden pin, which is what CFF2
fonts always get. The output is correct, only larger. Likewise the
exact-grid fallback uses interval bounds, which are conservative.
Say so in the comments instead of "left unconstrained".
Tested: meson test -C build (278/278); hb-subset --instance
wght=400 and wght=300:700 on GoogleSansFlex, NotoSansKR and
SourceSerif4 variable fonts, all glyphs.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
* [subset] Bound the dense delta matrix when rebuilding a VarStore
item_variations_t::as_item_varstore() allocates one int per
(row, region) pair for the whole rebuilt ItemVariationStore, every row
as wide as the full region list. In the font a row only pays for the
regions of its own VarData (possibly none, and several dataSets offsets
may share one VarData), so the row count and the region count are
independent and their product is unbounded: a ~120 KB font drove the
allocation to 2.4 GB, and a 972-byte font with region-less rows to
~800 MB.
Bound the matrix before allocating it, at the single site all
instancing callers (MVAR, HVAR/VVAR, GDEF, BASE, COLR, avar) pass
through: HB_SUBSET_MAX_VARSTORE_ROWS (1<<21, which also bounds the
per-row hb_vector_t overhead and catches the zero-width-row variant)
and HB_SUBSET_MAX_VARSTORE_DELTAS (1<<26 cells, 256 MB of int),
computed in 64-bit. These are flat ceilings on this one allocation
rather than a bound proportional to the source size: optimizer output
routinely has several VarData over disjoint region subsets, so the
dense matrix is legitimately much wider than any single VarData and a
proportional bound would reject it. No store in the test fonts comes
near the cell cap. Returning
false is the path a failed resize() already takes, and every caller
drops the table on it. Rows are fixed-width, so they are now allocated
with resize_exact(), removing the ~19% growth slack per row.
The cap bounds the amplification rather than removing it (a ~75 KB
font just under the cell cap still peaks around 265 MB); the
structural follow-up is to stop making every row as wide as the whole
region list.
Adds a unit test (test_delta_matrix_limits) covering both caps and an
under-cap case.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-0ZZNV0U6.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* [instancer] Budget tuple splitting when narrowing axes
Narrowing an axis makes change_tuple_variations_axis_limits() replace
every tuple whose region uses that axis with up to six tuples
(rebase_tent solutions), axis after axis with no merging, so one region
spanning N narrowed axes becomes up to 6^N tuples, each with its own
copy of the axis map and deltas. A 364-byte font with a region on 8
narrowed axes drove one hb_subset_or_fail() call to 9 s of CPU and
1.7 GB. The only existing limit, the subset output buffer cap, is
checked after the whole instantiation has run.
Charge the copies to a cumulative budget held in optimize_scratch_t,
which every caller (gvar, cvar, CFF2, and item_variations_t for
GDEF/HVAR/MVAR/BASE/COLR) already keeps for one whole table. The budget
starts at HB_BUDGET_INSTANCER_MIN and earns HB_BUDGET_INSTANCER_FACTOR
times the cost of each source tuple; each split spends
out[0].get_cost() x (out.length - 1) through the existing
hb_budget_spend() helper, and the function returns false when the
budget is spent, which all callers already treat as failure. The cost
(32 + 8 per axis + 1 per row/point) scales with what a copy allocates
for both ItemVariationStore and gvar tuples, so the budget also bounds
a store with many VarData and a gvar with many glyphs.
An instancing request whose splits exceed the budget (roughly more than
64 copies per source tuple beyond a 4M-unit floor) now fails instead of
producing a store that could not be serialized anyway. Normal fonts
stay far below the floor, so the subset suite's partial-instance
tests are byte-identical.
Adds a unit test (test_tuple_split_budget) with a tent on 16 axes.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-X7UB9BVO.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* [subset] Budget the dense per-point expansion of gvar/cvar tuples
create_from_tuple_var_data() expands every tuple to arrays with one
entry per point of its glyph (per cvt value), however few points the
tuple actually names, and keeps them until the table is serialized. The
tuple count (12-bit) and point count (16-bit) are each bounded per
glyph, but their product and its sum over the table are not, and neither
factor costs many font bytes: 15 bytes of gvar can expand to ~590 KB,
and a 31 KB font reached 2.1 GiB.
Give the decode a per-table points budget,
HB_BUDGET_SUBSET_TUPLE_POINTS_FACTOR per byte of the source table
floored at HB_BUDGET_SUBSET_TUPLE_POINTS_MIN, owned by
glyph_variations_t for gvar and a local in cvar::subset(), and charge
point_count per decoded tuple before expanding it. Exhausting it
returns false exactly like the function's existing allocation-failure
paths (the table is dropped from the subset). Real gvar tables
expand to only a small multiple of their byte size, so the factor
leaves ample headroom. The extra copies made when a range limit splits
a tuple are already bounded by the instancer split budget in
optimize_scratch_t, so they are not charged here again.
Adds a unit test (test_tuple_points_budget) covering the decode charge.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-8CH2PGW8.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
* [subset/cff] Bound parsed subroutines by the table size before allocating
subr_subsetter_t::subset() resizes one parsed_cs_str_vec_t per Font DICT
to that DICT's localSubrs->count, assuming the sum is bounded by the
table. It is not: any number of Font DICTs may point at the same
Private DICT and Subrs INDEX, so a 500 KB font with 16 Font DICTs all
sharing one 1000-subr INDEX cost about 1.6 GiB (measured: control 10
MiB, shared 1651 MiB; 2.8 GiB with hb_subset_preprocess).
Sum the global plus per-Font-DICT local subroutine counts in 64-bit
before any per-Font-DICT allocation, and fail the subset when the
records would exceed 256 bytes per byte of the source table, the same
ratio _hb_subset_table_try() uses to stop growing the output buffer.
A font whose Font DICTs do not share their Subrs needs at least one
table byte per subroutine, so it stays far below the limit; every
CFF/CFF2 font in the test corpus is at most a couple of bytes per table
byte. Over the limit the subset fails, as any CFF planning failure has
since dde7da182e; the shared font now peaks at 7 MiB instead of 1.6 GiB.
The check sits before the allocations in the non-accelerator branch, so
it also covers the hb_subset_preprocess path and both CFF1 and CFF2
instantiations of the template; the --desubroutinize flattener path
does not allocate per subroutine and is unaffected.
Adds test_subset_cff1_shared_local_subrs: a 16-Font-DICT CID font with
1000 local subrs subsets when the subrs are unshared and fails when
every Font DICT shares them.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-HPFG1IAV.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* [subset] Share one CFF charstring work budget across a subsetting pass
Every per-glyph charstring loop in the subsetter (subr_subsetter_t::
subset, subr_flattener_t::flatten, the two CFF2 partial-instancing
passes, the CFF2 instance-metrics loop, and the CFF1 seac closure in
the plan and in the depend builder) created a fresh interpreter bounded
only by HB_CFF_MAX_OPS per charstring. Glyphs can share subroutines,
so a font where every glyph makes one cheap call into a deeply nested
shared subr cost num_glyphs x ~200,000 ops: a 121 KB, 30,000-glyph font
took 33 s to subset (control 0.05 s).
Give each pass one cumulative counter, max(HB_BUDGET_SUBSET_CFF = 2^24,
32 ops per table byte), threaded through cs_interpreter_t::interpret()'s
existing budget argument exactly as the outline and extents paths do.
When it runs out, interpret() fails as it does for a single over-limit
charstring, so the CFF/CFF2 table fails to subset (the subset fails, as
any CFF planning failure has since dde7da182e); the seac closure fails
the plan and the depend builder fails. The 32-ops-per-byte allowance
was measured against the in-tree corpus, where real fonts interpret at
most a few operations per CFF byte, so they stay far below it and
produce byte-identical output; the attacker font now fails in 0.17 s.
Adds test_subset_cff1_shared_subrs: four shared-subr glyphs subset
fine, while a hundred of them exhaust the budget and the subset (and
the dependency builder) fail.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-Z5NLRFA6.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
* [test] Force the ot shaper in the layout budget tests
test_ot_layout_gpos_mark_base_rescan_budget calls hb_shape() with no
shaper forced, then asserts an OT-specific max_ops trip via
hb_buffer_allocation_successful(). Under the HarfRust shaper
(HB_SHAPER_LIST=harfrust, as the rust CI job re-runs the api suite)
it aborts, because harfrust shapes independently and never reaches
the C-side max_ops paths it tests.
Shape with hb_shape_full(..., {"ot", NULL}) so it exercises the OT
shaper regardless of the configured shaper list, as
test_shape_lookup_budget already does.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* [layout] Charge the skip, skipped-record and ligature walks
The per-pass `len / 16` charge does not bound per-position inner work:
the skipping iterator's rescans over default-ignorables, apply_lookup's
walk over a rule's skipped LookupRecords, and match_input /
ligate_input's walk over a ligature's components and marks. Each is a
CPU-DoS a crafted font triggers under the default max_ops.
Charge each on its work path only, so honest shaping is unaffected:
skipping_iterator_t::next/prev charge one op per skip (a first-try
match charges nothing); apply_lookup charges each skipped record;
match_input charges the ligbase backward walk and ligate_input the
mark re-adjust walk, once each.
Reproducers drop from 20 s / 6.8 s / 3.8 s to 0.05 s / 0.003 s /
0.02 s; in-house and aots shaping tests pass with no output change
(the pre-existing text-rendering-tests failures are unchanged).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* [layout] Stop matching once the skip/walk budget is spent
The previous commit charged the walks, but the skipping iterator's skip
arm only decremented max_ops; within one pass a tiny aliased font could
still re-run a walk per candidate, per rule or per subtable without bound
(dfrg's harfrust #604 review found the same gaps here).
Flag the buffer unsuccessful when the skip arm spends the budget -- it
still never early-returns, so *unsafe_to stays set for the kern machine --
and stop the loops that repeat walks once it clears: apply_backward,
Ligature::apply, the reverse-chain and mark-base/lig subtable applies,
and context_apply_lookup / chain_context_apply_lookup. apply_forward
already checks successful.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* [layout] Enforce the budget in the shared subtable loop
dfrg's re-review (harfrust #604): the per-kind entry guards miss paths
that scan before reaching them -- context format 3, the context/ligature
pre-match scans, cursive and mark-to-mark -- so a lookup aliasing thousands
of subtables restarts a buffer scan at each one. Guard the shared
accelerator apply instead (hb_applicable_t::apply), and drop the
now-redundant reverse-chain and mark-base/lig entry guards it subsumes.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Run the six configuration variants in one job and the four C++
compiler/standard variants in another. This removes eight runner
requests per push or pull request while retaining all compile checks.
Group logs by variant and accumulate failures so later checks still run.
Validated all 16 compile/link checks locally, workflow Bash syntax,
compiler-failure propagation, and actionlint with the existing
ubuntu-26.04 runner label allowed.
Fixes: https://github.com/harfbuzz/harfbuzz/issues/6649
Assisted-by: OpenAI Codex
cff2_instancing_plan_t::create() builds k identity tuples of k cells
(then keeps a k-float column per surviving solver tuple) for every
entry of the CFF2 ItemVariationStore's VarData offset array, and
nothing bounded k (a 16-bit region count), the number of entries, or
their aliasing of one VarData. The work is therefore quadratic in a
font field, so a 12 KB font cost 2.2 GB.
Charge those cells, before they are allocated, to a per-table budget
HB_BUDGET_SUBSET_CFF2_CELLS (2^24 cells) via the existing
hb_budget_spend helper, at both allocation sites (the k*k identity
tuples and the surviving solver columns). Exhausting it fails create()
like any other planning failure, so the partial instance fails safely
(bounded at ~175 MB worst case) instead of exhausting memory.
Adds test_instance_cff2_vardata_budget: a 6.8 KB font with 40 offsets
aliasing one unused 800-region VarData must fail to partially instance
rather than build a region transform for each; it succeeds (keeping
CFF2 at hundreds of MB) before this change.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-I7KWU2X6.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
hb_depend_context_t::recurse() only refused to re-enter a lookup already
on the call stack, so a chain of distinct Context lookups recursed once
per lookup (stack overflow around 8600 lookups on an 8 MB stack) and
lookups invoking each other in every order were walked once per ordering
(a factorial number of interned paths, gigabytes of memory).
recurse() is where every sibling context (closure, closure-lookups,
apply) enforces HB_MAX_NESTING_LEVEL, so add the same nesting_level_left
guard here; shaping never applies lookups nested deeper, so no edge the
closure can reach is lost (a chain's final edge drops at exactly the
depth the closure stops, 65->66). Bound the number of distinct
recursion paths with a counter kept over the whole table (not cleared by
reset_recurse_cache, which runs per top-level lookup) against a new
HB_MAX_DEPEND_RECURSE_PATHS limit in hb-limits.hh, so it can be tuned
on its own; exceeding it fails the build so
hb_subset_depend_from_face_or_fail() returns nullptr instead of emitting
a truncated graph. The largest whole-table path count among the test
fonts is 744 (NotoNastaliqUrdu-Bold), so 35000 leaves ample headroom.
Builds only with experimental_api. Adds a small permutation-font fuzz
seed and a test-ot-depend test; test-ot-depend, the depend fuzzer and
the depend-closure-parity tests pass. Related to PR #6185.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-N28924W8.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
reset_recurse_cache() runs once per top-level lookup and cleared
completed_recursions and recurse_path_to_index with hb_hashmap_t::clear(),
which walks the whole table and keeps its allocated capacity. A single
lookup that grew these maps large therefore made every later top-level
lookup pay to walk that full capacity, however little it recursed,
giving a font with one busy lookup followed by many trivial ones a CPU
DoS in hb_subset_depend_from_face_or_fail().
Add clear_or_release(): when a map is large but was left mostly empty by
the lookup that just finished, swap in fresh storage before clearing, so
later lookups start from a small table. Adds a fuzzer regression font.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-PNJPHF76.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
propagate_attachment_offsets() turns a mark's stored attachment into an
offset by summing the advances of every glyph between the mark and its
base. That distance can be up to 32767 glyphs (the range of
attach_chain), and position_finish_offsets() runs the pass once per
attached glyph, so the total work is the sum of all mark-to-base
distances and is not bounded by the font; it was never charged to
buffer->max_ops. Attacker-chosen text over a cooperating font (or the
kerx path) could thus make hb_shape() spend several times the budgeted
CPU.
Thread the buffer into propagate_attachment_offsets() and charge the
base-to-mark distance to buffer->max_ops before the summation loops,
failing the shape when the budget runs out (the same budget the
unsafe_to_break walk over this range already uses). Normal text, whose
marks sit next to their base, pays a negligible amount.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-4JGOSACZ.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
MarkBasePosFormat1 and MarkLigPosFormat1 find a mark's base with a
cache (c->last_base / last_base_until) that is only amortized while
buffer->idx moves forward. A (Chain)Context lookup that recurses into
the mark lookup at input positions out of order resets the cache, so
each application rescans the glyphs from last_base_until to idx from
scratch; on a long run of marks with no base this is quadratic and was
uncharged.
Charge the rescanned span (idx - j) to buffer->max_ops after the
backward search in both lookups, failing the shape when the budget runs
out. A real mark-heavy font pays a negligible amount. Adds a
regression test shaping a Context lookup that recurses to MarkBasePos
at positions 1,0,1,0,...
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-FJEXEDJ4.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Lookups can share subtables, features can share lookups, and each
shaping stage applies its lookups anew, so the number of passes over
the buffer is not bounded by the font size. An earlier lookup can
also grow the buffer far beyond the text the budget was sized from:
a font that grows one character into a long buffer and then walks it
with thousands of lookups (as in harfbuzz/harfrust#571) made hb_shape()
spend CPU out of proportion to the text, and none of it was charged
to buffer->max_ops.
Charge each pass in apply_string() len / 16 for walking the buffer,
even if it applies at no glyph (skipping a glyph is cheap, hence the
division; applying at one is charged only through the buffer
operations and nested lookups it does), and stop the stage loop in
hb_ot_map_t::apply() once the buffer has failed. Nothing is charged
in the matching hot loops (skipping iterator, RuleSet, ChainRuleSet,
LigatureSet): charging there cost real fonts most of the budget in
HarfRust (Gulzar spent about half of max_ops on ordinary Urdu prose,
Noto Sans Duployan ran out on its own sample text). Aliased rules and
ligatures stay bounded by the sanitizer, including the ChainRule array
charge. Matches harfbuzz/harfrust#601.
test_shape_lookup_budget grows one 'a' to 65025 glyphs before applying
aliased lookups, and checks that the pass charge stops the shape.
With the font from harfbuzz/harfrust#571 (one 'A' grown to 30,000
glyphs, then 2,000 lookups), hb_shape() takes about 10 ms instead of
0.6 s, stopping after about 35 passes with the glyphs kept. Gulzar
and Noto Nastaliq Urdu spend under 0.5% of max_ops on Urdu and Persian
prose. Noto Sans Duployan spends up to 45% on its sample text, as on
main: nearly all of it is the _infos_set_glyph_flags() charge from
#5522; the per-pass charge adds about 5%.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-6A9E6OEX.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-K2T2LOJH.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-DVG5XAU0.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* [sanitize] Charge ChainRule backtrack/input/lookahead arrays to max_ops
ChainRule::sanitize() checks the length of each of its three arrays but
only sanitizes the trailing LookupRecord array, so it never charges
max_ops for the bytes it skipped over. A table with many ChainRuleSet
offsets all pointing at one large ChainRule could therefore be
sanitized in time proportional to offsets x rule size, escaping the
sanitizer's work bound (restoring the accounting removed by 385896ff6).
Charge the skipped span (from this to the LookupRecord array) to
check_ops before sanitizing the records. Adds a fuzzer regression
font.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-EFNNHRHV.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* [GPOS] Charge zero-size ValueRecord arrays to the sanitizer op budget
When a ValueFormat is empty its records take no bytes, so
ValueFormat::sanitize_values() and PairPosFormat2::sanitize() pass
check_range() without charging max_ops for the records, while later
code (the subsetter, variation-index collection) still walks count
records. A tiny table can thus declare a huge valueCount / class
matrix and cost the subsetter CPU out of proportion to its size.
Charge count ops when the record size / stride is zero, following the
918193ebf precedent. Adds two fuzzer regression fonts.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-HFGOLC64.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
* [subset] Charge Coverage and ClassDef glyph walks to a work budget
Coverage::subset() expands a format 2 Coverage glyph by glyph, up to
numGlyphs, every time an offset to it is subset, and nothing bounded
that work. A 10-byte range Coverage referenced by 30,000 two-byte
offsets in a subtable listed 8 times costs 1.6e10 iterator steps,
while the sanitizer only bounds work by table bytes; a 60 KB font
keeps hb-subset busy ~50 s. GDEF's MarkGlyphSets reaches the same
walk with no feature or lookup needing to survive planning.
Give hb_subset_context_t a per-table work budget
(HB_BUDGET_SUBSET_TABLE, in the hb_budget_spend() idiom of
hb-limits.hh) with a check_ops() helper that fails the serializer once
exhausted, and charge Coverage::subset() its capped population before
the walk. Charging inside Coverage::subset() covers every caller
(ReverseChainSingleSubst, (Chain)ContextFormat3, GDEF MarkGlyphSets,
...) without touching them. The same unbounded per-reference pattern
in ClassDefFormat1_3 / ClassDefFormat2_4::subset() (the range or
glyphset walk and the glyph_filter count) is charged the same way.
A hostile table that exceeds the budget now fails the subset cleanly
(hb_subset_or_fail returns NULL) in a fraction of a second instead of
succeeding slowly; valid-font output is byte-identical and the
heaviest local table spends a small fraction of the budget.
test_subset_shared_coverage_budget builds the reverse-chaining GSUB in
memory and asserts 256 shared references subset while 2048 fail.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-LLIWV9UK.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* [subset] Charge layout glyph walks to the existing subset budget
Drop the separate HB_BUDGET_SUBSET_TABLE budget and the second
hb_subset_context_t field it needed; check_ops() now charges
budget_remaining (HB_BUDGET_SUBSET_GLYF, 1 << 28), the per-table
budget glyf instancing already uses. Both are per-table and shared
across buffer-size retries, and no table spends both.
The larger budget still bounds the attack (fails after 2^28 glyph
steps, ~3 s), so test_subset_shared_coverage_budget now expects the
failure at 8192 shared offsets instead of 2048.
Subsetting all glyphs with --layout-features='*' of Gulzar,
NotoSansKR-VF and GoogleSansFlex-VF keeps GSUB/GPOS/GDEF with output
byte-identical to before; the heaviest table (Gulzar GPOS) spends
~98K units, under 0.04% of the budget. Full meson test: 278 OK.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* [depend] Clip context glyph sets to the face and charge a build budget
While extracting GSUB dependencies, find_or_create_glyph_set() turned
every Coverage (format 3 contexts) and class (format 2 contexts) that
a contextual rule mentions into an hb_set_t holding every glyph id the
table lists, whether the face has it or not, with no budget on the
expansion or on the second copy kept in the returned graph. In
experimental builds, where the depend API and 24-bit Coverage formats
live together, a 6.5 KB font with 400 backtrack Coverage format 4
tables each covering [0, 0xFFFFFF] drives a build to ~2 GB.
Clip the cached sets to the face in find_or_create_glyph_set(), the
one place every context position goes through (the first input
Coverage and ReverseChainSingleSubst already clip this way), so the
copies kept in the graph shrink with them. For real fonts this
changes nothing; only broken fonts stop carrying glyph ids past the
face.
Clipping alone is not enough: the temporary is still expanded in full,
and the glyph count itself is cheap to inflate with a MAXP table. So
add a work budget for the whole build in the existing hb_budget_spend()
style: HB_BUDGET_DEPEND, budget_remaining on hb_depend_data_builder_t,
and charge_set(), which spends HB_BUDGET_4 per page while expanding a
temporary and HB_BUDGET_32 per page for every set the graph or context
keeps (new_set(), find_or_create_glyph_set(), find_or_create_recurse_set()).
Running out fails the build and hb_subset_depend_from_face_or_fail()
returns NULL, as it already does on allocation failure. A
get_page_count() accessor is added to the bit-set types so the charge
does not reach into set internals; no public API change.
The 400-position font now peaks at ~11 MB instead of ~2 GB, the 64 KB
/ 4000-position font is refused, and hb-subset-depend output is
unchanged for real fonts. Regression tests build the face with
hb_face_builder_create(): one asserts no glyph above the face count is
kept, the other that a 600-range face is refused.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-856K54QG.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* [layout] Charge GSUB glyph closure to a per-session work budget
hb_closure_context_t bounded GSUB glyph closure only by counting lookup
visits (HB_MAX_LOOKUP_VISIT_COUNT per round), and forgets which lookups
are done whenever the glyph set grows, so what one visit walks -- through
aliased offsets, many times the table size -- was charged to nothing. A
LigatureSubst with 9000 ligatureSet offsets aliased onto one 64-component
Ligature, re-walked after every one of 1700 Context triggers that each
add a glyph, makes hb-subset --unicodes='*' of an 86 KB font spend ~110 s
of CPU. A ReverseChain/ChainContextFormat3 with aliased backtrack
Coverages is a second way in.
Give the context an int64_t budget (HB_BUDGET_LAYOUT_CLOSURE records, in
the hb_budget_spend() idiom) spent as each closure() implementation walks
its arrays: dispatch() charges a visit its coverage record count;
ligature sets / ligatures / components, sequences, alternates,
single-subst intersections, rule sets and rules, context Coverages (via a
spend_coverages() helper) and the per-rule-set ClassDef walks are each
charged. Coverage and ClassDef gain a get_record_count() helper because
intersects()/intersect_set() are linear in records, not population. Once
the budget is spent, should_visit_lookup()/lookup_limit_exceeded() stop
the closure early, exactly as they do at the visit limit.
The budget lives in the context, so both public closure entry points (also
reached from hb_ot_shape_glyphs_closure() and the subset plan) are covered
with no API/ABI change. Both attack shapes drop to ~1 s and the control
font's closure output is byte-identical; the heaviest real font in the
corpora uses about 1% of the budget. A hostile GSUB now gets a truncated
closure, as one hitting the visit limit already does.
test_ot_layout_lookups_substitute_closure_budget builds the hostile table
in C and drives hb_ot_layout_lookups_substitute_closure() over it.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-J9K92HA9.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Merge main's active-glyph fast paths and precomputed ClassDef caches
with the dependency and GSUB closure budgets. Charge the fast paths
for the glyphs they visit and the class caches for their ClassDef
scans, preserving both the optimizations and the work limits.
The full Meson suite passes with experimental APIs enabled (300 tests)
and with the default configuration (281 tests). Also syntax-checked
hb-ot-layout.cc with HB_NO_BEYOND_64K.
Assisted-by: Codex
std_code_to_glyph() resolves a seac component (bchar/achar) with
Charset::get_glyph(), a linear scan of the whole charset, and every
load of a seac charstring does it twice. The scan is not charged to
the glyph work budget, so a COLRv0 glyph whose layers all name one
seac glyph costs seconds of CPU while the budget stays almost
untouched (the attacker font: 32 s).
Charging the scan is not a good fit here: Charset::get_glyph() does
not report how far it scanned, so there is no exact cost to charge,
and a flat per-lookup charge against the shared subset budget would
make large fonts with many accented seac glyphs fail to subset.
Instead remove the redundant work: the key space is the 256
StandardEncoding codes, so on first use build a 256-entry
code-to-glyph table in one pass over the charset, recording the
first glyph carrying each StandardEncoding SID, as get_glyph() does.
This fixes all three callers (path, extents and the subsetter's seac
closure) with byte-identical output.
The table is allocated lazily and installed with cmpexch, like the
accelerator's glyph_names, and freed in _fini(): the accelerator
grows by one pointer, HB_NULL_POOL_SIZE is unchanged, and nothing is
allocated for fonts without seac. On allocation failure the lookup
falls back to the scan.
Tested by checking the table against get_glyph() on every lookup
across the full test suite (temporary assert), and the existing seac
tests (draw, extents, subset).
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-FH71HHTD.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
The class-based (Chain)Context closure and depend paths called
ClassDef::intersects_class() for every rule-set index / class, and each
call walks the whole ClassDef, so a subtable with many classes sharing
one large ClassDef was quadratic per closure visit (and thus in
subsetting).
Collect ClassDef::intersected_classes() of the glyph set into a set
once per visit and answer the per-class query from that set. All eight
call sites across ContextFormat2 and ChainContextFormat2 (closure and
depend) use the precomputed set; results are identical. Adds a fuzzer
regression font.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-ZCMLEQFJ.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
SingleSubstFormat2 already picks, per closure visit, between walking its
whole Coverage and iterating the (usually small) active glyph set. The
Multiple/Alternate/Ligature/ReverseChain closure and depend paths, the
format-1 (Chain)Context closure, and Coverage::intersect_set lacked that
choice, so a nested lookup visited many times over a small active set
re-walked a large Coverage every time, giving quadratic GSUB closure
(and thus subsetting) time.
Add the same get_population()-based fast path to those paths and to
CoverageFormat1/2::intersect_set. Output is byte-identical; only the
per-visit work is bounded.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-KNHDK379.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Rule::collect_second_glyphs() resolved the second input glyph of a
class-based contextual rule by scanning the whole input ClassDef once
per rule, so a RuleSet with many rules sharing one large ClassDef was
quadratic in collect_glyphs() (and thus in subsetting).
Collect the needed classes into a set and walk each ClassDef once for
all of them: add ClassDef::collect_classes(), and have
collect_second_glyphs() accumulate the classes and resolve them in a
single pass. The collected sets are identical; only the work is
reduced.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-5FCXNOQF.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Since 12b686dad, _hb_next_syllable() cuts syllables longer than
HB_MAX_SYLLABLE_LENGTH at whatever glyph index the walk reaches, and
nothing records that cut. The Indic shaper's initial and final
reordering (with GSUB features shortening the buffer in between) then
walk different pieces, the deferred pre-base-matra cluster merge never
happens, and hb_shape() returns non-monotone clusters at the default
MONOTONE_GRAPHEMES level for an over-long Indic syllable.
Add hb_syllabic_record_cut(), next to the other shared syllabic
helpers, and call it on each piece from the foreach_syllable() loops
that already exist where syllables are set up in all four syllabic
shapers (Indic, Khmer, Myanmar, USE), and once more in Indic initial
reordering since dotted-circle insertion can push a piece back over
the limit. Its inline fast path is a single length compare, so it
costs nothing unless a piece reaches the limit. Only a piece of
HB_MAX_SYLLABLE_LENGTH glyphs that is followed by more of the same
syllable takes the slow path: it cuts the rest of the syllable into
the pieces foreach_syllable() would make, gives every piece but the
last one of two serials that differ from the preceding syllable and
from the last piece (which keeps the ragel serial), so substituted
glyphs inherit it and all later walks see identical pieces, and
merges the whole oversized syllable into one cluster
(merge_clusters at monotone cluster levels, unsafe-to-break
otherwise) so the cut cannot become a line-break opportunity
mid-syllable. Serials of all other syllables are untouched, so
numbering and wraparound are exactly what the ragel machines
produce. The cut in _hb_next_syllable() stays as the backstop.
Behaviour change: syllables longer than HB_MAX_SYLLABLE_LENGTH become
a single cluster, where previously each piece got its own clusters.
A regression test with a 68-codepoint Devanagari input is added to
indic-syllable.tests; it fails (non-monotone clusters) on the
unpatched tree.
Tested: meson test (all pass). hb-shape on hi-words / a 175KB
Devanagari paragraph shows no measurable slowdown.
Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-W15T9EXZ.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Use hb_bit_vector_t and hb_min_max_t as Coverage sinks for the GDEF
mark-set cache. Preserve the exact-cache span limit and fall back to
the digest and table when allocation fails. Pack the repacker's
Dijkstra visited flags into one bit per vertex.
Fix singleton ranges and compute bit masks relative to the vector's
minimum. Avoid overflow when sizing inclusive ranges, expose allocation
failure, and add the Coverage sink methods needed by GDEF.
Add regression tests for biased ranges, singleton and allocation
boundaries, failing allocation, moves, and GDEF cache/table parity.
Testing: full meson test suite (303 passed, 1 skipped); bitvector tests
with AddressSanitizer and UndefinedBehaviorSanitizer; HB_TINY
amalgamation syntax check.
Assisted-by: OpenAI Codex
* [subset] Charge Coverage and ClassDef glyph walks to a work budget
Coverage::subset() expands a format 2 Coverage glyph by glyph, up to
numGlyphs, every time an offset to it is subset, and nothing bounded
that work. A 10-byte range Coverage referenced by 30,000 two-byte
offsets in a subtable listed 8 times costs 1.6e10 iterator steps,
while the sanitizer only bounds work by table bytes; a 60 KB font
keeps hb-subset busy ~50 s. GDEF's MarkGlyphSets reaches the same
walk with no feature or lookup needing to survive planning.
Give hb_subset_context_t a per-table work budget
(HB_BUDGET_SUBSET_TABLE, in the hb_budget_spend() idiom of
hb-limits.hh) with a check_ops() helper that fails the serializer once
exhausted, and charge Coverage::subset() its capped population before
the walk. Charging inside Coverage::subset() covers every caller
(ReverseChainSingleSubst, (Chain)ContextFormat3, GDEF MarkGlyphSets,
...) without touching them. The same unbounded per-reference pattern
in ClassDefFormat1_3 / ClassDefFormat2_4::subset() (the range or
glyphset walk and the glyph_filter count) is charged the same way.
A hostile table that exceeds the budget now fails the subset cleanly
(hb_subset_or_fail returns NULL) in a fraction of a second instead of
succeeding slowly; valid-font output is byte-identical and the
heaviest local table spends a small fraction of the budget.
test_subset_shared_coverage_budget builds the reverse-chaining GSUB in
memory and asserts 256 shared references subset while 2048 fail.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-LLIWV9UK.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* [subset] Charge layout glyph walks to the existing subset budget
Drop the separate HB_BUDGET_SUBSET_TABLE budget and the second
hb_subset_context_t field it needed; check_ops() now charges
budget_remaining (HB_BUDGET_SUBSET_GLYF, 1 << 28), the per-table
budget glyf instancing already uses. Both are per-table and shared
across buffer-size retries, and no table spends both.
The larger budget still bounds the attack (fails after 2^28 glyph
steps, ~3 s), so test_subset_shared_coverage_budget now expects the
failure at 8192 shared offsets instead of 2048.
Subsetting all glyphs with --layout-features='*' of Gulzar,
NotoSansKR-VF and GoogleSansFlex-VF keeps GSUB/GPOS/GDEF with output
byte-identical to before; the heaviest table (Gulzar GPOS) spends
~98K units, under 0.04% of the budget. Full meson test: 278 OK.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
hb_closure_context_t bounded GSUB glyph closure only by counting lookup
visits (HB_MAX_LOOKUP_VISIT_COUNT per round), and forgets which lookups
are done whenever the glyph set grows, so what one visit walks -- through
aliased offsets, many times the table size -- was charged to nothing. A
LigatureSubst with 9000 ligatureSet offsets aliased onto one 64-component
Ligature, re-walked after every one of 1700 Context triggers that each
add a glyph, makes hb-subset --unicodes='*' of an 86 KB font spend ~110 s
of CPU. A ReverseChain/ChainContextFormat3 with aliased backtrack
Coverages is a second way in.
Give the context an int64_t budget (HB_BUDGET_LAYOUT_CLOSURE records, in
the hb_budget_spend() idiom) spent as each closure() implementation walks
its arrays: dispatch() charges a visit its coverage record count;
ligature sets / ligatures / components, sequences, alternates,
single-subst intersections, rule sets and rules, context Coverages (via a
spend_coverages() helper) and the per-rule-set ClassDef walks are each
charged. Coverage and ClassDef gain a get_record_count() helper because
intersects()/intersect_set() are linear in records, not population. Once
the budget is spent, should_visit_lookup()/lookup_limit_exceeded() stop
the closure early, exactly as they do at the visit limit.
The budget lives in the context, so both public closure entry points (also
reached from hb_ot_shape_glyphs_closure() and the subset plan) are covered
with no API/ABI change. Both attack shapes drop to ~1 s and the control
font's closure output is byte-identical; the heaviest real font in the
corpora uses about 1% of the budget. A hostile GSUB now gets a truncated
closure, as one hitting the visit limit already does.
test_ot_layout_lookups_substitute_closure_budget builds the hostile table
in C and drives hb_ot_layout_lookups_substitute_closure() over it.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-J9K92HA9.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
While extracting GSUB dependencies, find_or_create_glyph_set() turned
every Coverage (format 3 contexts) and class (format 2 contexts) that
a contextual rule mentions into an hb_set_t holding every glyph id the
table lists, whether the face has it or not, with no budget on the
expansion or on the second copy kept in the returned graph. In
experimental builds, where the depend API and 24-bit Coverage formats
live together, a 6.5 KB font with 400 backtrack Coverage format 4
tables each covering [0, 0xFFFFFF] drives a build to ~2 GB.
Clip the cached sets to the face in find_or_create_glyph_set(), the
one place every context position goes through (the first input
Coverage and ReverseChainSingleSubst already clip this way), so the
copies kept in the graph shrink with them. For real fonts this
changes nothing; only broken fonts stop carrying glyph ids past the
face.
Clipping alone is not enough: the temporary is still expanded in full,
and the glyph count itself is cheap to inflate with a MAXP table. So
add a work budget for the whole build in the existing hb_budget_spend()
style: HB_BUDGET_DEPEND, budget_remaining on hb_depend_data_builder_t,
and charge_set(), which spends HB_BUDGET_4 per page while expanding a
temporary and HB_BUDGET_32 per page for every set the graph or context
keeps (new_set(), find_or_create_glyph_set(), find_or_create_recurse_set()).
Running out fails the build and hb_subset_depend_from_face_or_fail()
returns NULL, as it already does on allocation failure. A
get_page_count() accessor is added to the bit-set types so the charge
does not reach into set internals; no public API change.
The 400-position font now peaks at ~11 MB instead of ~2 GB, the 64 KB
/ 4000-position font is refused, and hb-subset-depend output is
unchanged for real fonts. Regression tests build the face with
hb_face_builder_create(): one asserts no glyph above the face count is
kept, the other that a 600-range face is refused.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-856K54QG.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
With edge keys hashed by fasthash32 over all fields, a font can no
longer steer its edges onto one slot, so probing is bounded by the
table's load factor; remove HB_DEPEND_MAX_EDGE_PROBES and its
per-probe charge.
HB_DEPEND_MAX_EDGES at 1<<22 was too close to real fonts: macOS's
DecoType Nastaleeq Urdu builds a graph of 1,198,826 edges, 3.5x below
it. Raise the cap to 1<<25, 28x above that. Other large fonts
measured: Noto Nastaliq 234,098; Hiragino Kaku Gothic 120,851; Gulzar
30,377; NotoSans-merged 29,968; NotoSansKR 7,797.
Reaching the raised cap takes 3.7 s and 1.7 GB, too much for a test,
so test_depend_edge_limit now only checks that a modest fan-out is
recorded in full. test_depend_gsub_high_bit_tags still covers the
hash.
Tested: meson test -C build-exp (experimental API, 296/296 OK).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The dependency-graph edge dedup table in
hb_depend_data_builder_t::add_edge() was indexed by the low bits of
an FNV-style hash whose chain of XORs and odd-constant multiplies
only ever carries upwards, so bit j of the result depended only on
bits 0..j of each field. A font controls feature tags (free 32-bit
values) and substitute glyph IDs, so it can pick values that differ
only in their high bits and pile every edge of a lookup onto one
slot. The open-addressed probe loop then does about N^2/2 work and
each resize_edge_slots() repeats it, so a 15 KB font with 680k
colliding edges spent ~10 min of CPU while an ordinary font with the
same edges takes 0.1 s.
hb_depend_edge_key_t::hash() now runs fasthash32() over all identity
fields, so every bit of every field reaches the index; equality and
the probe sequence are unchanged, so real fonts produce the same
graph at about two probes per edge. The now-unused
hb_depend_edge_t::hash() is removed.
A mixed hash alone is not enough: it is unkeyed, so colliding edges
can still be found offline (each one then costs font bytes instead
of coming free from a product of tags and pairs, but the walk stays
quadratic in them). Every occupied slot stepped over in add_edge()
and resize_edge_slots() is therefore charged to a new per-build
counter edge_probes_remaining, seeded from HB_DEPEND_MAX_EDGE_PROBES
(1<<26, in hb-limits.hh and overridable like the other HB_*_MAX_*
limits, following the HB_RASTER_MAX_DRAW_EDGES precedent); exceeding
it fails the build the way an allocation failure does, so
hb_subset_depend_from_face_or_fail() returns NULL. At about two
probes per edge the cap leaves more than 100x headroom over the
largest test font. Honest fonts are already bounded well below it
by the HB_DEPEND_MAX_EDGES cap added in the previous commit; the
probe budget is what stops a crafted all-colliding chain from doing
quadratic work before that cap is reached.
A regression test builds a GSUB with 2048 features whose tags differ
only in bits 20 and up and checks that all 2048 edges are recorded.
test-ot-depend, the api suite and the depend fuzzing/closure-parity
tests pass on the ASan experimental build, and the finding's
reproducer now builds the hostile font in well under a second.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-4XW1PGV5.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
hb_depend_data_builder_t::add_edge() stored one record per
(source, target, feature tag) with no bound. In GSUB a lookup
reached by F feature tags multiplies its N*M substitutions by F, so
a lookup whose covered glyphs all share one AlternateSet, selected
by many feature tags, produces N*M*F edges from a font that grows
only with N+M+F. A 5 KB font yields 33M edges and ~1.4 GB of
builder memory; COLRv0 overlapping layer slices reach the same sink
without any GSUB. The builder also kept walking after fail(), so an
allocation failure still cost the full N*M*F iterations.
This adds HB_DEPEND_MAX_EDGES (1<<22, about 4M, next to
HB_MAX_GRAPH_EDGE_COUNT in hb-limits.hh and overridable the same
way; 16x the largest graph in the test corpus) and enforces it in
add_edge(), the single choke point every table's extractor stores
through, so hb_subset_depend_from_face_or_fail() returns NULL
instead of building an unbounded graph. add_edge() and
add_gsub_lookup() return early once the builder has failed, and
GSUB_accelerator_t::depend()'s lookup loop stops as well, matching
the existing !successful checks in the context walkers, so a failed
build does bounded work.
A regression test builds the fan-out font in memory with
hb_face_builder (no binary test font needed) and checks that a
16x16x4 fan-out is recorded in full and that the 256x256x512 one is
refused. test-ot-depend and the api suite pass on the ASan
experimental build, and the finding's reproducer now returns NULL
in ~1 s.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-9IOHFFER.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
hb_ot_map_builder_t::add_lookups() paged through a feature's lookup
indices 32 at a time with hb_ot_layout_feature_with_variations_get_lookups(),
which re-resolves the feature on every call. Under a FeatureVariations
record that resolution is a linear search of the substitution records,
so a feature with many lookups and many variation records cost time
quadratic in the number of lookups, stalling hb_shape()'s plan build.
Add _hb_ot_layout_feature_with_variations_get_lookups(), which resolves
the feature once and returns its whole lookup-index array, and have
add_lookups() iterate that array directly. The public API is
unchanged; the resulting map is identical.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-M3XZD80O.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
create_from_item_var_data() deep-copied a region's axis hash map once
per entry of VarData.regionIndexes, so memory grew with
regionIndexCount x axisCount while the font pays only their sum, and
region indices may repeat freely. A 100 KB font (2000 axes, one region,
16000 copies of region index 0) made one hb-subset call allocate about
2 GB.
A region a VarData names again now adds its delta column to the tuple
it already owns, exactly what merge_tuple_variations() computes later,
so the instanced output is byte-identical. To also bound the sibling
case of many dataSets offsets each pointing at one VarData, the region
axes copied while converting one ItemVariationStore are summed across
its VarData subtables and capped at a new HB_VARSTORE_MAX_TUPLE_AXES
(1<<20); stores in the test fonts stay far below the
cap. Exceeding the cap fails instancing of that store, the same
path a failed allocation already takes.
Adds a unit test (test_repeated_region_index) covering the merge and
the cap.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-1CGIYCMY.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
* [gpos] Skip non-increasing Coverage indices in PairPosFormat1::intersects fast path
The slow-population fast path of PairPosFormat1_3::intersects() walked
the glyph set and indexed pairSet by the Coverage index of each glyph.
In a well-formed font those indices increase with glyph id, but a
broken Coverage can repeat an index, so one PairSet could be scanned
once per glyph, giving quadratic time.
Track the last index used and skip any that does not increase (and any
NOT_COVERED), following the existing "Broken table. Skip." convention,
so each PairSet is scanned at most once. Well-formed fonts are
unchanged. Adds a fuzzer regression font.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-6GSU471N.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* [subset] Skip PairPosFormat2 classes outside the class matrix when collecting variation indices
collect_pair_variation_indices() added every class returned by the two
ClassDefs to class1_set / class2_set without bounding them by
class1Count / class2Count. A ClassDef can map glyphs to classes far
outside the value matrix, so the collected sets could be enormous and
the subsequent nested loop quadratic, although apply() and the
serialization loops only ever touch classes inside the matrix.
Bound the collected classes by class1Count / class2Count, the same
bound the rest of the code already uses. Output is byte-identical;
adds a fuzzer regression font.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-C60AYSA3.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
The GDEF accelerator built its per-mark-set bit-page/digest cache by
materializing an hb_set_t for every mark glyph set and walking it glyph
by glyph. A mark set's Coverage can name an enormous glyph range in a
few bytes, and several sets can alias one all-glyphs Coverage, so a
256 KiB font with 65535 such sets cost about 1 GiB and billions of
iterations in the accelerator constructor.
Fill each entry directly from its Coverage table via
collect_coverage() into lightweight sinks (gid extents, then a biased
bit-page or a digest), so the work is proportional to the coverage
records the sanitizer already budgeted for, not to the glyphs they
span. Replace MarkGlyphSets::collect_coverage() with get_count() /
get_coverage() accessors. Answers are identical. Adds a fuzzer
regression font.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-OM3ZVHGK.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
GSUB_accelerator_t::depend() resolved each feature tag separately: it
ran hb_ot_layout_collect_features() once per tag and, for every tag,
walked the whole FeatureVariations table looking for substitute
features. Tables with many features and many FeatureVariations records
were therefore quadratic, work that sanitize() bounds only for a single
pass.
Query all tags at once, then visit each feature once and each
FeatureVariations substitute once (via new visit_substitutes()
helpers), mapping every lookup to the tag of the feature it belongs to.
The emitted dependency graphs are unchanged.
Adds a regression test building a FeatureVariations GSUB whose features
have no direct lookups.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-5C2QXX5N.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
context_closure_recurse_lookups() and context_depend_recurse_lookups()
already hold the rule's input sequence as a width-erased glyph_data_t
view, but for glyph-based rules (ContextFormat::SimpleContext) they
unwrapped the raw pointer and let intersected_glyph() index it as
HBUINT16. That is wrong for the HBUINT24 arrays of
SequenceContextFormat4 / ChainedSequenceContextFormat4: every input
position after the first was read at the wrong bytes, so the nested
lookup was closed over the wrong glyph and its real output never
entered the closure (other glyph ids keep glyphs that can never
appear). Only experimental / beyond-64k builds are affected.
Resolve the glyph via input[seqIndex - 1] for every format and make
intersected_glyph() a plain insert of the value, mirroring its sibling
intersects_glyph() which already takes the resolved glyph and ignores
data. These two call sites were the only users of the
pointer-plus-index convention; 16-bit formats are unchanged, and there
is no API/ABI change.
Adds a regression test under HB_NO_BEYOND_64K: a SequenceContextFormat4
rule "1 2" invoking a SingleSubst 2->3 must close {1, 2} to {1, 2, 3}.
It fails on the unpatched library and passes with the fix.
Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-IU58QGNT.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Passes 2 and 3 of CFF::specialize_commands() called
hb_vector_t::remove_ordered() once per merged command, and each call
shifts every command behind it, so a charstring of A mergeable line
segments followed by T unmergeable commands cost A*T element moves,
bounded only by HB_CFF_MAX_OPS: 32 s of CPU for one glyph of a 1.6 KB
font with --downgrade-cff2, paid again on every serializer-buffer
retry.
Replace both loops with one helper, combine_commands(), that walks
backwards exactly as before (each command absorbs its already-merged
successor chunk while the predicate allows, matching fontTools order)
but keeps finished commands packed at the tail and compacts the vector
once at the end, so the work is linear. The two merge conditions
(operator pair, args-length parity, combined args < maxstack) become
the predicates verbatim and the merge order is unchanged.
Adds test_specialized_many_commands() to src/test-cff.cc (100,000 unit
rlineto followed by 100,000 empty hhcurveto must come back as 2,128
line commands plus the untouched hhcurveto commands); it takes 0.08 s
with this change versus tens of seconds before.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-7TEMF5SE.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>