From 1ca796b3a323527584f671ded7e67d44c7e926ce Mon Sep 17 00:00:00 2001 From: piepie62 Date: Thu, 23 Apr 2020 22:12:31 -0400 Subject: [PATCH] Add invalid glyph index protection --- libctru/source/font.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libctru/source/font.c b/libctru/source/font.c index 1272cdd..81c61c8 100644 --- a/libctru/source/font.c +++ b/libctru/source/font.c @@ -48,7 +48,7 @@ int fontGlyphIndexFromCodePoint(CFNT_s* font, u32 codePoint) font = g_sharedFont; if (!font) return -1; - int ret = font->finf.alterCharIndex; + int ret = 0xFFFF; if (codePoint < 0x10000) { for (CMAP_s* cmap = font->finf.cmap; cmap; cmap = cmap->next) @@ -79,6 +79,13 @@ int fontGlyphIndexFromCodePoint(CFNT_s* font, u32 codePoint) } } } + if (ret == 0xFFFF) // Bogus CMAP entry. Probably exist to save space by using TABLE mappings? + { + if (font->finf.alterCharIndex == 0xFFFF) + return -1; + else + return font->finf.alterCharIndex; + } return ret; }