Skip to content

bug: libobs: a keymap xkbcommon can't compile crashes OBS on Wayland #2975

Closed

Description

@rdoupe

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_string returns NULL (a keymap this libxkbcommon can't compile, for example one using syntax newer than the installed library), xkb_state_new(NULL) and xkb_keymap_key_for_each(NULL, ...) dereference it and OBS crashes;
  • ignores format. With WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP the 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_context without 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.

Activity

  1. added
    bug
    on Oct 30, 2026
  2. rdoupe commented on Oct 30, 2026

    @rdoupe
    CollaboratorAuthor

    Claiming: #2975.

    1. RED: a new cmocka test, 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 a no_keymap one, expecting no crash and the good keymap kept. Cases for an uncompilable first keymap and for no xkb context.
    2. GREEN: in platform_keyboard_keymap(), ignore any format but XKB_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.

  3. added
    ready
    on Oct 30, 2026
  4. rdoupe commented on Oct 30, 2026

    @rdoupe
    CollaboratorAuthor

    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 new test_wayland_keymap covers 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugready

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions