From 42283f56abe62e7487dc67634da26e5029a64760 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 22 Aug 2023 22:35:39 +0200 Subject: [PATCH] - added a quick header check for WebP before loading the entire file for real identification. This allows quick rejection of virtually everything that's not a WebP without loading the entire file first. --- src/common/textures/formats/webptexture.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/common/textures/formats/webptexture.cpp b/src/common/textures/formats/webptexture.cpp index 64cc46d08..622c8e701 100644 --- a/src/common/textures/formats/webptexture.cpp +++ b/src/common/textures/formats/webptexture.cpp @@ -56,6 +56,12 @@ FImageSource *WebPImage_TryCreate(FileReader &file, int lumpnum) { int width = 0, height = 0; int xoff = 0, yoff = 0; + file.Seek(0, FileReader::SeekSet); + + uint8_t header[12]; + if (file.Read(header, 12) != 12) return nullptr; + if (memcmp(header, "RIFF", 4) || memcmp(header + 8, "WEBP", 4)) return nullptr; + file.Seek(0, FileReader::SeekSet); auto bytes = file.Read(); @@ -76,7 +82,7 @@ FImageSource *WebPImage_TryCreate(FileReader &file, int lumpnum) } return new FWebPTexture(lumpnum, width, height, xoff, yoff); } - return NULL; + return nullptr; } FWebPTexture::FWebPTexture(int lumpnum, int w, int h, int xoff, int yoff)