From 4051431311d3becf4ced309895d7a29ab7e01810 Mon Sep 17 00:00:00 2001 From: Darcy Shen Date: Wed, 13 Nov 2024 15:15:21 +0800 Subject: [PATCH] [7_14] Fix crash when pasting the source code of image ## What ``` |pdf>|0.618par|||> ``` ## How to test your changes? Copy and paste it to Mogan, it will crash Mogan. --- src/Graphics/Fonts/smart_font.cpp | 7 ++++++- src/Plugins/Freetype/unicode_font.cpp | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Graphics/Fonts/smart_font.cpp b/src/Graphics/Fonts/smart_font.cpp index e5acde898..a879b369d 100644 --- a/src/Graphics/Fonts/smart_font.cpp +++ b/src/Graphics/Fonts/smart_font.cpp @@ -268,10 +268,15 @@ init_unicode_substitution () { int get_utf8_code (string c) { + int c_N= N (c); + if (c_N <= 2 || c_N > 6) { + // the largest unicode is U+10FFFF + return -1; + } string uc = strict_cork_to_utf8 (c); int pos = 0; int code= decode_from_utf8 (uc, pos); - if (pos == N (uc)) return code; + if (pos == c_N) return code; else return -1; } diff --git a/src/Plugins/Freetype/unicode_font.cpp b/src/Plugins/Freetype/unicode_font.cpp index 1ec3e6e16..2d0112f1d 100644 --- a/src/Plugins/Freetype/unicode_font.cpp +++ b/src/Plugins/Freetype/unicode_font.cpp @@ -816,7 +816,11 @@ unicode_font_rep::index_glyph (string s, font_metric& rm, font_glyphs& rg) { static bool is_math_italic (string c) { - if (N (c) <= 2) return false; + int c_N= N (c); + if (c_N <= 2 || c_N > 6) { + // the largest unicode is U+10FFFF + return false; + } int i = 0; int code= decode_from_utf8 (strict_cork_to_utf8 (c), i); if (code < 0x2100 || code > 0x1d7ff) return false;