shithub: choc

Download patch

ref: d3c8f7316df2491ce3bb1244f22defdb745cc418
parent: 3cf08f9fb0c92bb652f8ffd901d278c6aa5123be
author: Jonathan Dowland <[email protected]>
date: Mon Jul 18 05:14:30 EDT 2016

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

--- a/src/w_wad.c
+++ b/src/w_wad.c
@@ -169,6 +169,7 @@
 	    // 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 @@
 	}
 
 	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 @@
     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 @@
     lumpinfo = realloc(lumpinfo, numlumps * sizeof(lumpinfo_t *));
     if (lumpinfo == NULL)
     {
+        W_CloseFile(wad_file);
         I_Error("Failed to increase lumpinfo[] array size.");
     }