Files
harfbuzz/test/api
Behdad EsfahbodandClaude Opus 4.8 a6beb11493 [subset/cff] Bound parsed subrs and share one charstring budget per pass (#6636)
* [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>
2026-11-11 16:58:48 -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