szn

Bug 474 — SGR mouse parser accepts trailing fields and unclamped coordinates

474. Under-validated SGR mouse event

Severity: MEDIUM Status: ✅ FIXED Files: src/tty/tty_key.zig


Root Cause Analysis

In src/tty/tty_key.zig:227-252, parseSgrMouse splits on ; for btn/x/y but never rejects a fourth field, and:

const col: u32 = if (x > 0) x - 1 else 0;

leaves up to ~4G unclamped to terminal size. Callers must clamp or OOB mouse routing/hit-test follows.

Proposed Fix

Reject trailing ;... fields and either clamp to display bounds at parse time or document the caller clamp contract with a debug assert. Add tests for 0;20;10;99M and huge coordinates.