Godot Engine – Multi-platform 2D and 3D game engine
[Font] Validate and fail invalid dynamic font imports.
Pāvels Nadtočajevsa4a9cfe9b0e1
diff --git a/doc/classes/TextServerExtension.xml b/doc/classes/TextServerExtension.xmlindex 6af8643c1c9..7553802938d 100644--- a/doc/classes/TextServerExtension.xml+++ b/doc/classes/TextServerExtension.xml@@ -1107,6 +1107,13 @@Returns the dictionary of the supported OpenType variation coordinates.</description></method>+ <method name="_font_validate" qualifiers="virtual const">+ <return type="bool" />+ <param index="0" name="font_rid" type="RID" />+ <description>+ Returns [code]true[/code] if the font data is valid.+ </description>+ </method><method name="_format_number" qualifiers="virtual const" deprecated="Use [method TranslationServer.format_number] instead."><return type="String" /><param index="0" name="number" type="String" />diff --git a/editor/import/resource_importer_dynamic_font.cpp b/editor/import/resource_importer_dynamic_font.cppindex db043764b58..730822af48f 100644--- a/editor/import/resource_importer_dynamic_font.cpp+++ b/editor/import/resource_importer_dynamic_font.cpp@@ -191,6 +191,11 @@ Error ResourceImporterDynamicFont::import(ResourceUID::ID p_source_id, const Strfont->set_oversampling(oversampling);font->set_fallbacks(fallbacks);+ RID frid = font->_get_rid();+ if (!TS->font_validate(frid)) {+ return FAILED;+ }+if (subpixel_positioning == 4 || hinting == 3 || hinting == 4) /* Dected Pixel Fonts */ {Array rids = font->get_rids();if (!rids.is_empty()) {diff --git a/modules/freetype/SCsub b/modules/freetype/SCsubindex 925f3e5d8e4..0f5c707a7f8 100644--- a/modules/freetype/SCsub+++ b/modules/freetype/SCsub@@ -63,6 +63,9 @@ if env["builtin_freetype"]:if env["brotli"]:env_freetype.Append(CPPDEFINES=["FT_CONFIG_OPTION_USE_BROTLI"])+ if env.debug_features:+ env_freetype.Append(CPPDEFINES=["FT_CONFIG_OPTION_ERROR_STRINGS"])+env_freetype.Prepend(CPPPATH=[thirdparty_dir + "/include"])# Also needed in main env for scene/env.Prepend(CPPPATH=[thirdparty_dir + "/include"])diff --git a/modules/text_server_adv/text_server_adv.h b/modules/text_server_adv/text_server_adv.hindex 9bb6e580dcb..291c9553545 100644--- a/modules/text_server_adv/text_server_adv.h+++ b/modules/text_server_adv/text_server_adv.h@@ -382,7 +382,6 @@ class TextServerAdvanced : public TextServerExtension {#endifbool _ensure_glyph(FontAdvanced *p_font_data, const Vector2i &p_size, int32_t p_glyph, FontGlyph &r_glyph, uint32_t p_oversampling = 0) const;bool _ensure_cache_for_size(FontAdvanced *p_font_data, const Vector2i &p_size, FontForSizeAdvanced *&r_cache_for_size, bool p_silent = false, uint32_t p_oversampling = 0) const;- _FORCE_INLINE_ bool _font_validate(const RID &p_font_rid) const;_FORCE_INLINE_ void _font_clear_cache(FontAdvanced *p_font_data);static void _generateMTSDF_threaded(void *p_td, uint32_t p_y);@@ -843,6 +842,7 @@ public:MODBIND2(font_set_data, const RID &, const PackedByteArray &);MODBIND3(font_set_data_ptr, const RID &, const uint8_t *, int64_t);+ MODBIND1RC(bool, font_validate, const RID &);MODBIND2(font_set_face_index, const RID &, int64_t);MODBIND1RC(int64_t, font_get_face_index, const RID &);diff --git a/modules/text_server_fb/text_server_fb.h b/modules/text_server_fb/text_server_fb.hindex b7b233674ec..dda076dd577 100644--- a/modules/text_server_fb/text_server_fb.h+++ b/modules/text_server_fb/text_server_fb.h@@ -290,7 +290,6 @@ class TextServerFallback : public TextServerExtension {#endifbool _ensure_glyph(FontFallback *p_font_data, const Vector2i &p_size, int32_t p_glyph, FontGlyph &r_glyph, uint32_t p_oversampling = 0) const;bool _ensure_cache_for_size(FontFallback *p_font_data, const Vector2i &p_size, FontForSizeFallback *&r_cache_for_size, bool p_silent = false, uint32_t p_oversampling = 0) const;- _FORCE_INLINE_ bool _font_validate(const RID &p_font_rid) const;_FORCE_INLINE_ void _font_clear_cache(FontFallback *p_font_data);static void _generateMTSDF_threaded(void *p_td, uint32_t p_y);@@ -595,6 +594,7 @@ public:MODBIND2(font_set_data, const RID &, const PackedByteArray &);MODBIND3(font_set_data_ptr, const RID &, const uint8_t *, int64_t);+ MODBIND1RC(bool, font_validate, const RID &);MODBIND2(font_set_face_index, const RID &, int64_t);MODBIND1RC(int64_t, font_get_face_index, const RID &);diff --git a/servers/text/text_server.h b/servers/text/text_server.hindex 311b2d22433..913b0962c20 100644--- a/servers/text/text_server.h+++ b/servers/text/text_server.h@@ -276,6 +276,7 @@ public:virtual void font_set_data(const RID &p_font_rid, const PackedByteArray &p_data) = 0;virtual void font_set_data_ptr(const RID &p_font_rid, const uint8_t *p_data_ptr, int64_t p_data_size) = 0;+ virtual bool font_validate(const RID &p_font_rid) const = 0;virtual void font_set_face_index(const RID &p_font_rid, int64_t p_index) = 0;virtual int64_t font_get_face_index(const RID &p_font_rid) const = 0;diff --git a/servers/text/text_server_extension.cpp b/servers/text/text_server_extension.cppindex 439b65c2b85..dcec7ee1560 100644--- a/servers/text/text_server_extension.cpp+++ b/servers/text/text_server_extension.cpp@@ -60,6 +60,7 @@ void TextServerExtension::_bind_methods() {GDVIRTUAL_BIND(_font_set_data, "font_rid", "data");GDVIRTUAL_BIND(_font_set_data_ptr, "font_rid", "data_ptr", "data_size");+ GDVIRTUAL_BIND(_font_validate, "font_rid");GDVIRTUAL_BIND(_font_set_face_index, "font_rid", "face_index");GDVIRTUAL_BIND(_font_get_face_index, "font_rid");@@ -523,6 +524,12 @@ void TextServerExtension::font_set_data_ptr(const RID &p_font_rid, const uint8_tGDVIRTUAL_CALL(_font_set_data_ptr, p_font_rid, p_data_ptr, p_data_size);}+bool TextServerExtension::font_validate(const RID &p_font_rid) const {+ bool ret = false;+ GDVIRTUAL_CALL(_font_validate, p_font_rid, ret);+ return ret;+}+void TextServerExtension::font_set_face_index(const RID &p_font_rid, int64_t p_index) {GDVIRTUAL_CALL(_font_set_face_index, p_font_rid, p_index);}diff --git a/servers/text/text_server_extension.h b/servers/text/text_server_extension.hindex b1d1488bd45..ab6799221e6 100644--- a/servers/text/text_server_extension.h+++ b/servers/text/text_server_extension.h@@ -90,8 +90,10 @@ public:virtual void font_set_data(const RID &p_font_rid, const PackedByteArray &p_data) override;virtual void font_set_data_ptr(const RID &p_font_rid, const uint8_t *p_data_ptr, int64_t p_data_size) override;+ virtual bool font_validate(const RID &p_font_rid) const override;GDVIRTUAL2(_font_set_data, RID, const PackedByteArray &);GDVIRTUAL3(_font_set_data_ptr, RID, GDExtensionPtr<const uint8_t>, int64_t);+ GDVIRTUAL1RC(bool, _font_validate, RID);virtual void font_set_face_index(const RID &p_font_rid, int64_t p_index) override;virtual int64_t font_get_face_index(const RID &p_font_rid) const override;