From f7ce715596c9a220b4df25d10f17ac7635e9964f Mon Sep 17 00:00:00 2001 From: Vincent Rabaud Date: Mon, 20 Feb 2023 23:52:22 +0100 Subject: [PATCH] Fix signed integer overflow. The overflow happens for INT_MAX so the code just needs to be moved down. --- modules/imgproc/src/stb_truetype.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/imgproc/src/stb_truetype.cpp b/modules/imgproc/src/stb_truetype.cpp index edbf72d104..5a481aa1ce 100644 --- a/modules/imgproc/src/stb_truetype.cpp +++ b/modules/imgproc/src/stb_truetype.cpp @@ -3530,11 +3530,14 @@ STBTT_DEF unsigned char* stbtt_GetGlyphBitmapSubpixelRealloc(const stbtt_fontinf iy1 = STBTT_max(iy1, y); } } - int w = ix1 - ix0 + 1, h = iy1 - iy0 + 1; + int w, h; if (ix0 == INT_MAX || iy0 == INT_MAX || ix1 == INT_MIN || iy1 == INT_MIN ) { w = h = 0; ix0 = pad_x; iy0 = pad_y; + } else { + w = ix1 - ix0 + 1; + h = iy1 - iy0 + 1; } if (width) *width = w; if (height) *height = h;