From ccfd20e0749fba3b75b78104e1f8b7ebf6e2ff6e Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 25 Sep 2020 19:06:19 +0200 Subject: [PATCH] - added some quick rejection checks for Doom patch textures. Since the checker reads all lumps completely into memory to check them, this can take quite a while. Reject everything that can be just by looking at the size fields immediately, without loading the rest. --- source/common/textures/formats/patchtexture.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/source/common/textures/formats/patchtexture.cpp b/source/common/textures/formats/patchtexture.cpp index 0a93adf50..46688d99b 100644 --- a/source/common/textures/formats/patchtexture.cpp +++ b/source/common/textures/formats/patchtexture.cpp @@ -127,13 +127,19 @@ FImageSource *PatchImage_TryCreate(FileReader & file, int lumpnum) { bool isalpha; - if (!CheckIfPatch(file, isalpha)) return NULL; - file.Seek(0, FileReader::SeekSet); int width = file.ReadUInt16(); int height = file.ReadUInt16(); int leftoffset = file.ReadInt16(); int topoffset = file.ReadInt16(); - return new FPatchTexture(lumpnum, width, height, leftoffset, topoffset, isalpha); + // quickly reject any lump which cannot be a texture without reading in all the data. + if (height > 0 && height <= 2048 && width > 0 && width <= 2048 && width < file.GetLength() / 4 && abs(leftoffset) < 4096 && abs(topoffset) < 4096) + { + file.Seek(0, FileReader::SeekSet); + if (!CheckIfPatch(file, isalpha)) return NULL; + file.Seek(8, FileReader::SeekSet); + return new FPatchTexture(lumpnum, width, height, leftoffset, topoffset, isalpha); + } + return nullptr; } //==========================================================================