Lower fastpath table creation limit to 1 << 26

When Lua is configured without memory restrictions, we use fastpath for table creation (unprotected mode).
In generally it's safe as long as we `abort()` on allocation failure.
However some Lua versions have additional restrictions on table size that we need to adhere in mlua too.
Probably Luau has the lowest limits.
Fixes #627
This commit is contained in:
Alex Orlenko
2025-08-13 22:49:40 +01:00
parent 3516f4c6ca
commit f0806a6d62
2 changed files with 10 additions and 1 deletions
+1 -1
View File
@@ -122,7 +122,7 @@ pub(crate) unsafe fn push_table(
) -> Result<()> {
let narr: c_int = narr.try_into().unwrap_or(c_int::MAX);
let nrec: c_int = nrec.try_into().unwrap_or(c_int::MAX);
if protect || narr >= const { 1 << 30 } || nrec >= const { 1 << 27 } {
if protect || narr >= const { 1 << 26 } || nrec >= const { 1 << 26 } {
protect_lua!(state, 0, 1, |state| ffi::lua_createtable(state, narr, nrec))
} else {
ffi::lua_createtable(state, narr, nrec);
+9
View File
@@ -61,6 +61,15 @@ fn test_table() -> Result<()> {
Ok(())
}
#[test]
#[cfg(target_os = "linux")] // Linux allow overcommiting the memory (relevant for CI)
fn test_table_with_large_capacity() {
let lua = Lua::new();
let t = lua.create_table_with_capacity(1 << 26, 1 << 26);
assert!(t.is_ok());
}
#[test]
fn test_table_push_pop() -> Result<()> {
let lua = Lua::new();