From e8133c8297176e9826cc4fb58e659cbf2a44df64 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Tue, 20 Feb 2024 12:33:13 -0500 Subject: [PATCH] LibGfx/OpenType: Undo minor deletion in #23225 Check if we have a cmap before dereferencing it again. Fixes a crash on page 8 of 0000188.pdf now that the font no longer fails to load to due to a missing name table. Looks like this is a Type2 truetype font, where we don't provide an external cmap. How this font is supposed to work without a cmap I don't know -- but for now, we no longer crash on it, and draw some of the text with the previous font (which happens to work fine in this particular case). --- Userland/Libraries/LibGfx/Font/OpenType/Font.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Userland/Libraries/LibGfx/Font/OpenType/Font.cpp b/Userland/Libraries/LibGfx/Font/OpenType/Font.cpp index 4ab5747d9b..2d94e64131 100644 --- a/Userland/Libraries/LibGfx/Font/OpenType/Font.cpp +++ b/Userland/Libraries/LibGfx/Font/OpenType/Font.cpp @@ -278,6 +278,8 @@ ErrorOr> Font::try_load_from_offset(ReadonlyBytes buffer, u3 hmtx = TRY(Hmtx::from_slice(opt_hmtx_slice.value(), maxp.num_glyphs(), hhea.number_of_h_metrics())); } + if (!options.external_cmap && !opt_cmap_slice.has_value()) + return Error::from_string_literal("Font is missing Cmap"); NonnullOwnPtr cmap = options.external_cmap ? options.external_cmap.release_nonnull() : TRY(CmapCharCodeToGlyphIndex::from_slice(opt_cmap_slice.value())); Optional loca;