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
A panic in the Lua::exec_raw closure unwinds through lua_pcall and leaves a dangling error handler (segfault) #762
Lua::exec_raw has no # Safety section, but the closure it takes runs inside lua_pcall through an extern "C-unwind" trampoline (protect_lua_closure, whose comment says the function must not panic). If the closure panics, the panic unwinds through Lua's C frames, which restore nothing. L->errorJmp keeps pointing at the jump buffer of the unwound luaD_rawrunprotected frame. When exec_raw runs inside a Rust callback, mlua catches the panic and raises it with lua_error, which then longjmps into the dead frame.
With vendored Lua built in release under AddressSanitizer:
thread 'main' panicked at src/main.rs:9:48:
closure panicked
==265530==ERROR: AddressSanitizer: SEGV on unknown address (pc 0x7f95369f9110 bp 0xe0b4cfd1ca92a58b sp 0x35c0cfd1deaaa22a T0)
Without the sanitizer it segfaults. Reproduced on mlua 0.12.2 and on master at a0ad453, with Lua 5.5.1 (vendored, lua55) and rustc 1.102.0-nightly (8eb778d04 2026-11-12), on x86_64 Linux.
A possible fix: catch the panic inside the trampoline, return normally to lua_pcall and resume the unwind after it returns. Also document exec_raw's safety requirements.
Found by Crustify, an experimental UB/soundness auditing agent developed at UC Berkeley and running on Claude Opus 5.5, then manually reviewed and independently reproduced.
Activity