Skip to content

Commit 72f6536

Browse files
committed
Check table requested capacity limits before enabling unprotected mode.
Lua tables have limits and can overflow, which must be captured in protected mode.
1 parent 646827a commit 72f6536

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/util/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl Drop for StackGuard {
8888
#[inline(always)]
8989
pub(crate) unsafe fn push_string(state: *mut ffi::lua_State, s: &[u8], protect: bool) -> Result<()> {
9090
// Always use protected mode if the string is too long
91-
if protect || s.len() > (1 << 30) {
91+
if protect || s.len() >= const { 1 << 30 } {
9292
protect_lua!(state, 0, 1, |state| {
9393
ffi::lua_pushlstring(state, s.as_ptr() as *const c_char, s.len());
9494
})
@@ -122,7 +122,7 @@ pub(crate) unsafe fn push_table(
122122
) -> Result<()> {
123123
let narr: c_int = narr.try_into().unwrap_or(c_int::MAX);
124124
let nrec: c_int = nrec.try_into().unwrap_or(c_int::MAX);
125-
if protect {
125+
if protect || narr >= const { 1 << 30 } || nrec >= const { 1 << 27 } {
126126
protect_lua!(state, 0, 1, |state| ffi::lua_createtable(state, narr, nrec))
127127
} else {
128128
ffi::lua_createtable(state, narr, nrec);

0 commit comments

Comments
 (0)