Add maximum recursion depth to read_json_value

This commit is contained in:
ShadowNinja 2014-01-11 14:08:02 -05:00
parent a9df87ede0
commit a3586cd18d
2 changed files with 7 additions and 3 deletions

@ -1088,8 +1088,11 @@ bool push_json_value(lua_State *L, const Json::Value &value, int nullindex)
} }
// Converts Lua table --> JSON // Converts Lua table --> JSON
void read_json_value(lua_State *L, Json::Value &root, int index) void read_json_value(lua_State *L, Json::Value &root, int index, u8 recursion)
{ {
if (recursion > 16) {
throw SerializationError("Maximum recursion depth exceeded");
}
int type = lua_type(L, index); int type = lua_type(L, index);
if (type == LUA_TBOOLEAN) { if (type == LUA_TBOOLEAN) {
root = (bool) lua_toboolean(L, index); root = (bool) lua_toboolean(L, index);
@ -1104,7 +1107,7 @@ void read_json_value(lua_State *L, Json::Value &root, int index)
while (lua_next(L, index)) { while (lua_next(L, index)) {
// Key is at -2 and value is at -1 // Key is at -2 and value is at -1
Json::Value value; Json::Value value;
read_json_value(L, value, lua_gettop(L)); read_json_value(L, value, lua_gettop(L), recursion + 1);
Json::ValueType roottype = root.type(); Json::ValueType roottype = root.type();
int keytype = lua_type(L, -1); int keytype = lua_type(L, -1);

@ -152,7 +152,8 @@ bool push_json_value (lua_State *L,
int nullindex); int nullindex);
void read_json_value (lua_State *L, void read_json_value (lua_State *L,
Json::Value &root, Json::Value &root,
int index); int index,
u8 recursion = 0);
extern struct EnumString es_TileAnimationType[]; extern struct EnumString es_TileAnimationType[];