SUMMARY When calling Clipboard.SelectionWrite, whatever I am writing into the FD will get repeated in the clipboard (seemingly arbitrarily) many times. STEPS TO REPRODUCE 1. Call Clipboard.SelectionWrite("ab") 2. Paste inside remote session OBSERVED RESULT The clipboard contains "ab" repeated many times (~3k-100k times). EXPECTED RESULT The clipboard should contain "ab". SOFTWARE/OS VERSIONS Linux/KDE Plasma: Fedora 43 KDE Plasma Version: 6.5.1 KDE Frameworks Version: 6.19.0 Qt Version: 6.10.0 xdg-desktop-portal-kde-6.5.2-1 (+ patch https://invent.kde.org/plasma/xdg-desktop-portal-kde/-/commit/b7f2107d0eb35d2b4cfccf9ffaa91437b88eff0a) ADDITIONAL INFORMATION I was unsure if this had anything to do with a missing null-terminator. Here is some example code I used to test this: > int written; > int remaining; > const char* data; > > char s[] = { 97, 98, '\0' }; > remaining = 3; > data = s; > > while (remaining > 0) { > written = write(fd, data, remaining); > > if (written < 0) { > vlog.error("Error writing to fd: %s", strerror(errno)); > selectionWriteDone(serial, false); > g_object_unref(fdList); > close(fd); > return; > } > > remaining -= written; > data += written; > } > > if (close(fd) != 0) { > vlog.error("Failed to close fd: %s", strerror(errno)); > selectionWriteDone(serial, false); > } else { > selectionWriteDone(serial, true); > } If I include the null-terminator (remaining = 3) and try to paste into Konsole, I get a Confirm Paste warning with between ~3k and 100k characters of repeated "ab", and a warning about pasting hidden control characters U+0000. Pasting with the null character will simply paste "ab" to the terminal. If I don't include the null-terminator (remaining = 2), I still get the Confirm Paste warning with ~3-100k characters. Note that the number of characters printed (~3-100k) will differ between each paste, and not between every time I write to the clipboard.
Can you share a complete reproducer? I am testing with a python script that writes a string and dont get multiple characters.
I reproduced this while testing https://bugs.kde.org/show_bug.cgi?id=512075 If both text/plain and text/plain;charset=utf8 are advertised we end up with a weird situation sometimes: text/plain;charset=utf8 is advertised twice, one instance is normal the other one contains the data repeated a random amount of times.
Although I can only make it happen very rarely for some reason.
I see this issue when trying to implement Clipboard support for TigerVNC's w0vncserver [1]. [1] https://github.com/TigerVNC/tigervnc/pull/2012
Currently I am not sure what goes wrong, I supect maybe ksystemclipboard loops somehow due to the duplicated mime type https://invent.kde.org/frameworks/kguiaddons/-/merge_requests/188 fixes the duplicated mime type, maybe https://invent.kde.org/frameworks/kguiaddons/-/commit/20b032c87b8d15228d99d162818e51c216054010 is also related. I will try to test with your program.
Thanks for looking into this, really appreciate it. Let me know what I can do to help, or if you're having trouble with TigerVNC.
Embarassing bug our side https://invent.kde.org/plasma/xdg-desktop-portal-kde/-/merge_requests/485
Git commit e42937815cd6e81a062139cfa7fc6a6487c7e125 by David Redondo. Committed on 20/11/2025 at 07:48. Pushed by davidre into branch 'master'. clipboard: Dont append data on when read results in EAGAIN Otherwise QByteArray::append is called with a negative number which tries to find a null terminator in buffer. FIXED-IN:6.5.4 M +1 -1 src/clipboard.cpp https://invent.kde.org/plasma/xdg-desktop-portal-kde/-/commit/e42937815cd6e81a062139cfa7fc6a6487c7e125
Git commit ef7fbf3004e5827f4668658a7b19889941adb8dd by David Redondo. Committed on 20/11/2025 at 07:56. Pushed by davidre into branch 'Plasma/6.5'. clipboard: Dont append data on when read results in EAGAIN Otherwise QByteArray::append is called with a negative number which tries to find a null terminator in buffer. FIXED-IN:6.5.4 (cherry picked from commit e42937815cd6e81a062139cfa7fc6a6487c7e125) Co-authored-by: David Redondo <kde@david-redondo.de> M +1 -1 src/clipboard.cpp https://invent.kde.org/plasma/xdg-desktop-portal-kde/-/commit/ef7fbf3004e5827f4668658a7b19889941adb8dd
Just tested with your patch, works as expected! (In reply to David Redondo from comment #7) > Embarassing bug our side > https://invent.kde.org/plasma/xdg-desktop-portal-kde/-/merge_requests/485 Can't say I haven't done way worse, these things happen :^)