Skip to content

Commit

Permalink
Fix C stack overflow with dumpvar/exportvar
Browse files Browse the repository at this point in the history
  • Loading branch information
Sainan authored and well-in-that-case committed Jan 22, 2025
1 parent 1d46d41 commit 21f85ab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/lbaselib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -692,13 +692,17 @@ static void luaB_dumpvar_impl (lua_State *L, int indents, std::unordered_set<Tab
dump.append(indents, '\t');
dump.push_back('[');
lua_pushvalue(L, -2);
luaE_incCstack(L);
luaB_dumpvar_impl(L, indents + 1, parents, is_export, true);
L->nCcalls--;
dump.append(lua_tostring(L, -1));
lua_pop(L, 2);
dump.append("] = ");

lua_pushvalue(L, -1);
luaE_incCstack(L);
luaB_dumpvar_impl(L, indents + 1, parents, is_export);
L->nCcalls--;
dump.append(lua_tostring(L, -1));
lua_pop(L, 2);
dump.append(",\n");
Expand Down
12 changes: 12 additions & 0 deletions testes/pluto/basic.pluto
Original file line number Diff line number Diff line change
Expand Up @@ -1598,6 +1598,18 @@ do
end
assert(select(2, pcall(overflow_enc)) == "C stack overflow")
end
do
local root = {}
do
local prev_t = root
for i = 1, 1000 do
local t = {}
prev_t:insert(t)
prev_t = t
end
end
assert(select(2, pcall(|| -> dumpvar(root))) == "C stack overflow")
end
do
local xml = require "pluto:xml"

Expand Down

0 comments on commit 21f85ab

Please sign in to comment.