From 9194a3b24d9298c91601c2a0b1fd533b4db77c68 Mon Sep 17 00:00:00 2001 From: jdgleaver Date: Tue, 24 Mar 2020 16:14:53 +0000 Subject: [PATCH] (Menu) Prevent font-related segfaults when using extremely small scales/window sizes --- gfx/gfx_display.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gfx/gfx_display.c b/gfx/gfx_display.c index 36b9d32b5d..380e154ea8 100644 --- a/gfx/gfx_display.c +++ b/gfx/gfx_display.c @@ -713,13 +713,19 @@ font_data_t *gfx_display_font_file( char* fontpath, float menu_font_size, bool is_threaded) { font_data_t *font_data = NULL; + float font_size = menu_font_size; if (!dispctx) return NULL; + /* Font size must be at least 2, or font_init_first() + * will generate a heap-buffer-overflow when using + * many font drivers */ + font_size = (font_size > 2.0f) ? font_size : 2.0f; + if (!dispctx->font_init_first((void**)&font_data, video_driver_get_ptr(false), - fontpath, menu_font_size, is_threaded)) + fontpath, font_size, is_threaded)) return NULL; return font_data;