mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-19 05:51:05 +01:00
* [subset] Charge Coverage and ClassDef glyph walks to a work budget Coverage::subset() expands a format 2 Coverage glyph by glyph, up to numGlyphs, every time an offset to it is subset, and nothing bounded that work. A 10-byte range Coverage referenced by 30,000 two-byte offsets in a subtable listed 8 times costs 1.6e10 iterator steps, while the sanitizer only bounds work by table bytes; a 60 KB font keeps hb-subset busy ~50 s. GDEF's MarkGlyphSets reaches the same walk with no feature or lookup needing to survive planning. Give hb_subset_context_t a per-table work budget (HB_BUDGET_SUBSET_TABLE, in the hb_budget_spend() idiom of hb-limits.hh) with a check_ops() helper that fails the serializer once exhausted, and charge Coverage::subset() its capped population before the walk. Charging inside Coverage::subset() covers every caller (ReverseChainSingleSubst, (Chain)ContextFormat3, GDEF MarkGlyphSets, ...) without touching them. The same unbounded per-reference pattern in ClassDefFormat1_3 / ClassDefFormat2_4::subset() (the range or glyphset walk and the glyph_filter count) is charged the same way. A hostile table that exceeds the budget now fails the subset cleanly (hb_subset_or_fail returns NULL) in a fraction of a second instead of succeeding slowly; valid-font output is byte-identical and the heaviest local table spends a small fraction of the budget. test_subset_shared_coverage_budget builds the reverse-chaining GSUB in memory and asserts 256 shared references subset while 2048 fail. Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-LLIWV9UK. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * [subset] Charge layout glyph walks to the existing subset budget Drop the separate HB_BUDGET_SUBSET_TABLE budget and the second hb_subset_context_t field it needed; check_ops() now charges budget_remaining (HB_BUDGET_SUBSET_GLYF, 1 << 28), the per-table budget glyf instancing already uses. Both are per-table and shared across buffer-size retries, and no table spends both. The larger budget still bounds the attack (fails after 2^28 glyph steps, ~3 s), so test_subset_shared_coverage_budget now expects the failure at 8192 shared offsets instead of 2048. Subsetting all glyphs with --layout-features='*' of Gulzar, NotoSansKR-VF and GoogleSansFlex-VF keeps GSUB/GPOS/GDEF with output byte-identical to before; the heaviest table (Gulzar GPOS) spends ~98K units, under 0.04% of the budget. Full meson test: 278 OK. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>