CopyQ icon indicating copy to clipboard operation
CopyQ copied to clipboard

Clipboard monitor SIGSEGV x5 in one day: KSystemClipboard::changed → QMimeData::data → wl_proxy_marshal race (Wayland, KF6 6.29)

Open marktantongco opened this issue 2 months ago • 1 comments

Describe the bug

The clipboard monitor process (copyq --clipboard-access monitorClipboard) segfaulted 5 times in one day on Omarchy (Arch-based, Hyprland/Wayland). Every crash runs down the same call chain:

QEventLoop (glib main loop)
 └─ KSystemClipboard::changed(QClipboard::Mode)      ← KF6GuiAddons
     └─ QMimeData::data(QString)
         └─ KF6GuiAddons Wayland clipboard glue
             └─ wl_proxy_marshal_flags → libwayland-client  → SIGSEGV

Five crashes, 2026-09-24 (+08) — all the same command line, /usr/bin/copyq --clipboard-access monitorClipboard:

Time (+08) PID Signal Crash frame
13:31 513971 SEGV_MAPERR @ 0x1 QVariant copy ← KF6GuiAddons
18:17 735297 SEGV_MAPERR @ wild 0x23d00000090 KF6GuiAddons +0x3f029
18:47 869686 SEGV (SI_KERNEL) QVariant copy ← KF6GuiAddons
19:56 908800 SEGV (SI_KERNEL) QMimeData::data ← KSystemClipboard::changed
22:05:58 987792 SEGV_MAPERR @ 0x81 libwayland-client (wl_proxy_marshal)

Kernel messages confirm wildly varying fault addresses (0x1, 0x81, 0x23d00000090) with both error 4 (read) and error 6 (write) — the signature of dereferencing freed/reused memory rather than a stable null-pointer bug.

To Reproduce

Not deterministically reproducible — it is a race. It fired 5 times in ~9 hours of normal desktop use with heavy clipboard churn (many Chromium scopes starting/stopping). First crash (13:31) came ~70 minutes after copyq 16.0.0-1 was installed (12:18); no copyq crashes earlier that day.

Expected behavior

The clipboard monitor should not crash when clipboard ownership changes or the source application exits.

Version, OS and Environment

CopyQ Clipboard Manager 16.0.0
Qt: 6.11.2
OS: Arch Linux (Omarchy), Hyprland (Wayland)
kf6 kguiaddons: 6.29.0
wayland: 1.26.0

Additional context

Backtrace of the 22:05:58 crash (PID 987792), from coredumpctl info:

Stack trace of thread 987792:
#0  0x00007fc21b5a21a0 n/a (libwayland-client.so.0 + 0x31a0)
#1  0x00007fc21b5a25c6 n/a (libwayland-client.so.0 + 0x35c6)
#2  0x00007fc21b5a5522 wl_proxy_marshal_array_flags (libwayland-client.so.0 + 0x6522)
#3  0x00007fc21b5a650e wl_proxy_marshal_flags (libwayland-client.so.0 + 0x750e)
#4  0x00007fc21be1ba2b n/a (libKF6GuiAddons.so.6 + 0x36a2b)
#5  0x00007fc219bdbc36 n/a (libQt6Core.so.6 + 0x1dbc36)
#6  0x00007fc219bdcf5d _ZNK9QMimeData4dataERK7QString (libQt6Core.so.6 + 0x1dcf5d)
#7  0x00006132f0d46b31 n/a (copyq + 0x10bb31)
#8  0x00006132f0d4d744 n/a (copyq + 0x112744)
#9  0x00006132f0e6b206 n/a (copyq + 0x230206)
#10 0x00006132f0e6b8bc n/a (copyq + 0x2308bc)
#11 0x00007fc219beeff3 n/a (libQt6Core.so.6 + 0x1eeff3)
#12 0x00007fc21be08167 _ZN16KSystemClipboard7changedEN10QClipboard4ModeE (libKF6GuiAddons.so.6 + 0x23167)
...
#17 0x00007fc219e9a4b8 n/a (libQt6Core.so.6 + 0x49a4b8)   ← QEventDispatcherGlib
#20 0x00007fc219501055 g_main_context_iteration

Cross-thread evidence from the same core — a KF6GuiAddons QObject destructor runs inside Wayland event dispatch while the main thread simultaneously marshals a Wayland request:

Thread 3 (destroying a clipboard object inside Wayland dispatch):
#3  QObject::~QObject()
#4  n/a (libKF6GuiAddons.so.6)
#8  n/a (libwayland-client.so.0)        ← ffi_call from Wayland callback
#10 wl_display_dispatch_queue_pending
#11 n/a (libKF6GuiAddons.so.6)

Thread 1 (crashing — marshalling on the same connection):
#0  n/a (libwayland-client.so.0)        ← SEGV here
#2  wl_proxy_marshal_array_flags
#4  n/a (libKF6GuiAddons.so.6)
#6  QMimeData::data
#12 KSystemClipboard::changed

This looks like a use-after-free race between KF6GuiAddons' Wayland clipboard object teardown (triggered by clipboard ownership change / source app exit) and a mime-data read from CopyQ's changed() handler.

Ruled out: OOM (15 Gi RAM, 6.2 Gi available at crash time; no OOM-killer journal entries).

Note: copyq and KF6 internals above are unsymbolized (no debug symbols published); frame shape is unambiguous regardless. Related-but-distinct closed issues: #2151 (Qt5-era monitor crash on Plasma Wayland), #2997 (different stack, QScreen::availableGeometry). Five systemd-coredump cores are available on the reporting machine on request.

marktantongco avatar Sep 24 '26 14:09 marktantongco

Thanks for the report.

CopyQ itself does not use threads for the clipboard access. This looks like a bug in KF6GuiAddons. Do you have a suggestion how to fix this in CopyQ?

hluk avatar Sep 27 '26 05:09 hluk