szn

Bug 485 — eraseChars: cx + n overflows u32 on untrusted CSI param

485. CSI 4294967295 X from any child panics the server

Severity: CRITICAL (server panic on untrusted bytes) Status: ✅ FIXED Files: src/screen.zig:1233, src/input.zig:287

Problem

pub fn eraseChars(self: *Screen, n: u32) void {
    const fill = self.eraseCell();
    const cx = @min(self.cursor.x, self.grid.width -| 1);
    const end = @min(cx + n, self.grid.width);

n comes straight from a CSI param, and advanceCsiParam (input.zig:287) saturates with *|/+| instead of clamping small — so n can be u32::MAX. With cx > 0, cx + n overflows u32: panic in any build with overflow checks (the default), silent wraparound in ReleaseFast (erases the wrong range via the wrapped @min).

Any child process in any pane can send CSI 4294967295 X and take down the whole server. This is the same untrusted-bytes-meets-integer-arithmetic class as #484.

Proposed Fix

const end = @min(cx +| n, self.grid.width);

Defense in depth: consider clamping CSI params to a sane range at parse time (the saturating parse exists to avoid parse overflow, but nothing downstream should see u32::MAX as a count). Audit other param + coordinate sites for the same pattern.

Resolution

Screen.eraseChars in src/screen.zig uses saturating addition (cx +| n) when calculating the end column.

Tests: eraseChars saturating parameter does not overflow — bug #485 validates that eraseChars(std.math.maxInt(u32)) with cursor.x > 0 executes safely without overflowing and clears to the end of the row.