diff --git a/src/lua_script.c b/src/lua_script.c index c6df314d4..8015e75f3 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -1333,6 +1333,9 @@ static UINT8 UnArchiveValue(int TABLESINDEX) break; case ARCH_TEND: return 1; + default: + CONS_Alert(CONS_ERROR, "Unknown value type unarchived, save is corrupted!\n"); + return 1; } return 0; } @@ -1530,12 +1533,29 @@ static void UnArchiveTables(void) for (i = 1; i <= n; i++) { lua_rawgeti(gL, TABLESINDEX, i); + + if (!lua_istable(gL, -1)) + { + CONS_Alert(CONS_ERROR, "Value in tables list #%d is not a table! (corrupted save?)\n", i); + continue; + } + while (true) { if (UnArchiveValue(TABLESINDEX) == 1) // read key break; - if (UnArchiveValue(TABLESINDEX) == 2) // read value + + UINT8 ret = UnArchiveValue(TABLESINDEX); + + if (ret == 1) + { + CONS_Alert(CONS_ERROR, "Unexpected end of save reached (Corrupted save?)\n"); + lua_pop(gL, 1); // Pop key + break; + } + else if (ret == 2) // read value n++; + if (lua_isnil(gL, -2)) // if key is nil (if a function etc was accidentally saved) { CONS_Alert(CONS_ERROR, "A nil key in table %d was found! (Invalid key type or corrupted save?)\n", i);