From cd05d187c893ad0bcf754393a865c417d5cff36d Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 1 Jun 2022 07:27:30 -0600 Subject: [PATCH] [font] Fix undefined-behavior when scales are negative Fixes https://github.com/harfbuzz/harfbuzz/issues/3555 --- src/hb-font.hh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/hb-font.hh b/src/hb-font.hh index 952beabe1..abc8bb3ba 100644 --- a/src/hb-font.hh +++ b/src/hb-font.hh @@ -631,8 +631,10 @@ struct hb_font_t void mults_changed () { signed upem = face->get_upem (); - x_mult = ((int64_t) x_scale << 16) / upem; - y_mult = ((int64_t) y_scale << 16) / upem; + bool x_neg = x_scale < 0; + x_mult = (x_neg ? -((int64_t) -x_scale << 16) : ((int64_t) x_scale << 16)) / upem; + bool y_neg = y_scale < 0; + y_mult = (y_neg ? -((int64_t) -y_scale << 16) : ((int64_t) y_scale << 16)) / upem; slant_xy = y_scale ? slant * x_scale / y_scale : 0.f; }