mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-24 16:31:14 +01:00
The COLRv1 paint walk bounds paint-table visits (HB_MAX_NESTING_LEVEL, HB_MAX_GRAPH_EDGE_COUNT) but handed out ColorLine stops uncharged, so a single 65535-stop ColorLine shared across up to 16384 gradient edges could deliver ~10^9 stops from one hb_font_paint_glyph() call, keeping the rendering thread busy for minutes per glyph in every backend. Give hb_paint_context_t the session's live budget via funcs->get_budget_remaining_ptr(), with the same local HB_BUDGET_GLYPH fallback hb_draw_session_t uses, charge HB_BUDGET_16 per stop delivered in ColorLine::get_color_stops() (the one place every consumer fetches stops, so vector, raster, cairo and client paint functions are all covered), and make recurse() skip further paints once the budget is negative, as it already does for an oversized graph. The backend's one budget is only spent, never re-armed, so this does not reintroduce the cross-subsystem budget multiplication removed in #6147. hb-ft-colr.hh has the same shape and gets the identical change. With the default 2^24 budget about a million stops per session are delivered before the rest of the walk is skipped best-effort. A separate quadratic cost inside cairo's own gradient pattern building is not addressed here. Adds a regression test that fails without the fix. Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-F2NWHRVP. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>