mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-19 14:01:10 +01:00
hb-limits.hh states that a session which drives another subsystem carries one cumulative budget, initialized once per top-level entry and only ever decremented. When instancing, glyf::subset() drives Glyph::get_points() once per retained glyph to recompute bounds and metrics, but passed no budget, so each glyph restarted from a fresh HB_BUDGET_GLYPH and the table as a whole was bounded only by 2^24 times the glyph count. A 59 KB font of 2,000 nested composites over a shared 64-level chain made one hb_subset_or_fail() instancing call spend 34 s of CPU, since the shared chain was re-walked (and re-charged only against a fresh budget) for every top-level glyph. Add HB_BUDGET_SUBSET_GLYF and keep the live counter in hb_subset_context_t, which is constructed once and reused across the ran-out-of-room retries in _hb_subset_table_try(), so a retry does not reset it. Thread it through _populate_subset_glyphs() and both compile_bytes_with_deltas() into get_points(). Exhausting it fails get_points(), which the existing loop already turns into dropping glyf from the instance -- the same outcome as any other glyph-load failure there. This is one cumulative counter, not a per-glyph budget multiplied by the glyph count. It is sized at 2^28; measured consumption of the largest glyf variable font under test/ (MPLUS1-Variable) is ~1.2M units, about 220x below the cap, and even a font at the 65,535-glyph maximum stays well under, so real fonts instance unchanged (outputs byte-identical). One behaviour change: a single glyph is now bounded by what is left of the table budget rather than by HB_BUDGET_GLYPH, so one glyph may spend between 2^24 and 2^28 units; the session total is still bounded. Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-5BY15VDS. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>