Added detection for broken WAD files

Do not try to allocate nonsensical amount of memory and bail out when broken WAD is detected
See http://forum.drdteam.org/viewtopic.php?t=6844
This commit is contained in:
alexey.lysiuk 2016-03-04 11:20:19 +02:00 committed by Christoph Oelckers
parent 93323b64f8
commit 9b23b41021

View file

@ -39,6 +39,7 @@
#include "v_text.h" #include "v_text.h"
#include "w_wad.h" #include "w_wad.h"
#include "gi.h" #include "gi.h"
#include "i_system.h"
// Console Doom LZSS wrapper. // Console Doom LZSS wrapper.
class FileReaderLZSS : public FileReaderBase class FileReaderLZSS : public FileReaderBase
@ -343,6 +344,12 @@ bool FWadFile::Open(bool quiet)
NumLumps = BigLong(header.NumLumps); NumLumps = BigLong(header.NumLumps);
InfoTableOfs = BigLong(header.InfoTableOfs); InfoTableOfs = BigLong(header.InfoTableOfs);
isBigEndian = true; isBigEndian = true;
// Check again to detect broken wads
if (InfoTableOfs + NumLumps*sizeof(wadlump_t) > (unsigned)wadSize)
{
I_Error("Cannot load broken WAD file %s\n", Filename);
}
} }
wadlump_t *fileinfo = new wadlump_t[NumLumps]; wadlump_t *fileinfo = new wadlump_t[NumLumps];