From f2d62aaa7d07898780868bac560d27870dfa8e01 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 4 Sep 2026 14:14:49 -0600 Subject: [PATCH] Fix an int overflow Fixes https://oss-fuzz.com/testcase-detail/4709124282318848 --- src/hb-ot-font.cc | 3 ++- test/api/test-ot-face.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc index d91ee7af2..604a75875 100644 --- a/src/hb-ot-font.cc +++ b/src/hb-ot-font.cc @@ -782,7 +782,8 @@ hb_ot_get_glyph_v_origins (hb_font_t *font, { hb_glyph_extents_t extents = {0}; if (likely (font->get_glyph_extents (*first_glyph, &extents))) - origin = extents.y_bearing + ((font_advance - -extents.height) >> 1); + origin = hb_clamp_to ((int64_t) extents.y_bearing + + (((int64_t) font_advance + extents.height) >> 1)); else origin = font_extents.ascender; diff --git a/test/api/test-ot-face.c b/test/api/test-ot-face.c index 37c2be127..30e474543 100644 --- a/test/api/test-ot-face.c +++ b/test/api/test-ot-face.c @@ -216,6 +216,37 @@ test_ot_var_axis_on_zero_named_instance (void) } #ifndef HB_NO_VERTICAL +static void +test_ot_font_v_origin_extents_overflow (void) +{ + static const char data[] = { + 0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x43, 0x4f, 0x4c, 0x52, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x09, + 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x10, 0x00, 0x00, + 0x00, 0x22, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, + 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x11, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x0c, + 0x00, 0x00, 0x17, 0x00, 0x00, 0x02, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + (char) 0xff, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x1d, 0x00, + 0x00, 0x04, 0x20, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x04, 0x03, 0x20, + 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00 + }; + hb_blob_t *blob = hb_blob_create (data, sizeof (data), HB_MEMORY_MODE_READONLY, + NULL, NULL); + hb_face_t *face = hb_face_create (blob, 0); + hb_font_t *font = hb_font_create (face); + hb_position_t x, y; + + hb_font_set_scale (font, 12, 12); + g_assert_true (hb_font_get_glyph_v_origin (font, 0, &x, &y)); + g_assert_cmpint (y, ==, -1073741719); + + hb_font_destroy (font); + hb_face_destroy (face); + hb_blob_destroy (blob); +} + static void test_ot_font_v_origin_cache_invalidated_by_scale (void) { @@ -247,6 +278,7 @@ main (int argc, char **argv) hb_test_add (test_ot_face_empty); hb_test_add (test_ot_var_axis_on_zero_named_instance); #ifndef HB_NO_VERTICAL + hb_test_add (test_ot_font_v_origin_extents_overflow); hb_test_add (test_ot_font_v_origin_cache_invalidated_by_scale); #endif