Files
harfbuzz/test/api
Behdad EsfahbodandClaude Opus 5.5 a1134fa3ea [subset] Budget kept glyf points and the avar2 reachable-range computation (#6640)
* [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>
2026-11-11 17:03:53 -06:00
..
2025-04-06 18:08:50 -06:00
2026-07-30 19:02:25 -06:00
2026-07-31 04:31:26 +03:00
2025-04-05 22:37:10 -06:00
2020-01-15 13:36:01 -08:00
2025-06-08 13:43:27 +03:00