From a016d142e8e11f73f4d91ccec2907998f4c53cbe Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 24 Mar 2023 16:45:08 +1100 Subject: [PATCH] Fix #106040: pasting long text fails in Gnome-Shell/Wayland Workaround gnome-shell including uninitialized memory when pasting from the clipboard. Where `read` woud Reading from the pipe into a power-of-two buffer works around the problem. It's not clear why this only impacts gnome-shell - as there is no significant down-side to changing the buffer size, apply a workaround. --- intern/ghost/intern/GHOST_SystemWayland.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/intern/ghost/intern/GHOST_SystemWayland.cpp b/intern/ghost/intern/GHOST_SystemWayland.cpp index 0d50a5b72df..e9225a3d937 100644 --- a/intern/ghost/intern/GHOST_SystemWayland.cpp +++ b/intern/ghost/intern/GHOST_SystemWayland.cpp @@ -2016,7 +2016,13 @@ static char *read_file_as_buffer(const int fd, const bool nil_terminate, size_t { struct ByteChunk { ByteChunk *next; - char data[4096 - sizeof(ByteChunk *)]; + /* NOTE(@ideasman42): On GNOME-SHELL-43.3, non powers of two values + * (1023 or 4088 for e.g.) makes `read()` return longer values than are actually read + * (causing uninitialized memory to be used) as well as truncating the end of the buffer. + * The WAYLAND spec doesn't mention buffer-size so this may be a bug in GNOME-SHELL. + * Whatever the case, using a power of two isn't a problem (besides some slop-space waste). + * This works in KDE & WLROOTS based compositors, see: #106040. */ + char data[4096]; }; ByteChunk *chunk_first = nullptr, **chunk_link_p = &chunk_first; bool ok = true;