Add few checks to prevent game crashing if netgame archive becomes corrupted

This commit is contained in:
indev authored and Alug committed 2024-10-12 22:10:48 +02:00
1 parent 55248e7fcf
commit 210d6ac8ac
1 file changed
+21 -1
+21 -1
View File
@@ -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);