Files
harfbuzz/test
Behdad EsfahbodandClaude Opus 4.8 339aa688fa [layout] Charge each GSUB/GPOS lookup pass to max_ops
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>
2026-11-11 12:43:10 -06:00
..