From 77b6bf3a6f1ead4d63948804d21e38137a316e53 Mon Sep 17 00:00:00 2001 From: neuralbroker Date: Sun, 7 Jun 2026 20:44:57 -0800 Subject: [PATCH] fix: use lossy UTF-8 conversion for device sysname to avoid panic The sysname() method used to_str().expect() which panics when a USB device's kernel sysname contains non-UTF-8 bytes (e.g. certain USB microphones with corrupted manufacturer strings). Use to_string_lossy() instead, matching the behavior of the name() method. Fixes pop-os/cosmic-epoch#2105 where cosmic-comp crashes with: 'Device sysname is no valid utf8: Utf8Error { valid_up_to: 126, error_len: Some(1) }' --- src/device.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/device.rs b/src/device.rs index d377f3b..ef7a898 100644 --- a/src/device.rs +++ b/src/device.rs @@ -388,11 +388,14 @@ impl Device { /// Get the system name of the device. /// /// To get the descriptive device name, use `name`. - pub fn sysname(&self) -> &str { + /// + /// The sysname is the name of the device in the `/sys` filesystem. + /// If the sysname is not valid UTF-8, the invalid bytes are replaced + /// with `U+FFFD REPLACEMENT CHARACTER`. + pub fn sysname(&self) -> Cow<'_, str> { unsafe { CStr::from_ptr(ffi::libinput_device_get_sysname(self.as_raw_mut())) - .to_str() - .expect("Device sysname is no valid utf8") + .to_string_lossy() } }