Setting a low memory limit via Lua::set_memory_limit can cause the auxiliary stack to fail to grow much earlier than it normally would, which causes a panic:
|
// It is a user error to create too many references to exhaust the Lua max stack size |
|
// for the ref thread. |
|
panic!("cannot create a Lua reference, out of auxiliary stack space (used {top} slots)"); |
If a memory limit is set, this panic can happen even when the user has not created enough references to exhaust Lua's max stack size. This could allow untrusted code to crash the host process by calling Rust code that needs to grow the auxiliary stack while close to a known memory limit. Ideally, growing the auxiliary stack would be a fallible operation that causes an error when memory limits are reached instead of panicking.
The current behavior makes memory limits significantly less useful, as they allow Lua code to crash the host process.
Setting a low memory limit via
Lua::set_memory_limitcan cause the auxiliary stack to fail to grow much earlier than it normally would, which causes a panic:mlua/src/state/extra.rs
Lines 293 to 295 in 4fd87af
If a memory limit is set, this panic can happen even when the user has not created enough references to exhaust Lua's max stack size. This could allow untrusted code to crash the host process by calling Rust code that needs to grow the auxiliary stack while close to a known memory limit. Ideally, growing the auxiliary stack would be a fallible operation that causes an error when memory limits are reached instead of panicking.
The current behavior makes memory limits significantly less useful, as they allow Lua code to crash the host process.