From 18b457306431c76e7a41cdff419f7be918dd359b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=B0=8F=E7=99=BD?= <364772080@qq.com> Date: Wed, 26 Jun 2024 23:01:48 +0800 Subject: [PATCH] Fix font feature tag validation (#13542) The previous implementation that I implemented had two issues: 1. It did not throw an error when the user input some invalid values such as "panic". 2. The feature tag for OpenType fonts should be a combination of letters and digits. We only checked if the input was an ASCII character, which could lead to undefined behavior. Closes #13517 Release Notes: - N/A --- crates/gpui/src/text_system/font_features.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/gpui/src/text_system/font_features.rs b/crates/gpui/src/text_system/font_features.rs index ef6d76481a..db48db62ef 100644 --- a/crates/gpui/src/text_system/font_features.rs +++ b/crates/gpui/src/text_system/font_features.rs @@ -58,7 +58,7 @@ impl<'de> serde::Deserialize<'de> for FontFeatures { while let Some((key, value)) = access.next_entry::>()? { - if key.len() != 4 && !key.is_ascii() { + if !is_valid_feature_tag(&key) { log::error!("Incorrect font feature tag: {}", key); continue; } @@ -142,3 +142,15 @@ impl schemars::JsonSchema for FontFeatures { schema.into() } } + +fn is_valid_feature_tag(tag: &str) -> bool { + if tag.len() != 4 { + return false; + } + for ch in tag.chars() { + if !ch.is_ascii_alphanumeric() { + return false; + } + } + true +}