mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-21 15:01:01 +01:00
COLR::depend() walked the COLRv1 paint graph from scratch for every BaseGlyphPaintRecord (clearing the visited set each time) with no total work limit, so N base glyphs sharing one paint graph cost N times the graph, quadratic in table size (204 s for a 200 KB font); the COLRv0 loop has the same base-glyphs x layers shape. The API is built only with -Dexperimental_api=true. hb_colrv1_depend_context_t, which already owns the per-walk depth and visited-set guards, now also carries max_ops sized like the sanitizer's (table length x HB_SANITIZE_MAX_OPS_FACTOR, clamped to the MIN/MAX), charged one unit per Paint::dispatch(), per COLRv0 layer record, and per PaintColrLayers layer run. Charging the layer run in dependv1() matters because a layer resolving to the null or an unknown-format paint is dropped by Paint::dispatch() before it reaches the context, so without it a PaintColrLayers could still spin its 255-iteration loop uncharged. Exhausting the budget calls depend_data->fail() (the existing error idiom) so hb_subset_depend_from_face_or_fail() returns NULL rather than a graph with silently missing edges, and the base-glyph loop stops once the builder has failed. The reproducer font is now rejected in a fraction of a second; the control still succeeds, and legitimate fonts keep 64 ops per table byte of headroom. Adds test_depend_colr_budget. Follow-up to #6113. Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-TO8ND880. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>