Severity: MEDIUM (memory amplification from pane-controlled data)
Status: 🟢 FIXED
Files: src/server/server.zig:2329-2346
paneClipboardCallback handles OSC 52 (clipboard set) from panes in two steps:
self.buffers, enforcing MAX_PASTE_SIZE.The comment on step 2 says pane-controlled data “must not balloon server memory” (bug #363) — but step 1 does std.fmt.allocPrint(...) (~1 MiB for a max-size payload) plus self.allocator.alloc(5 + raw_buf.len) (~1 MiB) and queues the full packet to every display client’s out_buf before the size check in step 2 drops it. One ≤1 MiB OSC 52 from any pane forces ~2 MiB transient server allocation plus ~1 MiB queued per attached client, even though the paste is then rejected.
Run calcSizeForSlice (or an equivalent base64-length estimate) first and skip the forward entirely when it exceeds MAX_PASTE_SIZE — the same gate the decode path already uses, applied before any allocation or fan-out.
Moved the calcSizeForSlice validation and MAX_PASTE_SIZE check to the start of paneClipboardCallback before allocating raw_buf, allocating the packet header/buffer, or queueing to display clients. Oversized or invalid base64 payloads are immediately dropped with a warning, preventing memory amplification on the server and client queues. Added regression test OSC 52 clipboard drops oversized payload without forwarding — bug #490.