While extracting GSUB dependencies, find_or_create_glyph_set() turned
every Coverage (format 3 contexts) and class (format 2 contexts) that
a contextual rule mentions into an hb_set_t holding every glyph id the
table lists, whether the face has it or not, with no budget on the
expansion or on the second copy kept in the returned graph. In
experimental builds, where the depend API and 24-bit Coverage formats
live together, a 6.5 KB font with 400 backtrack Coverage format 4
tables each covering [0, 0xFFFFFF] drives a build to ~2 GB.
Clip the cached sets to the face in find_or_create_glyph_set(), the
one place every context position goes through (the first input
Coverage and ReverseChainSingleSubst already clip this way), so the
copies kept in the graph shrink with them. For real fonts this
changes nothing; only broken fonts stop carrying glyph ids past the
face.
Clipping alone is not enough: the temporary is still expanded in full,
and the glyph count itself is cheap to inflate with a MAXP table. So
add a work budget for the whole build in the existing hb_budget_spend()
style: HB_BUDGET_DEPEND, budget_remaining on hb_depend_data_builder_t,
and charge_set(), which spends HB_BUDGET_4 per page while expanding a
temporary and HB_BUDGET_32 per page for every set the graph or context
keeps (new_set(), find_or_create_glyph_set(), find_or_create_recurse_set()).
Running out fails the build and hb_subset_depend_from_face_or_fail()
returns NULL, as it already does on allocation failure. A
get_page_count() accessor is added to the bit-set types so the charge
does not reach into set internals; no public API change.
The 400-position font now peaks at ~11 MB instead of ~2 GB, the 64 KB
/ 4000-position font is refused, and hb-subset-depend output is
unchanged for real fonts. Regression tests build the face with
hb_face_builder_create(): one asserts no glyph above the face count is
kept, the other that a 600-range face is refused.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-856K54QG.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>