summaryrefslogtreecommitdiff
path: root/docs/vaxis-mouse-bytes.md
blob: 4b9a7226d39320b4912ad772b7f5c936a0a553a2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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".