You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ASan: SEGV in X11 hotkey thread (keycode_pressed) on shutdown — NULL xcb_query_keymap reply #126
key_pressed only checks error after xcb_query_keymap_reply(). When the X connection is closed or broken, xcb returns a NULL reply with no error, and keycode_pressed() reads reply->keys[...] from NULL. The fault address 0xe is offsetof(keys) + code/8.
Repro
Built with -fsanitize=address,undefined, run under Xvfb, send SIGINT after ~45 s (normal shutdown). The crash hit after ==== Shutting down ====: the hotkey thread was still polling while the X connection was being torn down. Disconnecting the X server while OBS runs triggers it too.
Harness: nix-shell rust/tools/sanitize/shell.nix --run 'rust/tools/sanitize/sanitize.sh asan' (in the sanitize branch; not yet merged).
Fix
Treat a NULL reply as "not pressed" (if (!reply) { free(error); return false; }), and stop the hotkey thread before the frontend's X display goes away. RED test first per testing-policy.md.
Valgrind reproduces this independently, this time during startup rather than shutdown. The hotkey thread crashed while the main thread was still in Initializing OpenGL..., so it isn't only a teardown-ordering problem: any time the X connection returns a NULL keymap reply, the thread dies.
Process terminating with default action of signal 11 (SIGSEGV)
Access not within mapped region at address 0xC
at keycode_pressed (obs-nix-x11.c:1048)
by key_pressed (obs-nix-x11.c:1068)
by obs_nix_x11_hotkeys_platform_is_pressed (obs-nix-x11.c:1087)
by obs_hotkeys_platform_is_pressed (obs-nix.c:407)
by is_pressed (obs-hotkey.c:1008)
by query_hotkeys (obs-hotkey.c:1144)
by obs_hotkey_thread (obs-hotkey.c:1176)
Debug build, valgrind --leak-check=full --track-origins=yes, Xvfb, QT_ENABLE_REGEXP_JIT=0. Apart from this, valgrind found no invalid reads, invalid writes or uninitialized-value errors in OBS code during the launch, and all its unit tests were clean.
ASan+UBSan: libobs/obs-nix-x11.c:1048:21: runtime error: member access within null pointer of type 'struct xcb_query_keymap_reply_t', after ==== Shutting down ====.
TSan: ERROR: ThreadSanitizer: SEGV on unknown address 0x00000000000e at keycode_pressed obs-nix-x11.c:1048, after shutdown began.
valgrind: SIGSEGV at the same frame.
Each time the process then hung and was SIGKILLed. Fixing this unblocks leak checking (LSan and valgrind's leak report) for the launch.
Activity
zackees commentedon Oct 10, 2026
Valgrind reproduces this independently, this time during startup rather than shutdown. The hotkey thread crashed while the main thread was still in
Initializing OpenGL..., so it isn't only a teardown-ordering problem: any time the X connection returns a NULL keymap reply, the thread dies.Debug build,
valgrind --leak-check=full --track-origins=yes, Xvfb,QT_ENABLE_REGEXP_JIT=0. Apart from this, valgrind found no invalid reads, invalid writes or uninitialized-value errors in OBS code during the launch, and all its unit tests were clean.zackees commentedon Oct 11, 2026
The CI run of the sanitizer workflow (https://github.com/obs-rust/obs-studio/actions/runs/38097738155, ubuntu-26.04) hit this in all three passes:
libobs/obs-nix-x11.c:1048:21: runtime error: member access within null pointer of type 'struct xcb_query_keymap_reply_t', after==== Shutting down ====.ERROR: ThreadSanitizer: SEGV on unknown address 0x00000000000eatkeycode_pressed obs-nix-x11.c:1048, after shutdown began.Each time the process then hung and was SIGKILLed. Fixing this unblocks leak checking (LSan and valgrind's leak report) for the launch.
zackees commentedon Oct 11, 2026
Claiming. Plan: move the keymap bit test into a tiny xcb-only helper, RED cmocka test with a NULL reply, then GREEN treats NULL as not pressed.
test: Fail the X11 keymap bit test on a NULL reply (RED)
libobs: Treat a NULL X11 keymap reply as nothing pressed (GREEN)