summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-23 16:13:35 -0300
committerGabriel Schneider <[email protected]>2026-11-23 16:46:30 -0300
commitaf78ec0dcb1ed40fd64001474f46b1b03a72475b (patch)
tree5262f4c395e06ffcfc743995cc2bc7ae0ff9ae3e
parent5a7716d32de84255e792c5f4bf0fa7b8261b9139 (diff)
downloadpardes-af78ec0dcb1ed40fd64001474f46b1b03a72475b.tar.gz
pardes-af78ec0dcb1ed40fd64001474f46b1b03a72475b.zip
vaxis: a mouse report's bytes are checked, not subtracted and cast: its X10 branch took `full_input[3] - 32` as a u8 (`integer overflow` at Parser.zig:792 on main: a legacy terminal's `ESC [ M` then a control byte, Alt+[ Shift+M Enter), and a button by `@fromBackingInt` (192..195 are none); two Edits in build/patches.zig `vaxis_parser` (a byte under 32: no event, its six bytes taken; a button none of Mouse.Button's: no event), upstream main unfixed (checked 2026-11-23), its report docs/vaxis-mouse-bytes.md; the test: dev/tui/tui.zig (the tests change); a user could hit it with an ordinary terminal in its legacy mouse encoding
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
-rw-r--r--build/patches.zig12
-rw-r--r--docs/vaxis-mouse-bytes.md29
2 files changed, 41 insertions, 0 deletions
diff --git a/build/patches.zig b/build/patches.zig
index 410d27ab..1cf79ac1 100644
--- a/build/patches.zig
+++ b/build/patches.zig
@@ -123,6 +123,18 @@ const vaxis_parser = [_]Edit{
\\
,
},
+ // An X10 report's bytes are 32 and up, and a button is one Mouse has:
+ // what is not (a legacy terminal's `ESC [ M` then a control byte: Alt+[,
+ // Shift+M, Enter; `CSI < 192;1;1M`) is no event, never a u8 underflow
+ // or a cast (docs/vaxis-mouse-bytes.md).
+ .{
+ .old = " button_mask = full_input[3] - 32;\n",
+ .new = " if (full_input[3] < 32 or full_input[4] < 32 or full_input[5] < 32) return .{ .event = null, .n = 6 }; // pardes's patch (its build.zig)\n button_mask = full_input[3] - 32;\n",
+ },
+ .{
+ .old = " const button: Mouse.Button = @fromBackingInt(@intCast(button_mask & mouse_bits.buttons));\n",
+ .new = " const button = std.enums.fromInt(Mouse.Button, button_mask & mouse_bits.buttons) orelse return .{ .event = null, .n = if (xterm) 6 else input.len }; // pardes's patch (its build.zig)\n",
+ },
};
/// vaxis's render: a blank whose ink alone changed is not sent, since a
diff --git a/docs/vaxis-mouse-bytes.md b/docs/vaxis-mouse-bytes.md
new file mode 100644
index 00000000..4b9a7226
--- /dev/null
+++ b/docs/vaxis-mouse-bytes.md
@@ -0,0 +1,29 @@
+# libvaxis: a mouse report's bytes are subtracted and cast unchecked
+
+A report for upstream (https://github.com/rockorager/libvaxis), against
+main as of 2026-11-23 (its newest commit to src/Parser.zig then:
+0ef2752d, 2026-11-12); pardes pins 6fd944a2. pardes patches its fetched
+copy at build time (build/patches.zig, `vaxis_parser`) until it is fixed
+there.
+
+## What happens
+
+`parseMouse` (src/Parser.zig), in Debug and ReleaseSafe:
+
+- the X10 branch reads `full_input[3] - 32`, `[4] - 32` and `[5] - 32` as
+ u8s: a byte below 32 is an integer overflow. A terminal in the legacy
+ encoding sends `ESC [ M` then a control byte for Alt+[, Shift+M, Enter;
+ a paste or a report past column 222 can hold one too;
+- the button is `@fromBackingInt(@intCast(button_mask & mouse_bits.buttons))`:
+ the mask keeps 0b11000011, and 192..195 are no `Mouse.Button` (an
+ invalid enum value): `CSI < 192 ; 1 ; 1 M`.
+
+Either panic ends the program reading the terminal.
+
+## The patch
+
+A report with a byte below 32 is no event (its six bytes taken); a
+button that is none of `Mouse.Button`'s is no event, by
+`std.enums.fromInt`. Held by dev/tui/tui.zig's test "an X10 mouse report
+with a byte below 32, and one with a button no mouse has, are no event,
+never a panic".