Files
harfbuzz/src
Behdad EsfahbodandClaude Opus 4.8 7b30ba988d [instancer] Budget VarStore rebuild, tuple splitting and per-point tuple expansion (#6639)
* [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>
2026-11-11 17:02:43 -06:00
..
2026-08-12 18:27:23 -06:00
2024-03-30 02:20:21 +02:00
2026-07-31 04:31:26 +03:00
2026-07-31 04:31:26 +03:00
…
2025-10-17 15:23:05 -06:00
…
2026-11-04 23:03:36 +02:00
2026-09-21 00:41:07 +03:00
2026-09-21 00:41:07 +03:00
2026-09-21 00:41:07 +03:00
2026-10-16 00:19:21 +03:00
2025-03-24 00:33:53 +02:00
2025-09-15 23:56:25 -06:00
…
…
2026-04-20 05:10:48 +02:00
2026-04-20 05:10:48 +02:00
2024-10-27 16:14:53 -07:00
…
2026-10-22 17:05:31 +03:00
2023-08-25 07:51:05 -06:00
2023-06-03 14:56:47 -06:00
2025-04-08 01:58:10 -06:00
2025-08-07 22:38:58 -06:00
2026-07-31 17:49:40 +03:00
2026-07-31 17:49:40 +03:00
2025-08-07 22:38:58 -06:00
2026-03-19 00:45:24 +02:00
2024-04-16 17:10:09 -06:00
2026-07-31 04:31:26 +03:00
2026-09-21 00:41:07 +03:00
2026-04-18 10:58:44 -06:00
2026-09-21 00:41:07 +03:00
2026-08-26 22:27:05 +03:00
2026-08-19 16:00:05 -06:00
2025-07-23 21:39:23 +03:00
2024-08-23 08:58:50 -06:00
2026-07-31 17:49:40 +03:00
2025-01-11 18:13:18 +02:00
2026-07-30 12:00:47 -06:00
2026-10-01 16:27:20 -06:00
…
2023-04-27 00:48:00 +02:00
2026-04-20 01:29:49 +02:00
2026-11-04 23:03:36 +02:00
2025-03-07 18:19:29 -07:00
2026-08-12 18:33:09 -06:00
…
2026-06-05 13:44:29 +02:00
…