From 8faf8490e518315a8eff17a76b019debe48104b4 Mon Sep 17 00:00:00 2001 From: Mark Pulford Date: Tue, 17 Jan 2012 23:28:10 +1030 Subject: Fix Lua C function stack overflow during encoding Ensure there are enough Lua stack slots available before descending into another table during encoding. This fixes a segfault when encoding deeply nested tables. This bug wasn't noticed earlier due to the previous limit of 20 nested tables. --- tests/test.lua | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'tests') diff --git a/tests/test.lua b/tests/test.lua index a827e6a..4c00453 100755 --- a/tests/test.lua +++ b/tests/test.lua @@ -67,6 +67,12 @@ function load_testdata() data.table_cycle = {} data.table_cycle[1] = data.table_cycle + local big = {} + for i = 1, 1100 do + big = { { 10, false, true, cjson.null }, "string", a = big } + end + data.deeply_nested_data = big + return data end @@ -185,6 +191,9 @@ local cjson_tests = { false, { "Cannot serialise, excessive nesting (6)" } }, { "Set encode_max_depth(1000)", json.encode_max_depth, { 1000 }, true, { 1000 } }, + { "Encode deeply nested data [throw error]", + json.encode, { testdata.deeply_nested_data }, + false, { "Cannot serialise, excessive nesting (1001)" } }, -- Test encoding simple types { "Encode null", -- cgit v1.2.3