forge
Explore
Log in

Don't you dare go Hollow

Catch panics from edid-rs

Browse files at this commit

2750b2038bed5495bcdfeacc7be25267d15ceab1Ivan MolodetskikhParent: c4145b0
Work around an integer overflow.

See: https://github.com/YaLTeR/niri/issues/239
src/backend/tty.rsmodified+16 -3
@@ -1,6 +1,7 @@
1 use std::cell::RefCell;1 use std::cell::RefCell;
2 use std::collections::{HashMap, HashSet};2 use std::collections::{HashMap, HashSet};
3 use std::fmt::Write;3 use std::fmt::Write;
4+use std::panic::{catch_unwind, AssertUnwindSafe};
4 use std::path::Path;5 use std::path::Path;
5 use std::rc::Rc;6 use std::rc::Rc;
6 use std::sync::{Arc, Mutex};7 use std::sync::{Arc, Mutex};
@@ -644,7 +645,7 @@ impl Tty {
644 645
645 if non_desktop {646 if non_desktop {
646 debug!("output is non desktop");647 debug!("output is non desktop");
647- let description = EdidInfo::for_connector(&device.drm, connector.handle())648+ let description = get_edid_info(&device.drm, connector.handle())
648 .map(|info| truncate_to_nul(info.model))649 .map(|info| truncate_to_nul(info.model))
649 .unwrap_or_else(|| "Unknown".into());650 .unwrap_or_else(|| "Unknown".into());
650 device.drm_lease_state.add_connector::<State>(651 device.drm_lease_state.add_connector::<State>(
@@ -704,7 +705,7 @@ impl Tty {
704 // Update the output mode.705 // Update the output mode.
705 let (physical_width, physical_height) = connector.size().unwrap_or((0, 0));706 let (physical_width, physical_height) = connector.size().unwrap_or((0, 0));
706 707
707- let (make, model) = EdidInfo::for_connector(&device.drm, connector.handle())708+ let (make, model) = get_edid_info(&device.drm, connector.handle())
708 .map(|info| {709 .map(|info| {
709 (710 (
710 truncate_to_nul(info.manufacturer),711 truncate_to_nul(info.manufacturer),
@@ -1250,7 +1251,7 @@ impl Tty {
1250 1251
1251 let physical_size = connector.size();1252 let physical_size = connector.size();
1252 1253
1253- let (make, model) = EdidInfo::for_connector(&device.drm, connector.handle())1254+ let (make, model) = get_edid_info(&device.drm, connector.handle())
1254 .map(|info| {1255 .map(|info| {
1255 (1256 (
1256 truncate_to_nul(info.manufacturer),1257 truncate_to_nul(info.manufacturer),
@@ -1755,6 +1756,18 @@ fn truncate_to_nul(mut s: String) -> String {
1755 s1756 s
1756 }1757 }
1757 1758
1759+fn get_edid_info(device: &DrmDevice, connector: connector::Handle) -> Option<EdidInfo> {
1760+ match catch_unwind(AssertUnwindSafe(move || {
1761+ EdidInfo::for_connector(device, connector)
1762+ })) {
1763+ Ok(info) => info,
1764+ Err(err) => {
1765+ warn!("edid-rs panicked: {err:?}");
1766+ None
1767+ }
1768+ }
1769+}
1770+
1758 #[cfg(test)]1771 #[cfg(test)]
1759 mod tests {1772 mod tests {
1760 use super::*;1773 use super::*;