From c70d42671aa42002c034aaabc267ccb9c395c2ca Mon Sep 17 00:00:00 2001 From: rustdesk Date: Fri, 4 Dec 2026 13:08:51 +0800 Subject: [PATCH] fix: bound peer-supplied wheel deltas and screenshot displays Refs #17396. A wheel or trackpad event passed its delta straight to the input backend. X11, uinput and macOS post one event per unit while holding the input lock, so one event with a delta near i32::MAX kept the lock for hours, blocked input for every session and went on after the peer disconnected. Clamp it to the bound the relative-move path already uses; clients send deltas of a few units. A screenshot request is kept in a global map until its display is captured. A request naming a display that does not exist was never removed, so a peer could grow the map without limit. Ignore such requests; the client already gives up after its 30 s cooldown, which is what happened to them before. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01JAxkkig1bcC5Xrr1uwX47b --- src/server/connection.rs | 5 +++++ src/server/input_service.rs | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/src/server/connection.rs b/src/server/connection.rs index ee1b4d103..2acdfba1f 100644 --- a/src/server/connection.rs +++ b/src/server/connection.rs @@ -4186,6 +4186,11 @@ impl Connection { // TODO: Maybe we can do a voice call from cm directly. } Some(message::Union::ScreenshotRequest(request)) => { + // Requests are kept until their display is captured, so one that names no + // display would stay in the global map for the life of the process. + if request.display as usize >= Self::video_source_count(self.video_source()) { + return true; + } if let Some(tx) = self.inner.tx.clone() { crate::video_service::set_take_screenshot( self.video_source(), diff --git a/src/server/input_service.rs b/src/server/input_service.rs index 1608ecc44..387cede71 100644 --- a/src/server/input_service.rs +++ b/src/server/input_service.rs @@ -1421,6 +1421,10 @@ pub fn handle_mouse_simulation_(evt: &MouseEvent, conn: i32) { { y = -y; } + // X11, uinput and macOS post one event per unit while holding the input lock. + const MAX_WHEEL_DELTA: i32 = 10000; + x = x.clamp(-MAX_WHEEL_DELTA, MAX_WHEEL_DELTA); + y = y.clamp(-MAX_WHEEL_DELTA, MAX_WHEEL_DELTA); #[cfg(any(target_os = "macos", target_os = "windows"))] let is_track_pad = evt_type == MOUSE_TYPE_TRACKPAD;