From 5c88e349dae440ae7ef70ffd27b51601651e9c5d Mon Sep 17 00:00:00 2001 From: Robby Russell Date: Fri, 27 Nov 2026 16:23:11 -0800 Subject: [PATCH] fix(clipboard): cap OSC 52 copies at 100 KB The OSC 52 fallback sent any amount of data to the terminal, so copying a large file (e.g. `copyfile` on a log) could be silently dropped or stall the terminal. Fail with an error instead when the base64 payload is over 100000 bytes, so people know the copy didn't happen. Follow-up to #14251. Co-Authored-By: Claude Opus 5.5 --- lib/clipboard.zsh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/clipboard.zsh b/lib/clipboard.zsh index 44e81e701..cd314ce8e 100644 --- a/lib/clipboard.zsh +++ b/lib/clipboard.zsh @@ -20,6 +20,8 @@ # # Set ZSH_CLIPBOARD_OSC52 to "always" to copy through OSC 52 even if a # clipboard tool is available, or to "never" to disable the fallback. +# OSC 52 copies larger than 100 KB (after base64 encoding) fail with an error, +# since many terminals drop or truncate payloads that size. # # Defines two functions, clipcopy and clippaste, based on the detected platform. ## @@ -60,6 +62,10 @@ function _clipcopy_osc52() { emulate -L zsh local content content=$(cat "${1:-/dev/stdin}" | base64 | tr -d '\n') || return 1 + if (( ${#content} > 100000 )); then + print "clipcopy: too large for OSC 52 (${#content} bytes encoded, limit 100000)" >&2 + return 1 + fi print -rn -- $'\e]52;c;'"${content}"$'\e\\' > /dev/tty }