From b6779f3831c48eca2f0ec6edc85a77b16db56270 Mon Sep 17 00:00:00 2001 From: kudasai <47227786+kudasaixc@users.noreply.github.com> Date: Fri, 3 Jul 2026 18:55:08 +0200 Subject: [PATCH] fix(ansi): u16 overflow on oversized CSI parameters The CSI parameter accumulator multiplied and added with no overflow protection. A sequence like ESC[99999m overflows the u16 parameter and, since the Zig objects are built with -O ReleaseSafe, trips the safety check and lands in the panic handler: the kernel silently freezes. Use saturating arithmetic so oversized parameters clamp to 65535 instead of bringing the machine down. --- src/kernel/ainsi.zig | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/kernel/ainsi.zig b/src/kernel/ainsi.zig index 81474ed..2c1f187 100644 --- a/src/kernel/ainsi.zig +++ b/src/kernel/ainsi.zig @@ -79,7 +79,9 @@ export fn ansi_process_char(c: u8) void { switch (c) { '0'...'9' => { const n = c - '0'; - val.params[val.param_index] = (val.params[val.param_index] * 10) + n; + // saturate instead of overflowing: a u16 overflow would + // trip the ReleaseSafe safety check and hang the kernel + val.params[val.param_index] = val.params[val.param_index] *| 10 +| n; }, 'J' => { switch (val.params[0]) {