diff options
author | Oneric <oneric@oneric.stub> | 2022-07-12 22:24:26 +0200 |
---|---|---|
committer | Oneric <oneric@oneric.stub> | 2022-07-13 01:08:01 +0200 |
commit | 4e636c8d38368e67d4649a728f0100d230c473d4 (patch) | |
tree | 00bbe46c44b12fedf4f09b898e8491860f9f7b9a | |
parent | 7bc0c45dd58de6afa1800f8e8a94285e7535d68d (diff) | |
download | libass-4e636c8d38368e67d4649a728f0100d230c473d4.tar.bz2 libass-4e636c8d38368e67d4649a728f0100d230c473d4.tar.xz |
render: fix div by zero in fix_glyph_scaling
While with floating point division by zero itself is not
undefined behaviour, it will lead to UB later on and can
lead to incorrect rendering.
E.g. on x86 with hinting enabled, non-zero font size and \fscy0,
the NAN to int conversion didn't crash, but the glyph was
incorrectly being displayed with zero width instead of normal width
but zero height.
Issue originally found by 顾涛涛 (Taotao Gu).
Fixes: https://github.com/libass/libass/issues/630
-rw-r--r-- | libass/ass_render.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/libass/ass_render.c b/libass/ass_render.c index a8be31b..bbc8070 100644 --- a/libass/ass_render.c +++ b/libass/ass_render.c @@ -1855,6 +1855,10 @@ fix_glyph_scaling(ASS_Renderer *priv, GlyphInfo *glyph) // to freetype. Normalize scale_y to 1.0. ft_size = glyph->scale_y * glyph->font_size; } + + if (!ft_size || !glyph->font_size) + return; + double mul = glyph->font_size / ft_size; glyph->scale_fix = 1 / mul; glyph->scale_x *= mul; |