Fix an int overflow

Fixes https://oss-fuzz.com/testcase-detail/4709124282318848
This commit is contained in:
Behdad Esfahbod committed 2026-09-04 14:14:49 -06:00
1 parent 724ef405f3
commit f2d62aaa7d
2 files changed
+34 -1

No files matched your search

+2 -1
View File
@@ -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<hb_position_t> ((int64_t) extents.y_bearing +
(((int64_t) font_advance + extents.height) >> 1));
else
origin = font_extents.ascender;
+32
View File
@@ -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