JSON encoding large nested table causes crash

Running the following code in the Studio command bar causes a crash. The crash seems to happen 100% of the time.

local nestedTable = {}

local t = nestedTable

for i = 1, 1000 do
	t[1] = {}
	t = t[1]
end

print(game:GetService("HttpService"):JSONEncode(nestedTable))

image

19 Likes

Just tested in Studio, also crashes for me.

3 Likes

Looks like it crashes at 606 (you can nest 605 and it will work).

To be fair, I can’t imagine any situation where you’d have a depth of over 600 in any JSON structure. If so, I’d point to bad design. Regardless, Studio should be able to avoid a crash with this.

Looking into the logs, I see this:

Exception Code: 0xC00000FD
Exception Information: The thread used up its stack.

So I’m assuming that’s a stack-overflow essentially?

Edit: Yeah, this is a stack-overflow error according to this page based on that exception code above.

5 Likes

Thanks for the repro steps. We have ticketed this issue and are looking into it.

5 Likes