Wayland: a key whose text needs 16 bytes or more reaches onTextInput cut inside a character and padded with NULs #205
Labels
No labels
claude:blocked
claude:done
claude:failed
claude:in-progress
claude:ready
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Catcrafts/Crafter.Graphics#205
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Device::keyboard_keyasks libxkbcommon for a key's text in a 16-byte buffer, and then keeps as many bytes as the call says the text needs, not as many as it wrote. For a text of 16 bytes or more,onTextInputand the key's repeats get the first 15 bytes, cut wherever they end (inside a UTF-8 sequence too), followed by NULs up to the length the call returned. Line numbers refer to148ed01.Details
implementations/Crafter.Graphics-Device.cpp:769-776:buf.resize(16),n = xkb_state_key_get_utf8(xkb_state, xkbKeycode, buf.data(), 16), and forn > 0with a first byte that is no control characterbuf.resize(n),utf8 = bufandonTextInput.Invoke(utf8). The repeat keeps the same string (:783), andTickKeyRepeatssends it again with every repeat (:846-847).xkb_state_key_get_utf8returns "the number of bytes required for the string, excluding theNULLbyte", truncates into a buffer that is too small "(though stillNULL-terminated)", and says to check for truncation by comparing the return value with the buffer's size, "similarly to thesnprintf(3)function" (/usr/include/xkbcommon/xkbcommon.h, libxkbcommon 1.13.2).xkb_state_key_get_symsin the same header).Concrete case
A keymap whose
<AC01>has one level of five keysyms,[ { U1F600, U1F601, U1F602, U1F603, U1F604 } ], compiled and queried with libxkbcommon 1.13.2 in a standalone program:xkb_state_key_get_symsgives 5 keysyms,xkb_state_key_get_utf8(state, 38, NULL, 0)gives 20, and into a 16-byte buffer it writesf0 9f 98 80 f0 9f 98 81 f0 9f 98 82 f0 9f 98 00and returns 20. With that,keyboard_keypasses on 20 bytes: three emoji, the first three bytes of the fourth, and five NULs. Not run through the library.Suggested fix
Ask for the length first (
xkb_state_key_get_utf8(state, key, nullptr, 0)), make the string that long, and fill it with a second call given that length plus one. Or keep the 16 bytes and treat a return value of 16 or more as no text.