From b777cae2fe8be4c7e3fcd7561dbb912187c41cca Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Mon, 9 Jun 2014 17:20:31 -0700 Subject: [PATCH] Fix crash on invalid extradata from automation --- src/auto4_lua_assfile.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/auto4_lua_assfile.cpp b/src/auto4_lua_assfile.cpp index 1eea59131..008389315 100644 --- a/src/auto4_lua_assfile.cpp +++ b/src/auto4_lua_assfile.cpp @@ -297,16 +297,18 @@ namespace Automation4 { dia->Effect = get_string_field(L, "effect", "dialogue"); dia->Text = get_string_field(L, "text", "dialogue"); - lua_getfield(L, -1, "extra"); std::vector new_ids; - lua_pushnil(L); - while (lua_next(L, -2)) { - auto key = get_string_or_default(L, -2); - auto value = get_string_or_default(L, -1); - new_ids.push_back(ass->AddExtradata(key, value)); - lua_pop(L, 1); - } - lua_pop(L, 1); + + lua_getfield(L, -1, "extra"); + auto type = lua_type(L, -1); + if (type != LUA_TNIL && type != LUA_TTABLE) + error(L, "dialogue extradata must be a table"); + lua_for_each(L, [&] { + if (lua_type(L, -2) != LUA_TSTRING) return; + new_ids.push_back(ass->AddExtradata( + get_string_or_default(L, -2), + get_string_or_default(L, -1))); + }); dia->ExtradataIds = new_ids; } else {