diff --git a/src/ljson.hpp b/src/ljson.hpp index 5dcf59d4e..5dbc8246c 100644 --- a/src/ljson.hpp +++ b/src/ljson.hpp @@ -76,7 +76,9 @@ static soup::UniquePtr checkJson(lua_State* L, int i) while (lua_next(L, -2)) { lua_pushvalue(L, -2); + luaE_incCstack(L); arr->children.emplace_back(checkJson(L, -2)); + L->nCcalls--; lua_pop(L, 2); } lua_pop(L, 1); diff --git a/testes/pluto/basic.pluto b/testes/pluto/basic.pluto index 703015c1f..75b4837f4 100644 --- a/testes/pluto/basic.pluto +++ b/testes/pluto/basic.pluto @@ -1577,13 +1577,23 @@ do local function recursive_enc() local t = {} t.t = t - try - return require"json".encode(t) - catch e then - return e + return require"json".encode(t) + end + assert(select(2, pcall(recursive_enc)) == "C stack overflow") + + local function overflow_enc() + local root = {} + do + local prev_t = root + for i = 1, 10000 do + local t = {} + prev_t:insert(t) + prev_t = t + end end + return require"json".encode(root) end - assert(recursive_enc() == "C stack overflow") + assert(select(2, pcall(overflow_enc)) == "C stack overflow") end do local xml = require "pluto:xml"