The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(bot-screen): the RFB bridge forwards SetDesktopSize instead of dropping the viewer's stream
teknium13c53adbc1e4a
diff --git a/tests/tools/test_bot_desktop_rfb_filter_limits.py b/tests/tools/test_bot_desktop_rfb_filter_limits.pyindex 018336d9f64..df4dd2fe27a 100644--- a/tests/tools/test_bot_desktop_rfb_filter_limits.py+++ b/tests/tools/test_bot_desktop_rfb_filter_limits.py@@ -1,5 +1,6 @@-"""A client-declared ClientCutText length is bounded at the header: the bridge must not buffer up to-2 GiB for a viewer that holds a ticket but no lease."""+"""RFB client-message framing at the bridge: a client-declared ClientCutText length is bounded at the header+(the bridge must not buffer up to 2 GiB for a viewer that holds a ticket but no lease), and every message+type Xvnc is configured to accept must be framed, or the stream dies on it."""import pytest@@ -22,3 +23,31 @@ def test_oversized_clipboard_is_rejected_at_header_without_waiting_for_payload(lassert parser.feed(bytes([byte])) == b""with pytest.raises(ValueError, match="clipboard"):parser.feed(header[-1:])+++def set_desktop_size(width, height, screens=1):+ # RFB 7.5.x SetDesktopSize: type, pad, u16 width, u16 height, u8 nScreens, pad, then 16 bytes per screen+ # (u32 id, u16 x, u16 y, u16 w, u16 h, u32 flags).+ head = bytes([251, 0]) + width.to_bytes(2, "big") + height.to_bytes(2, "big") + bytes([screens, 0])+ return head + b"".join(i.to_bytes(4, "big") + b"\x00\x00\x00\x00" + width.to_bytes(2, "big") + height.to_bytes(2, "big")+ + b"\x00\x00\x00\x00" for i in range(screens))++[email protected]("holder", [False, True])+def test_set_desktop_size_is_framed_and_forwarded_even_to_a_watcher(holder):+ """Regression for #110039: launcher.sh passes -AcceptSetDesktopSize (the viewer fits the screen to its+ pane), but the filter had no frame for client message 251 and killed the stream with 'unknown RFB client+ message type'. It carries no input, so it passes through like SetEncodings, lease or not."""+ parser = RfbClientFilter(lambda: holder)+ parser.feed(_HANDSHAKE)+ msg = set_desktop_size(1280, 800) + b"\x03\x00" + b"\x00" * 8 # followed by a FramebufferUpdateRequest+ assert parser.feed(msg) == msg+++def test_truncated_set_desktop_size_waits_for_the_rest():+ parser = RfbClientFilter(lambda: False)+ parser.feed(_HANDSHAKE)+ msg = set_desktop_size(1280, 800, screens=2)+ for byte in msg[:-1]:+ assert parser.feed(bytes([byte])) == b""+ assert parser.feed(msg[-1:]) == msgdiff --git a/tools/bot_desktop/rfb_filter.py b/tools/bot_desktop/rfb_filter.pyindex 6fe9127559a..88a0668e17b 100644--- a/tools/bot_desktop/rfb_filter.py+++ b/tools/bot_desktop/rfb_filter.py@@ -3,7 +3,8 @@noVNC's ``viewOnly`` is a UI hint; anyone holding the socket could still inject input. The bridgeparses the client stream and forwards only non-input messages from viewers that do not hold thelease. RFB messages do not align with WebSocket frames, so this is a stateful stream parser fed-arbitrary chunks (RFC 6143 §7.5 layouts; TigerVNC's EnableContinuousUpdates 150 and Fence 248 pass+arbitrary chunks (RFC 6143 §7.5 layouts; TigerVNC's EnableContinuousUpdates 150, Fence 248 and+SetDesktopSize 251 — Xvnc runs -AcceptSetDesktopSize so the viewer can fit the screen to its pane — passthrough untouched since they carry no input; QEMU Extended KeyEvent 255 is keyboard input — noVNCswitches to it as soon as Xvnc advertises the pseudo-encoding — so it is gated like KeyEvent).@@ -29,6 +30,7 @@ _FIXED = {_SET_ENCODINGS = 2_CLIENT_CUT_TEXT = 6_FENCE = 248+_SET_DESKTOP_SIZE = 251 # u8 type, pad, u16 width, u16 height, u8 nScreens, pad, then 16 bytes per screen# TigerVNC's default MaxCutText, and the value launcher.sh passes as ``-MaxCutText`` so Xvnc and# the bridge agree (keep the two in sync). The length is client-declared (int32); without a cap a@@ -96,6 +98,10 @@ class RfbClientFilter:if len(self._buf) < 9:return Nonereturn 9 + self._buf[8]+ if t == _SET_DESKTOP_SIZE:+ if len(self._buf) < 8:+ return None+ return 8 + 16 * self._buf[6]# Unknown client message: we cannot frame it, and forwarding blind would let an input message# hide behind it. Drop the rest of the stream; the viewer reconnects.raise ValueError(f"unknown RFB client message type {t}")