From 781b1c39bb2befd683d1f94a0634cb8e07e465f4 Mon Sep 17 00:00:00 2001 From: CodeGhost21 <164498022+CodeGhost21@users.noreply.github.com> Date: Sat, 16 May 2026 04:10:51 +0530 Subject: [PATCH] socket: panic-safe utf-8 truncation in socket event log (#1814) (#1826) Co-authored-by: Cursor Co-authored-by: Steven Enamakel --- src/openhuman/socket/event_handlers.rs | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/openhuman/socket/event_handlers.rs b/src/openhuman/socket/event_handlers.rs index bbb16cc02..abd6566d4 100644 --- a/src/openhuman/socket/event_handlers.rs +++ b/src/openhuman/socket/event_handlers.rs @@ -330,6 +330,33 @@ mod tests { assert_eq!(*shared.status.read(), ConnectionStatus::Error); } + #[test] + fn handle_sio_event_debug_truncation_respects_utf8_boundary() { + // Serialized JSON must be >= 500 bytes with a multi-byte codepoint + // straddling byte 500 — mirrors OPENHUMAN-TAURI-KC (Cyrillic at 499..501). + let inner = format!("{}н", "a".repeat(498)); + let payload_json = serde_json::Value::String(inner.clone()).to_string(); + assert!( + payload_json.len() >= 500, + "fixture too short: {} bytes", + payload_json.len() + ); + assert!( + !payload_json.is_char_boundary(500), + "fixture must place byte 500 inside a multi-byte character" + ); + + let shared = make_shared(); + let (tx, _rx) = mpsc::unbounded_channel::(); + handle_sio_event( + "weird.unrelated.event", + serde_json::Value::String(inner), + &tx, + &shared, + ); + assert_eq!(*shared.status.read(), ConnectionStatus::Disconnected); + } + #[test] fn handle_sio_event_unknown_event_is_noop_on_status() { let shared = make_shared();