From 7b7e4ef3d12ec00bddaf7f38a084842bfc57b255 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 31 Oct 2026 01:51:40 -0600 Subject: [PATCH] [glyf] Guard phantom-shift subarray against OOM underflow In phantom_only mode the horizontal shift walks all_points.sub_array (all_points.length - PHANTOM_COUNT). If the preceding extend (phantoms) failed under memory pressure, all_points can be shorter than PHANTOM_COUNT, so the subtraction wraps and the code forms an out-of-range pointer (UB flagged by UBSan under the failing-malloc fuzzers) even though sub_array clamps the count to 0 and the in-error result is discarded. Fall back to offset 0 when the phantoms are not present. Co-Authored-By: Claude Opus 4.8 --- src/OT/glyf/Glyph.hh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/OT/glyf/Glyph.hh b/src/OT/glyf/Glyph.hh index c104a930b..71c4a2a0f 100644 --- a/src/OT/glyf/Glyph.hh +++ b/src/OT/glyf/Glyph.hh @@ -588,8 +588,14 @@ struct Glyph * Shift points horizontally by the updated left side bearing */ if (shift) - for (auto &point : all_points.as_array ().sub_array (phantom_only ? all_points.length - PHANTOM_COUNT : 0)) + { + /* Guard the subtraction: a failed phantom extend() under OOM can + * leave all_points shorter than PHANTOM_COUNT. */ + unsigned start = phantom_only && all_points.length >= PHANTOM_COUNT + ? all_points.length - PHANTOM_COUNT : 0; + for (auto &point : all_points.as_array ().sub_array (start)) point.x -= shift; + } } return !all_points.in_error ();