From 55c41f219f539464335c16dc8392787fd0ac1b46 Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Thu, 6 Aug 2020 23:37:43 +0430 Subject: [PATCH] [glyf] Clamp advance value result Fixes a sanitizer complain https://circleci.com/gh/harfbuzz/harfbuzz/150247 revealed by 02d1ec1 --- src/hb-ot-glyf-table.hh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/hb-ot-glyf-table.hh b/src/hb-ot-glyf-table.hh index dc15ff1d6..f4691622a 100644 --- a/src/hb-ot-glyf-table.hh +++ b/src/hb-ot-glyf-table.hh @@ -946,7 +946,7 @@ struct glyf contour_point_t *get_phantoms_sink () { return phantoms; } }; - unsigned int + unsigned get_advance_var (hb_font_t *font, hb_codepoint_t gid, bool is_vertical) const { bool success = false; @@ -960,9 +960,10 @@ struct glyf ? face->table.vmtx->get_advance (gid) : face->table.hmtx->get_advance (gid); - return is_vertical - ? roundf (phantoms[PHANTOM_TOP].y - phantoms[PHANTOM_BOTTOM].y) - : roundf (phantoms[PHANTOM_RIGHT].x - phantoms[PHANTOM_LEFT].x); + float result = is_vertical + ? phantoms[PHANTOM_TOP].y - phantoms[PHANTOM_BOTTOM].y + : phantoms[PHANTOM_RIGHT].x - phantoms[PHANTOM_LEFT].x; + return hb_clamp (roundf (result), 0.f, (float) UINT_MAX / 2); } int get_side_bearing_var (hb_font_t *font, hb_codepoint_t gid, bool is_vertical) const