From f30f23ba51166ae89ea5b58078ee76ef574ce929 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Thu, 1 Dec 2022 05:49:47 +0300 Subject: [PATCH] engine: common: validate and load PNG images in customization --- engine/common/custom.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/engine/common/custom.c b/engine/common/custom.c index 1cb8f746..745d85f6 100644 --- a/engine/common/custom.c +++ b/engine/common/custom.c @@ -17,9 +17,21 @@ GNU General Public License for more details. #include "custom.h" #include "ref_common.h" -qboolean CustomDecal_Validate( void *raw, int nFileSize ) +static rgbdata_t *CustomDecal_LoadImage( const char *path, void *raw, int size ) { - rgbdata_t *test = FS_LoadImage( "#logo.bmp", raw, nFileSize ); + const char *testname; + + // this way we limit file types + if( !Q_stricmp( COM_FileExtension( path ), "png" )) + testname = "#logo.png"; + else testname = "#logo.bmp"; + + return FS_LoadImage( testname, raw, size ); +} + +static qboolean CustomDecal_Validate( const char *path, void *raw, int nFileSize ) +{ + rgbdata_t *test = CustomDecal_LoadImage( path, raw, nFileSize ); if( test ) { @@ -97,7 +109,7 @@ qboolean COM_CreateCustomization( customization_t *pListHead, resource_t *pResou { pCust->resource.playernum = playernumber; - if( CustomDecal_Validate( pCust->pBuffer, pResource->nDownloadSize )) + if( CustomDecal_Validate( pResource->szFileName, pCust->pBuffer, pResource->nDownloadSize )) { if( !FBitSet( flags, FCUST_IGNOREINIT )) { @@ -108,7 +120,7 @@ qboolean COM_CreateCustomization( customization_t *pListHead, resource_t *pResou pCust->nUserData2 = 1; if( !FBitSet( flags, FCUST_WIPEDATA )) - pCust->pInfo = FS_LoadImage( "#logo.bmp", pCust->pBuffer, pCust->resource.nDownloadSize ); + pCust->pInfo = CustomDecal_LoadImage( pResource->szFileName, pCust->pBuffer, pCust->resource.nDownloadSize ); else pCust->pInfo = NULL; if( nLumps ) *nLumps = 1; }