mlua-rs/rlua

Crash on empty source

xNxExOx opened this issue · 2 comments

moinimal example:

let file = ""; // loaded from actual file, but that file can by empty
// ...
        lua.context(|state|{
            state.load(file.as_bytes())
                .exec()
        })?;

produces this error:

thread 'main' panicked at 'rlua internal error: 1 too many stack values popped (this is a bug, please file an issue)', .cargo\registry\src\index.crates.io-6f17d22bba15001f\rlua-0.19.5\src\util.rs:59:17
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library\std\src\panicking.rs:593
   1: core::panicking::panic_fmt
             at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library\core\src\panicking.rs:67
   2: rlua::util::impl$1::drop
             at .cargo\registry\src\index.crates.io-6f17d22bba15001f\rlua-0.19.5\src\util.rs:59
   3: core::ptr::drop_in_place
             at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be\library\core\src\ptr\mod.rs:497
   4: rlua::context::Context::load_chunk
             at .cargo\registry\src\index.crates.io-6f17d22bba15001f\rlua-0.19.5\src\context.rs:902
   5: rlua::context::Chunk::into_function
             at .cargo\registry\src\index.crates.io-6f17d22bba15001f\rlua-0.19.5\src\context.rs:988
   6: rlua::context::Chunk::call
             at .cargo\registry\src\index.crates.io-6f17d22bba15001f\rlua-0.19.5\src\context.rs:981
   7: rlua::context::Chunk::exec
             at .cargo\registry\src\index.crates.io-6f17d22bba15001f\rlua-0.19.5\src\context.rs:950
   8: script_validator::validate_with_lua::closure$0

Easy workaround for me is just wrap it with if !file.is_empty(), so not an critical issue for me.

Thanks for the report.
This seems to work on Lua 5.4 (the default) but does indeed panic with Lua 5.1 as above. I'll look into it, thanks!

I believe I've got a fix for the issue: #284