commit d3c8f7316df2491ce3bb1244f22defdb745cc418
Author: Jonathan Dowland <jon+github@alcopop.org>
AuthorDate: Mon Jul 18 09:14:30 2016 +0100
Commit: Jonathan Dowland <jon+github@alcopop.org>
CommitDate: Mon Jul 18 09:38:07 2016 +0100
Implement Vanilla limit of 4046 lumps in a WAD
Thanks Quasar et al for discovering and investigating the limit and
edward-san for most of this patch.
Fixes #430
---
src/w_wad.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/src/w_wad.c b/src/w_wad.c
index 6f0bc58f..8eed5942 100644
--- a/src/w_wad.c
+++ b/src/w_wad.c
@@ -169,6 +169,7 @@ wad_file_t *W_AddFile (char *filename)
// Homebrew levels?
if (strncmp(header.identification,"PWAD",4))
{
+ W_CloseFile(wad_file);
I_Error ("Wad file %s doesn't have IWAD "
"or PWAD id\n", filename);
}
@@ -177,6 +178,16 @@ wad_file_t *W_AddFile (char *filename)
}
header.numlumps = LONG(header.numlumps);
+
+ // Vanilla Doom doesn't like WADs with more than 4046 lumps
+ // https://www.doomworld.com/vb/post/1010985
+ if (!strncmp(header.identification,"PWAD",4) && header.numlumps > 4046)
+ {
+ W_CloseFile(wad_file);
+ I_Error ("Error: Vanilla limit for lumps in a WAD is 4046, "
+ "PWAD %s has %d", filename, header.numlumps);
+ }
+
header.infotableofs = LONG(header.infotableofs);
length = header.numlumps*sizeof(filelump_t);
fileinfo = Z_Malloc(length, PU_STATIC, 0);
@@ -189,6 +200,7 @@ wad_file_t *W_AddFile (char *filename)
filelumps = calloc(numfilelumps, sizeof(lumpinfo_t));
if (filelumps == NULL)
{
+ W_CloseFile(wad_file);
I_Error("Failed to allocate array for lumps from new file.");
}
@@ -197,6 +209,7 @@ wad_file_t *W_AddFile (char *filename)
lumpinfo = realloc(lumpinfo, numlumps * sizeof(lumpinfo_t *));
if (lumpinfo == NULL)
{
+ W_CloseFile(wad_file);
I_Error("Failed to increase lumpinfo[] array size.");
}