From 09640ab2919c17f24e14c8d71fafdb15c4748395 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Tue, 16 Aug 2022 12:43:10 -0700 Subject: Fix T99872: Crash Loading Embedded Fonts - Master Commit rBc0845abd897f to 3.4 (master) uses font's filepath without checking if it exists, therefore crashing on embedded fonts since they do not have a filepath (loaded from memory). See D15703 for more details Differential Revision: https://developer.blender.org/D15703 Reviewed by Brecht Van Lommel --- source/blender/blenfont/intern/blf_font.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c index b3729b7a673..226752bffd8 100644 --- a/source/blender/blenfont/intern/blf_font.c +++ b/source/blender/blenfont/intern/blf_font.c @@ -1384,22 +1384,27 @@ static FontBLF *blf_font_new_ex(const char *name, BLI_mutex_init(&font->glyph_cache_mutex); - /* If we have static details about this font we don't need to load the Face. */ - const eFaceDetails *static_details = NULL; - char filename[256]; - for (int i = 0; i < (int)ARRAY_SIZE(static_face_details); i++) { - BLI_split_file_part(font->filepath, filename, sizeof(filename)); - if (STREQ(static_face_details[i].name, filename)) { - static_details = &static_face_details[i]; - font->UnicodeRanges[0] = static_details->coverage1; - font->UnicodeRanges[1] = static_details->coverage2; - font->UnicodeRanges[2] = static_details->coverage3; - font->UnicodeRanges[3] = static_details->coverage4; - break; + /* If we have static details about this font file, we don't have to load the Face yet. */ + bool face_needed = true; + + if (font->filepath) { + const eFaceDetails *static_details = NULL; + char filename[256]; + for (int i = 0; i < (int)ARRAY_SIZE(static_face_details); i++) { + BLI_split_file_part(font->filepath, filename, sizeof(filename)); + if (STREQ(static_face_details[i].name, filename)) { + static_details = &static_face_details[i]; + font->UnicodeRanges[0] = static_details->coverage1; + font->UnicodeRanges[1] = static_details->coverage2; + font->UnicodeRanges[2] = static_details->coverage3; + font->UnicodeRanges[3] = static_details->coverage4; + face_needed = false; + break; + } } } - if (!static_details) { + if (face_needed) { if (!blf_ensure_face(font)) { blf_font_free(font); return NULL; -- cgit v1.2.3