From 8b487b1ced8bc5d4de0f9343622ddefaaa126e14 Mon Sep 17 00:00:00 2001 From: Roman Fomin Date: Fri, 29 Dec 2023 21:06:02 +0700 Subject: [PATCH] fix loading lumps with -file command (#1357) Sometimes the `FileContainsMaps` function tries to allocate too much memory. * add checks for "IWAD" and "PWAD" --- src/d_main.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 67828e4b..1542a842 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -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));