ed1787d
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
ed1787d
From: Zhang Boyang <zhangboyang.id@gmail.com>
ed1787d
Date: Wed, 3 Aug 2022 19:45:33 +0800
ed1787d
Subject: [PATCH] font: Reject glyphs exceeds font->max_glyph_width or
ed1787d
 font->max_glyph_height
ed1787d
ed1787d
Check glyph's width and height against limits specified in font's
ed1787d
metadata. Reject the glyph (and font) if such limits are exceeded.
ed1787d
ed1787d
Signed-off-by: Zhang Boyang <zhangboyang.id@gmail.com>
ed1787d
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
ed1787d
(cherry picked from commit 5760fcfd466cc757540ea0d591bad6a08caeaa16)
ed1787d
---
ed1787d
 grub-core/font/font.c | 4 +++-
ed1787d
 1 file changed, 3 insertions(+), 1 deletion(-)
ed1787d
ed1787d
diff --git a/grub-core/font/font.c b/grub-core/font/font.c
ed1787d
index d09bb38d89..2f09a4a55b 100644
ed1787d
--- a/grub-core/font/font.c
ed1787d
+++ b/grub-core/font/font.c
ed1787d
@@ -760,7 +760,9 @@ grub_font_get_glyph_internal (grub_font_t font, grub_uint32_t code)
ed1787d
 	  || read_be_uint16 (font->file, &height) != 0
ed1787d
 	  || read_be_int16 (font->file, &xoff) != 0
ed1787d
 	  || read_be_int16 (font->file, &yoff) != 0
ed1787d
-	  || read_be_int16 (font->file, &dwidth) != 0)
ed1787d
+	  || read_be_int16 (font->file, &dwidth) != 0
ed1787d
+	  || width > font->max_char_width
ed1787d
+	  || height > font->max_char_height)
ed1787d
 	{
ed1787d
 	  remove_font (font);
ed1787d
 	  return 0;