szn

Bug 490 — OSC 52 forward path ignores the paste-size cap

490. Size check runs after the allocation and fan-out

Severity: MEDIUM (memory amplification from pane-controlled data) Status: 🟢 FIXED Files: src/server/server.zig:2329-2346

Problem

paneClipboardCallback handles OSC 52 (clipboard set) from panes in two steps:

  1. Forward the raw OSC 52 to all display clients wrapped in an output packet.
  2. Decode base64 and push to 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.

Proposed Fix

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.

Resolution

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.