szn

Bug 363 — Paste buffers: unbounded size and unbounded count

363. Any child process can balloon server memory via OSC52

File: src/server/server.zig:2156-2174; src/buffer.zig:14-88 Severity: HIGH Status: ✅ FIXED

Fix (applied)

  1. paneClipboardCallback rejects OSC52 payloads whose decoded size exceeds MAX_PASTE_SIZE (16 KiB) before allocating.
  2. BufferList gained max_buffers = 50; push/pushOwned evict the oldest entry when full, so every yank/click no longer accumulates a permanent "bufferN".

Test: buffer list evicts oldest past max_buffers — bug #363 (5 pushes at cap 3 leave the newest three, oldest two freed).

Problem

  1. paneClipboardCallback decodes an arbitrary-size base64 payload and stores it permanently. MAX_PASTE_SIZE — enforced in the yank/paste paths (cmdPasteBuffer, cmd.zig:471) — is never consulted here.
  2. BufferList has no entry limit: every mouse yank / click-selection / OSC52 push adds "bufferN" forever. tmux defaults to ~50 buffers.

Fix (proposed)

Enforce MAX_PASTE_SIZE in the OSC52 path (reject or truncate with a log line), and add MAX_BUFFERS eviction of the oldest entry in buffers.pushOwned. Regression tests: oversized payload rejected; pushing limit+1 buffers evicts the oldest.