[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 <noreply@anthropic.com>
This commit is contained in:
Behdad EsfahbodandClaude Opus 4.8 committed 2026-10-31 22:00:12 -06:00
1 parent 820032a852
commit 7b7e4ef3d1
1 file changed
+7 -1
+7 -1
View File
@@ -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 ();