From 7532cd1df4661c3533be497fa773b0deda50753b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Arrufat?= Date: Mon, 25 May 2026 17:39:49 +0200 Subject: [PATCH] session: cap console message size to remaining budget --- src/browser/Session.zig | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/browser/Session.zig b/src/browser/Session.zig index bcf5fc82..2a3a4c94 100644 --- a/src/browser/Session.zig +++ b/src/browser/Session.zig @@ -183,7 +183,14 @@ fn onConsoleMessage(ctx: *anyopaque, msg: *const Notification.ConsoleMessage) !v const aw = &self._console_messages; const start = aw.written().len; if (start >= max_console_bytes) return; - appendConsoleMessageInner(&aw.writer, msg) catch { + + // Format into a scratch buffer sized to the remaining budget so a single + // 10 MB `console.log` can't bust the cap before the post-hoc check fires. + const remaining = max_console_bytes - start; + var scratch_buf: [max_console_bytes]u8 = undefined; + var scratch: std.Io.Writer = .fixed(scratch_buf[0..remaining]); + appendConsoleMessageInner(&scratch, msg) catch {}; + aw.writer.writeAll(scratch.buffered()) catch { aw.shrinkRetainingCapacity(start); }; }