Skip to content

Prevent clipboard capture hangs - #9488

Merged
dhh merged 2 commits into
omacom:quattrofrom
maxcroy1:fix/clipboard-capture-timeouts
Oct 5, 2026
Merged

dhh merged 2 commits into
omacom:quattrofrom
maxcroy1:fix/clipboard-capture-timeouts

Conversation

@maxcroy1

@maxcroy1 maxcroy1 commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

wl-paste --watch waits for each capture callback before handling another clipboard event. An owner that stalls without closing the payload pipe can therefore leave capture.sh waiting for EOF indefinitely, silently stopping clipboard history as reported in #9443.

Bound MIME queries and every payload read, including watched stdin and startup snapshots, to two seconds. Stage each payload before decoding or hashing it, and emit an entry only when the read completes successfully. Incomplete transfers are dropped and their temporary files are removed on normal exit. This prevents recording a truncated copy and allows the watcher to process subsequent events. A legitimate transfer taking longer than two seconds is omitted from history; the clipboard itself is unchanged.

Fixes #9443

@aholbreich aholbreich left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. I reran your fake-wl-paste harness against quattro and this branch (0a9d2c49) and got the same numbers: 3.02 s before, 2.02 s after for the stalled --list-types, and 3.02 s → 2.01 s for the snapshot read. The two timeouts look correct and safe to me. I also checked that a password-manager copy is still skipped when --list-types times out: in watch mode wl-paste sets CLIPBOARD_STATE=sensitive itself from the same x-kde-passwordManagerHint type, so line 15 still exits.

One hang path is still open, and I think it is the one behind #9443. In watch mode, capture.sh's stdin is the pipe from the clipboard owner (wl-paste dup2s it and then blocks in waitpid(), wl-paste.c L198, L218). emit_text and emit_image read that pipe to EOF with no bound. If the owner keeps its end open without closing it (frozen, or the fd leaked to a child process), the callback never exits. It reproduces on this branch for both text and image:

{ printf 'copied'; sleep 12; } | timeout 8 shell/plugins/clipboard/capture.sh text        # still killed by the outer 8 s guard
{ printf 'PNG';    sleep 12; } | timeout 8 shell/plugins/clipboard/capture.sh image/png   # same

Two hints that this, not line 13, is what hung in #9443:

  • wl-paste --list-types never opens a pipe to the owner. It prints the offered types and exits (wl-paste.c L280-285), so an owner going away can't stall it.
  • The ps filter in #9443 (grep -E "wl-paste|capture\.sh") would have shown a stuck wl-paste --list-types child, and none is listed. A stuck perl (emit_text) wouldn't match that filter.

Possible fixes, either one:

  • bound the stdin read in capture.sh: text) timeout 2s cat | emit_text and the same for image/*, or
  • bound the whole callback in Clipboard.qml: "wl-paste", "--type", "text", "--watch", "timeout", "5s", root.captureScript, "text" (same for the image watcher), which also covers any wait added later. A longer limit is kinder to large images.

Small nit: if the snapshot read on line 105 times out partway through, emit_text still writes what it received so far. With a fake that sends half, pauses 3 s, then sends the rest, this branch records "first half ", while quattro records the full text. It only affects the one snapshot at shell start. Skipping the entry when timeout exits with 124 would avoid it.

In watch mode capture.sh reads the copy from the owner's pipe on stdin, to EOF, with no bound. An owner that stalls without closing its end keeps the callback alive, and wl-paste --watch handles no further clipboard events until it exits. That matches omacom#9443, whose stuck capture.sh had no wl-paste child: --list-types never reads from the owner.

Every read now goes through one bounded reader into a temporary file, and the copy is recorded only when the read finished, so a snapshot that stalls halfway no longer records its first half.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Sep 30, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed, reproduced on a worker built from the Omarchy ISO, and fixed in one commit pushed to this branch (b147c75).

What was still open. @aholbreich's review is right, and I've followed it. wl-paste --watch hands capture.sh the clipboard owner's pipe as stdin, and emit_text (perl) and emit_image (cat) read it to EOF with no bound. An owner that stalls without closing its end keeps the callback alive, and text history stops. The ps in #9443 fits this: its stuck capture.sh text has no wl-paste child, and --list-types never reads from the owner. With only 0a9d2c4, { printf copied; sleep 12; } | timeout 8 capture.sh text (and the same for image/png) is still killed by the outer guard.

What b147c75 changes. Every read in capture.sh, watched stdin included, now goes through one read_copy helper: timeout 2s into a temporary file. The entry is emitted only when the read finished, so a snapshot that stalls halfway no longer records its first half, which was the nit in the same review. The temporary file is removed on exit. clipboard-test.sh gains a test for a snapshot stalled midway, tests for watched text and image whose owner never closes, and a check that dropped copies leave no temporary files. Your two tests are unchanged and still pass.

Tested on the worker. clipboard-test.sh fails on quattro (watched text killed by the outer guard), fails on 0a9d2c4 (records "first half "), and passes 84/84 on b147c75. ./test/cli is green. ./test/shell shows 2909 passed and 2 failed, ascii-test.sh and branding-about-animation-test.sh, and both fail the same way on quattro on that worker, so this change doesn't cause them. I linked the branch into the worker's running shell and copied text before and after freezing a real wl-copy owner. Both copies were recorded and no temporary files were left behind. The freeze didn't reliably catch the owner mid-transfer, though, so the stall itself is proven by the tests, not by that run.

Second opinion. Codex at medium effort reviewed the change. It found no defect in the stdin bound or the tests, and its agreement there is not independent: it can read this session's work. It also raised something I had not reasoned about: when --list-types times out, the x-kde-passwordManagerHint check at line 15 sees no types. That does not let a password through. wl-clipboard 2.3.0 sets CLIPBOARD_STATE=sensitive from the same offer it pipes to the watcher (src/wl-paste.c L101–110, L331–335), and in snapshot mode an empty type list reads nothing. Given that source, it withdrew the finding, and its second round was clean.

For the maintainer. One trade-off to decide: the two-second limit covers the whole read, so a large image that is still streaming after two seconds is now dropped from history instead of recorded. The clipboard itself is untouched. The snapshot image read already had this limit. #11920 (an enhancement rewriting capture.sh with a 10-second read limit and size limits) overlaps the same lines, so whichever lands second will need rebasing. This fixes #9443 and waits on the maintainer. Nothing is needed from you.

@greptile-apps

greptile-apps Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 3/5

[Medium risk] Adds timeout protection to clipboard capture operations.

The PR is not safe to merge until a timed-out MIME query cannot bypass password-manager-hint suppression.

Findings

  1. P1 Security Password hint can be bypassed ▶
  2. P2 Interrupted captures leave text behind ▶

Summary

The PR bounds clipboard MIME queries and payload reads, stages captures in temporary files, and adds deterministic stall tests. The timed-out MIME query needs a fail-closed path for password-manager-hinted watched items, and text temporary files need interruption-safe handling.

Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Watched clipboard text] --> B[Bounded MIME query]
  B -->|times out; types empty| C[Hint check misses marker]
  C --> D[Read watched stdin]
  D --> E[Save JSON to clipboard history]
Loading

Reviews (1) · Last reviewed commit: "Bound the watched clipboard read and dro..."

mkdir -p "$IMAGE_DIR"

types=$(wl-paste --list-types 2>/dev/null || true)
types=$(timeout 2s wl-paste --list-types 2>/dev/null || true)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 security Password hint can be bypassed

If a clipboard item carries x-kde-passwordManagerHint, CLIPBOARD_STATE is unset, and --list-types takes more than two seconds, the timeout leaves types empty. The hint check then misses the marker, while the watched-text branch still reads stdin and emits JSON. Password-manager text can be saved to clipboard history.

How this was verified: The timed-out MIME result feeds the hint check, while the watched-text branch emits its stdin payload regardless of that result.

}

emit_text() {
tmp=$(mktemp --tmpdir="$STATE_DIR" clipboard.XXXXXX) || return 0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Interrupted captures leave text behind

Text is now written to a temporary file in the state directory, but cleanup relies on an EXIT trap. If the capture process is forcibly terminated while reading, the file can remain on disk with raw clipboard text. This adds a non-blocking cleanup and privacy concern; handle interruption cleanup or avoid staging text on disk.

@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed b147c75 against current quattro and checked both Greptile findings. No code changes were needed; the PR description now matches the watched-stdin fix.

On a disposable worker built from the Omarchy ISO, an independent producer kept its payload pipe open. Text and image capture hung on quattro, exited in about two seconds on this head without recording partial data, and accepted the next copy. All 84 clipboard checks pass. This reproduces the blocked-pipe mechanism behind #9443, rather than the reporter’s intermittent compositor race.

Greptile’s password warning does not apply: wl-clipboard exports CLIPBOARD_STATE=sensitive from the payload’s own offer. With real wl-paste --watch, wl-copy --sensitive, and a deliberately timed-out MIME query, sensitive text emitted nothing and the next ordinary copy was recorded. A snapshot with no MIME types reads no payload.

The temporary-file finding is a real, nonblocking limitation. A force-killed capture can leave an owner-only (0600) text file; normal completion and timeout cleanup pass. Codex Medium identified destruction of the startup snapshot’s Quickshell Process as a possible forced-kill path. I checked the destructor and reproduced retention with SIGKILL, which a signal trap cannot handle.

The current-quattro integration run of ./test/all reports 4,642 passed and four failures: ascii-test.sh, branding-about-animation-test.sh, launch-browser-test.sh, and passwordless-grant-lifecycle-test.sh. All four fail the same way on unmodified current quattro. The screenshot check passes on the integration tree; its failure on the PR’s older tree is resolved by existing base-branch changes. Two unrelated checks were skipped by the suite (brightness-display-apple-cache-test.sh and kitty-config-test.sh); no clipboard checks were skipped. GitHub CI is green and the PR merges cleanly.

Codex Medium’s second opinion found no merge blockers; its agreement is not guaranteed to be independent. One review round completed within a three-round bound.

A legitimate transfer taking over two seconds is omitted from history; the clipboard itself is unchanged. #11920 overlaps this file and must account for this fix if it lands later. Nothing remains for the author; this waits on the maintainer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working verified Omarchy Triage has verified that this issue is ready for final review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stuck capture.sh silently stops text clipboard history (no timeout on wl-paste)

5 participants