From 064540294665d186bfee68ec42acad8dd4810426 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 19 Sep 2022 06:02:41 +0300 Subject: [PATCH] engine: fix crash when reading GoldSrc hashpaks --- engine/common/hpak.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/engine/common/hpak.c b/engine/common/hpak.c index 076c3428..d9be8a68 100644 --- a/engine/common/hpak.c +++ b/engine/common/hpak.c @@ -647,7 +647,7 @@ qboolean HPAK_GetDataPointer( const char *filename, resource_t *pResource, byte for( p = gp_hpak_queue; p != NULL; p = p->next ) { - if( !Q_stricmp(p->name, filename ) && !memcmp( p->resource.rgucMD5_hash, pResource->rgucMD5_hash, 16 )) + if( !Q_stricmp( p->name, filename ) && !memcmp( p->resource.rgucMD5_hash, pResource->rgucMD5_hash, 16 )) { if( buffer ) { @@ -702,11 +702,13 @@ qboolean HPAK_GetDataPointer( const char *filename, resource_t *pResource, byte { entry = &directory.entries[i]; - if( !memcmp( entry->resource.rgucMD5_hash, pResource->rgucMD5_hash, 16 )) + if( entry->filepos > 0 && + entry->disksize > 0 && + !memcmp( entry->resource.rgucMD5_hash, pResource->rgucMD5_hash, 16 )) { FS_Seek( f, entry->filepos, SEEK_SET ); - if( buffer && entry->disksize > 0 ) + if( buffer ) { tmpbuf = Z_Malloc( entry->disksize ); FS_Read( f, tmpbuf, entry->disksize );