From 873dbc1e32483cffa1f5d92cfcc4fcbf7104e0d3 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 23 Sep 2026 10:18:44 -0600 Subject: [PATCH] [font] Fix signed integer overflow in scale_glyph_extents (#6275) hb_font_t::scale_glyph_extents() computed extents->x_bearing + extents->width (and the y equivalent) as a plain hb_position_t (int32_t) addition before scaling to float. glyf's contour_bounds_t::get_extents() clamps x_bearing and width independently via hb_clamp_to(), so each can reach INT32_MIN/INT32_MAX on its own for a malformed/adversarial glyf outline. Their sum can then overflow a 32-bit int, which is undefined behavior and was flagged by UBSan. Fix by doing the addition in float, after each term is already scaled, instead of adding the raw hb_position_t values first. Reproduced with the OSS-Fuzz hb-raster-fuzzer testcase at https://oss-fuzz.com/testcase?key=5782717883809792, built locally with -Db_sanitize=undefined: ../src/hb-font.hh:205:28: runtime error: signed integer overflow: 32 + 2147483647 cannot be represented in type 'int' Confirmed the UBSan report no longer triggers on that testcase after the fix, and `meson test -C build` passes in full (278/278, 1 pre-existing skip). Co-authored-by: Claude Sonnet 5 --- src/hb-font.hh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hb-font.hh b/src/hb-font.hh index 30b2d27e2..bc75fe1f9 100644 --- a/src/hb-font.hh +++ b/src/hb-font.hh @@ -202,8 +202,8 @@ struct hb_font_t { float x1 = em_fscale_x (extents->x_bearing); float y1 = em_fscale_y (extents->y_bearing); - float x2 = em_fscale_x (extents->x_bearing + extents->width); - float y2 = em_fscale_y (extents->y_bearing + extents->height); + float x2 = x1 + em_fscale_x (extents->width); + float y2 = y1 + em_fscale_y (extents->height); extents->x_bearing = floorf (x1); extents->y_bearing = floorf (y1);