Repository navigation
Description
Location
libobs/obs-nix-wayland.c.h, platform_keyboard_keymap() (lines 86-111 on master), the wl_keyboard.keymap handler of the Wayland hotkey platform:
struct xkb_keymap *xkb_keymap = xkb_keymap_new_from_string(
plat->xkb_context, keymap_shm, XKB_KEYMAP_FORMAT_TEXT_V1, XKB_KEYMAP_COMPILE_NO_FLAGS);
munmap(keymap_shm, size);
close(fd);
// cleanup old keymap and state
xkb_keymap_unref(plat->xkb_keymap);
xkb_state_unref(plat->xkb_state);
plat->xkb_keymap = xkb_keymap;
plat->xkb_state = xkb_state_new(xkb_keymap);
rebuild_keymap_data(plat);Class
NULL dereference (crash)
How it is reached
The compositor sends wl_keyboard.keymap when OBS takes the seat's keyboard at startup, and again on every layout change. The handler:
- drops the old keymap and state before it checks the new one. When
xkb_keymap_new_from_stringreturns NULL (a keymap this libxkbcommon can't compile, for example one using syntax newer than the installed library),xkb_state_new(NULL)andxkb_keymap_key_for_each(NULL, ...)dereference it and OBS crashes; - ignores
format. WithWL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAPthe fd's contents are meaningless, yet they are compiled as an XKB keymap, which fails the same way (or replaces a good keymap with whatever the fd holds); - compiles against
plat->xkb_contextwithout checking it.xkb_context_new()returns NULL when libxkbcommon finds no keyboard data (the situation of appimage: crashes at start on NixOS Wayland: bundled libxkbcommon finds no keyboard data (/usr/share/X11/xkb) #2437), and compiling against a NULL context crashes too.
Not reported by a user; found reading the code. No upstream issue.
Proposed fix and failing test
Fix: ignore a keymap whose format isn't WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1 (closing its fd), and when there is no xkb context or compilation fails, keep the previous keymap and state and log a warning. Hotkeys then keep working with the last good layout, or stay off when there never was one, instead of taking OBS down.
Test (RED, then GREEN): a new cmocka test, test_wayland_keymap, that compiles in the real Wayland hotkey platform and hands its keymap handler a keymap through a memfd, as the compositor does. After a good keymap (<AC01> is a), it sends one that doesn't compile, then a no_keymap one whose fd holds a keymap with b, and expects no crash and <AC01> still a. Further cases: an uncompilable first keymap, and a keymap with no xkb context, both leave hotkeys without a keymap and don't crash. On master the first case crashes in xkb_state_new.
Metadata
Metadata
Assignees
Type
Projects
- StatusShow more project fieldsDone
Activity
rdoupe commentedon Oct 30, 2026
Claiming: #2975.
test_wayland_keymap, that compiles in the real Wayland hotkey platform and feeds its keymap handler through a memfd: a good keymap, then one that doesn't compile, then ano_keymapone, expecting no crash and the good keymap kept. Cases for an uncompilable first keymap and for no xkb context.platform_keyboard_keymap(), ignore any format butXKB_V1, and keep the old keymap and state (with a warning) when there is no context or the new keymap doesn't compile.One PR; a draft opens with the RED commit today.
test: Keep the Wayland keymap when one won't load
libobs: Keep the Wayland keymap if one won't load
rdoupe commentedon Oct 30, 2026
Fixed by the PR that keeps the Wayland keymap when one won't load (PR #2976, merged as 055f9fe).
platform_keyboard_keymap()now ignores any keymap format but XKB_V1 and does nothing without an xkb context, and when compilation fails it keeps the previous keymap and state and logs a warning, so OBS no longer crashes. The newtest_wayland_keymapcovers all three cases.Nothing is left of this issue, so there is no follow-up issue. Upstream OBS has the same handler; no upstream issue exists for it.
libobs: Keep the Wayland keymap if one won't load (obs-rust#2976)