From 9f322df498a8673bbd26f1bb823f6391bb796853 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Wed, 22 Jan 2025 19:21:51 +0300 Subject: [PATCH] engine: imagelib: handle loading truncated palette files, by filling remaining bytes with zeros --- engine/common/imagelib/img_wad.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/engine/common/imagelib/img_wad.c b/engine/common/imagelib/img_wad.c index 094efaf7..14513752 100644 --- a/engine/common/imagelib/img_wad.c +++ b/engine/common/imagelib/img_wad.c @@ -28,12 +28,20 @@ Image_LoadPAL qboolean Image_LoadPAL( const char *name, const byte *buffer, fs_offset_t filesize ) { int rendermode = LUMP_NORMAL; + byte pal[768]; - if( filesize != 768 ) + if( filesize > sizeof( pal )) { - Con_DPrintf( S_ERROR "%s: (%s) have invalid size (%li should be %d)\n", __func__, name, (long)filesize, 768 ); + Con_DPrintf( S_ERROR "%s: (%s) have invalid size (%li should be less or equal than %d)\n", __func__, name, (long)filesize, sizeof( pal )); return false; } + else if( filesize < sizeof( pal ) && buffer != NULL ) + { + // palette might be truncated, fill it with zeros + memset( pal, 0, sizeof( pal )); + memcpy( pal, buffer, filesize ); + buffer = pal; + } if( name[0] == '#' ) {