BlueGit

ict rusty-teams

fix(browser): strip only app emoji fontconfig from Chrome

Keep user FONTCONFIG_FILE/PATH for managed Chrome; only drop the
GPUI fontconfig-emoji path that breaks MS login fonts.

metis Joachim Mild · pushed by metis

Authored 2026-11-13 · 2 weeks ago

Hash
0b439af087a398aef93a222779000773cdb19cda
Parent
f2609340
2 files changed +50 −15
crates/app-base/src/linux_fonts.rs +4 −3
@@ -8,9 +8,10 @@
8 8 //! emoji file out. An existing `FONTCONFIG_FILE` is left alone.
9 9 //!
10 10 //! This `FONTCONFIG_FILE` is for the app process only. Chrome must not
11 //! inherit it (`browser::launch` strips `FONTCONFIG_FILE` /
12 //! `FONTCONFIG_PATH` on spawn) — the dirs-only conf breaks Segoe/Arial
13 //! fallback on the Microsoft login page.
11 //! inherit the app-generated `fontconfig-emoji` conf (`browser::launch`
12 //! strips that path on spawn) — the dirs-only file breaks Segoe/Arial
13 //! fallback on the Microsoft login page. A user-provided
14 //! `FONTCONFIG_FILE` is left alone for both the app and Chrome.
14 15
15 16 use std::collections::HashSet;
16 17 use std::fs;
@@ -8,9 +8,10 @@
8//! emoji file out. An existing `FONTCONFIG_FILE` is left alone.
8//! emoji file out. An existing `FONTCONFIG_FILE` is left alone.
9//!
9//!
10//! This `FONTCONFIG_FILE` is for the app process only. Chrome must not
10//! This `FONTCONFIG_FILE` is for the app process only. Chrome must not
11//! inherit it (`browser::launch` strips `FONTCONFIG_FILE` /
11//! inherit the app-generated `fontconfig-emoji` conf (`browser::launch`
12//! `FONTCONFIG_PATH` on spawn) — the dirs-only conf breaks Segoe/Arial
12//! strips that path on spawn) — the dirs-only file breaks Segoe/Arial
13//! fallback on the Microsoft login page.
13//! fallback on the Microsoft login page. A user-provided
14//! `FONTCONFIG_FILE` is left alone for both the app and Chrome.
14
15
15use std::collections::HashSet;
16use std::collections::HashSet;
16use std::fs;
17use std::fs;
crates/browser/src/launch.rs +46 −12
@@ -88,14 +88,25 @@ pub(crate) fn major_from_version_output(output: &str) -> Option<u32> {
88 88
89 89 const FALLBACK_MAJOR: u32 = 150;
90 90
91 /// Env the app sets for GPUI emoji font filtering. Chrome must use the system
92 /// fontconfig again — the GPUI file is dirs-only and breaks Segoe/Arial fallback
93 /// (Orbitron, Font Awesome, … on the Microsoft login page).
94 const APP_ONLY_FONTCONFIG_VARS: &[&str] = &["FONTCONFIG_FILE", "FONTCONFIG_PATH"];
91 /// Marker directory used by `app_base::linux_fonts::hide_system_color_emoji`.
92 /// Only that app-generated conf must be cleared for Chrome; a user-provided
93 /// `FONTCONFIG_FILE` / `FONTCONFIG_PATH` stays inherited.
94 const APP_EMOJI_FONTCONFIG_MARKER: &str = "fontconfig-emoji";
95
96 fn is_app_emoji_fontconfig(value: &std::ffi::OsStr) -> bool {
97 std::path::Path::new(value)
98 .components()
99 .any(|component| component.as_os_str() == APP_EMOJI_FONTCONFIG_MARKER)
100 }
95 101
96 102 fn strip_app_fontconfig(command: &mut Command) {
97 for key in APP_ONLY_FONTCONFIG_VARS {
98 command.env_remove(*key);
103 for key in ["FONTCONFIG_FILE", "FONTCONFIG_PATH"] {
104 let Some(value) = std::env::var_os(key) else {
105 continue;
106 };
107 if is_app_emoji_fontconfig(&value) {
108 command.env_remove(key);
109 }
99 110 }
100 111 }
101 112
@@ -275,14 +286,37 @@ mod tests {
275 286 }
276 287
277 288 #[test]
278 fn chrome_drops_gpui_fontconfig_env() {
279 assert!(APP_ONLY_FONTCONFIG_VARS.contains(&"FONTCONFIG_FILE"));
280 assert!(APP_ONLY_FONTCONFIG_VARS.contains(&"FONTCONFIG_PATH"));
289 fn chrome_drops_only_app_emoji_fontconfig() {
290 assert!(is_app_emoji_fontconfig(std::ffi::OsStr::new(
291 "/tmp/cache/fontconfig-emoji/fonts.conf"
292 )));
293 assert!(!is_app_emoji_fontconfig(std::ffi::OsStr::new(
294 "/etc/fonts/fonts.conf"
295 )));
296
297 let previous_file = std::env::var_os("FONTCONFIG_FILE");
298 let previous_path = std::env::var_os("FONTCONFIG_PATH");
299 // SAFETY: test-only env mutation around a synchronous strip call.
300 unsafe {
301 std::env::set_var(
302 "FONTCONFIG_FILE",
303 "/tmp/cache/fontconfig-emoji/fonts.conf",
304 );
305 std::env::set_var("FONTCONFIG_PATH", "/etc/fonts");
306 }
281 307 let mut command = Command::new("true");
282 command.env("FONTCONFIG_FILE", "/tmp/gpui-fonts.conf");
283 command.env("FONTCONFIG_PATH", "/tmp/gpui-fontconfig");
284 308 strip_app_fontconfig(&mut command);
285 // env_remove is applied; child would not see the GPUI-only vars.
309 // App marker path is removed; user FONTCONFIG_PATH is left alone.
286 310 let _ = command;
311 unsafe {
312 match previous_file {
313 Some(value) => std::env::set_var("FONTCONFIG_FILE", value),
314 None => std::env::remove_var("FONTCONFIG_FILE"),
315 }
316 match previous_path {
317 Some(value) => std::env::set_var("FONTCONFIG_PATH", value),
318 None => std::env::remove_var("FONTCONFIG_PATH"),
319 }
320 }
287 321 }
288 322 }
@@ -88,14 +88,25 @@ pub(crate) fn major_from_version_output(output: &str) -> Option<u32> {
88
88
89const FALLBACK_MAJOR: u32 = 150;
89const FALLBACK_MAJOR: u32 = 150;
90
90
91/// Env the app sets for GPUI emoji font filtering. Chrome must use the system
91/// Marker directory used by `app_base::linux_fonts::hide_system_color_emoji`.
92/// fontconfig again — the GPUI file is dirs-only and breaks Segoe/Arial fallback
92/// Only that app-generated conf must be cleared for Chrome; a user-provided
93/// (Orbitron, Font Awesome, … on the Microsoft login page).
93/// `FONTCONFIG_FILE` / `FONTCONFIG_PATH` stays inherited.
94const APP_ONLY_FONTCONFIG_VARS: &[&str] = &["FONTCONFIG_FILE", "FONTCONFIG_PATH"];
94const APP_EMOJI_FONTCONFIG_MARKER: &str = "fontconfig-emoji";
95
96fn is_app_emoji_fontconfig(value: &std::ffi::OsStr) -> bool {
97 std::path::Path::new(value)
98 .components()
99 .any(|component| component.as_os_str() == APP_EMOJI_FONTCONFIG_MARKER)
100}
95
101
96fn strip_app_fontconfig(command: &mut Command) {
102fn strip_app_fontconfig(command: &mut Command) {
97 for key in APP_ONLY_FONTCONFIG_VARS {
103 for key in ["FONTCONFIG_FILE", "FONTCONFIG_PATH"] {
98 command.env_remove(*key);
104 let Some(value) = std::env::var_os(key) else {
105 continue;
106 };
107 if is_app_emoji_fontconfig(&value) {
108 command.env_remove(key);
109 }
99 }
110 }
100}
111}
101
112
@@ -275,14 +286,37 @@ mod tests {
275 }
286 }
276
287
277 #[test]
288 #[test]
278 fn chrome_drops_gpui_fontconfig_env() {
289 fn chrome_drops_only_app_emoji_fontconfig() {
279 assert!(APP_ONLY_FONTCONFIG_VARS.contains(&"FONTCONFIG_FILE"));
290 assert!(is_app_emoji_fontconfig(std::ffi::OsStr::new(
280 assert!(APP_ONLY_FONTCONFIG_VARS.contains(&"FONTCONFIG_PATH"));
291 "/tmp/cache/fontconfig-emoji/fonts.conf"
292 )));
293 assert!(!is_app_emoji_fontconfig(std::ffi::OsStr::new(
294 "/etc/fonts/fonts.conf"
295 )));
296
297 let previous_file = std::env::var_os("FONTCONFIG_FILE");
298 let previous_path = std::env::var_os("FONTCONFIG_PATH");
299 // SAFETY: test-only env mutation around a synchronous strip call.
300 unsafe {
301 std::env::set_var(
302 "FONTCONFIG_FILE",
303 "/tmp/cache/fontconfig-emoji/fonts.conf",
304 );
305 std::env::set_var("FONTCONFIG_PATH", "/etc/fonts");
306 }
281 let mut command = Command::new("true");
307 let mut command = Command::new("true");
282 command.env("FONTCONFIG_FILE", "/tmp/gpui-fonts.conf");
283 command.env("FONTCONFIG_PATH", "/tmp/gpui-fontconfig");
284 strip_app_fontconfig(&mut command);
308 strip_app_fontconfig(&mut command);
285 // env_remove is applied; child would not see the GPUI-only vars.
309 // App marker path is removed; user FONTCONFIG_PATH is left alone.
286 let _ = command;
310 let _ = command;
311 unsafe {
312 match previous_file {
313 Some(value) => std::env::set_var("FONTCONFIG_FILE", value),
314 None => std::env::remove_var("FONTCONFIG_FILE"),
315 }
316 match previous_path {
317 Some(value) => std::env::set_var("FONTCONFIG_PATH", value),
318 None => std::env::remove_var("FONTCONFIG_PATH"),
319 }
320 }
287 }
321 }
288}
322}