mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-25 08:51:07 +01:00
avar::_subset_avar2() builds the offset-compensation knots and runs _avar2_estimate_offset_error() twice per narrowed axis; every breakpoint and every estimator sample is looked up in the old segment map, the instantiated mapping and the knots by linear search, so the cost is quadratic in the axis's avar breakpoints and nothing bounded it (42 s of CPU for a 131 KB font, re-run on each serializer out-of-room retry). Add HB_BUDGET_SUBSET_TABLE to hb-limits.hh (same hb_budget_spend() idiom as the rendering budgets) and, right before the knot loop and the estimator, charge (256 + breakpoints) * 8 * breakpoints from a budget shared by all axes of the table. Charging at the point where the quadratic work starts covers the O(n^2) knot-collection loop and its map_float() calls too. On exhaustion the table fails through c->serializer->check_success(), so the whole subset fails (hb_subset_or_fail() returns NULL) rather than avar being silently dropped from an avar2-instanced font. The budget is 1<<30: a 5,000-breakpoint axis narrowed to -900:900 is still admitted (0.6 s), while 16,385 and 32,769 breakpoints are rejected in 0.01 s (the 42 s DoS). A reviewer may tighten it; real avar maps have a handful of breakpoints, far below the cap. Adds test_avar2_restrict_many_breakpoints to test/api/test-subset-avar2.c. This caps the cost; it does not remove the quadratic algorithm. Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-CWJXX1BL. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>