fix loading lumps with -file command (#1357)

Sometimes the `FileContainsMaps` function tries to allocate too much memory.

* add checks for "IWAD" and "PWAD"
This commit is contained in:
Roman Fomin 2023-12-29 21:06:02 +07:00 committed by GitHub
parent fc9731ffa0
commit 8b487b1ced
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -864,9 +864,12 @@ static void CheckIWAD(const char *iwadname)
return;
}
if (strncmp(header.identification, "IWAD", 4))
if (strncmp(header.identification, "IWAD", 4) ||
strncmp(header.identification, "PWAD", 4))
{
I_Printf(VB_WARNING, "CheckIWAD: IWAD tag not present %s", iwadname);
fclose(file);
I_Error("Wad file %s doesn't have IWAD or PWAD id\n", iwadname);
return;
}
// read IWAD directory
@ -937,7 +940,7 @@ static boolean FileContainsMaps(const char *filename)
while (ret == false)
{
if (filename == NULL)
if (filename == NULL || M_StringCaseEndsWith(filename, ".wad") == false)
{
break;
}
@ -954,6 +957,12 @@ static boolean FileContainsMaps(const char *filename)
break;
}
if (strncmp(header.identification, "IWAD", 4) ||
strncmp(header.identification, "PWAD", 4))
{
break;
}
header.numlumps = LONG(header.numlumps);
header.infotableofs = LONG(header.infotableofs);
fileinfo = malloc(header.numlumps * sizeof(filelump_t));