From 220ef2ca34c8e71ed374a41e1ee4c9030b869cc0 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 30 Oct 2026 15:13:04 -0600 Subject: [PATCH] [glyf] Restore scratch length when gvar fails in get_points; clear comp_points at entry Glyph::get_points() uses scratch.comp_points as a stack shared by all recursion levels: it appends one point per component plus four phantoms, and every exit restores points.length to old_length -- except the exit taken when gvar->apply_deltas_to_points() returns false (for example on a tuple whose variationDataSize overruns its data). Because the hb_glyf_scratch_t is cached on the glyf (and VARC) accelerator for the life of the face, every failed depth-0 load grows the vector permanently, until it reaches its allocation ceiling; a VARC font can drive hundreds of thousands of such failing leaf loads within one glyph budget, leaving tens of megabytes behind per extents or draw call. Balance the missing exit the way every sibling exit (and #6410) already does. Also clear comp_points next to the existing all_points.clear() at the depth-0 entry in glyf_accelerator_t::get_points(), the only entry into the cached scratch (the subsetter's call uses a local scratch), so the cached vector can never carry stale points across loads even if a future exit forgets the discipline. No behaviour change for well-formed fonts: the resize only runs on the failure path and comp_points is empty at entry when exits are balanced. Adds a minimized VARC+gvar font to test/fuzzing/fonts exercising the failing path through the shape/draw/raster/vector/subset fuzzers. Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-NM4GCMBX. Co-Authored-By: Claude Opus 4.8 --- src/OT/glyf/Glyph.hh | 3 +++ src/OT/glyf/glyf.hh | 3 +++ ...f-gvar-truncated-tuple-varc-scratch-growth.ttf | Bin 0 -> 472 bytes 3 files changed, 6 insertions(+) create mode 100644 test/fuzzing/fonts/glyf-gvar-truncated-tuple-varc-scratch-growth.ttf diff --git a/src/OT/glyf/Glyph.hh b/src/OT/glyf/Glyph.hh index 57f4d890c..56f4d1f1c 100644 --- a/src/OT/glyf/Glyph.hh +++ b/src/OT/glyf/Glyph.hh @@ -423,7 +423,10 @@ struct Glyph gvar_cache, phantom_only && type == SIMPLE, budget)) + { + points.resize (old_length); return false; + } } #endif diff --git a/src/OT/glyf/glyf.hh b/src/OT/glyf/glyf.hh index 5b22b931a..3a9916150 100644 --- a/src/OT/glyf/glyf.hh +++ b/src/OT/glyf/glyf.hh @@ -297,6 +297,9 @@ struct glyf_accelerator_t auto &all_points = scratch.all_points; all_points.clear (); + /* The scratch is cached across loads; don't let a failed one leave + * component points behind. */ + scratch.comp_points.clear (); bool phantom_only = !consumer.is_consuming_contour_points (); if (unlikely (!glyph_for_gid (gid).get_points (font, *this, all_points, scratch, nullptr, nullptr, nullptr, true, true, phantom_only, coords, gvar_cache, 0, nullptr, budget))) diff --git a/test/fuzzing/fonts/glyf-gvar-truncated-tuple-varc-scratch-growth.ttf b/test/fuzzing/fonts/glyf-gvar-truncated-tuple-varc-scratch-growth.ttf new file mode 100644 index 0000000000000000000000000000000000000000..05e15c7b06190e3b5369ba0a8d176d5039c2abc3 GIT binary patch literal 472 zcmZQzWME)m2Vx)ya}08Zuo!B9^pfPnIq#ttAI9Lz5m7@C{Gs-f!Q`E9-eeG3%F2{=H0 M#SQ`(fOazg0JO^-J^%m! literal 0 HcmV?d00001