szn

Bug 182 — Sixel parser permanently stuck after 16 MiB buffer cap — DoS from missing .dcs_discard transition

182. Sixel parser permanently stuck after 16 MiB buffer cap — DoS from missing .dcs_discard transition

File: src/input.zig:440–457 Severity: HIGH Status: ✅ FIXED

fn advanceDcsSixel(self: *InputParser, byte: u8) !void {
    ...
    // Cap raw sixel data at 16 MiB to prevent runaway memory use.
    if (self.dcs_buf.items.len < 16 * 1024 * 1024) {
        try self.dcs_buf.append(self.screen.allocator, byte);
    }
    // After cap: byte silently dropped, parser stays in .dcs_sixel
}

When the 16 MiB cap is reached, incoming bytes are silently dropped but the parser remains in .dcs_sixel state. No transition to .dcs_discard occurs. All subsequent non-sixel data is consumed as sixel bytes and dropped. The only escape is an ST terminator (0x1B \ or 0x9C).

Impact: A malicious or misbehaving client that sends a sixel stream with no ST terminator permanently locks the input parser. All keystrokes and terminal output after the cap is hit are silently consumed/dropped.

Fix: When the cap is reached, transition to .dcs_discard so subsequent bytes are consumed silently until ST arrives. The discarded body bytes are gone forever, but the parser recovers. Unit test added: sixel 16 MiB cap transitions to discard and recovers on ST.