From 2149706ca495b587442921ad72f6a5f0e1f919ff Mon Sep 17 00:00:00 2001 From: WitteShadovv <26429638+WitteShadovv@users.noreply.github.com> Date: Mon, 24 Aug 2026 10:58:57 +0200 Subject: [PATCH] utils/region: Use saturating math for rect extremities Region rects arrive from the client through wl_region.add() unclamped, so a rect like (0, i32::MAX, 1, 1) overflows r.loc.y + r.size.h. That's a panic with overflow-checks = true in the release profile, and it takes the whole session down with it. ext-background-effect is created without the client_is_unrestricted filter, so a client on a security-context socket can get here by setting such a region as its blur region. Saturating matches what smithay's Point and Size operators already do, and the region gets clipped during rendering anyway, so nothing changes for sensible coordinates. --- src/utils/region.rs | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/utils/region.rs b/src/utils/region.rs index a6beac5b..da5082ab 100644 --- a/src/utils/region.rs +++ b/src/utils/region.rs @@ -104,7 +104,7 @@ pub fn region_to_non_overlapping_rects( region .rects .iter() - .flat_map(|(_, r)| [r.loc.y, r.loc.y + r.size.h]), + .flat_map(|(_, r)| [r.loc.y, r.loc.y.saturating_add(r.size.h)]), ); let mut ys = ys.into_iter(); @@ -122,12 +122,12 @@ pub fn region_to_non_overlapping_rects( 'region: for (kind, r) in ®ion.rects { // Skip rects that don't overlap with the Y band. - if hi <= r.loc.y || r.loc.y + r.size.h <= lo { + if hi <= r.loc.y || r.loc.y.saturating_add(r.size.h) <= lo { continue; } let mut x1 = r.loc.x; - let mut x2 = r.loc.x + r.size.w; + let mut x2 = r.loc.x.saturating_add(r.size.w); if x1 == x2 { // Empty rect. continue; @@ -279,6 +279,30 @@ mod tests { ); } + // A client can send a region like wl_region.add(0, i32::MAX, 1, 1), and smithay stores the + // coordinates as they came in. Computing the rect extremities must not overflow here, since + // that panics with overflow-checks on. + #[test] + fn test_extremity_overflow() { + let region = RegionAttributes { + rects: vec![ + ( + RectangleKind::Add, + Rectangle::new(Point::new(0, i32::MAX), Size::new(1, 1)), + ), + ( + RectangleKind::Add, + Rectangle::new(Point::new(i32::MAX, 0), Size::new(1, 1)), + ), + ], + }; + + // Both rects are degenerate after clamping, so nothing comes out. + let mut output = Vec::new(); + region_to_non_overlapping_rects(®ion, &mut output); + assert!(output.is_empty()); + } + proptest! { #[test] fn non_overlapping_output(