Fix infinite loop in case an invalid pk3 file has been downloaded from the server. Thanks tjw for reporting (#3074)
This commit is contained in:
parent
d93cc3c997
commit
fd57c987c4
5 changed files with 78 additions and 20 deletions
|
@ -1660,7 +1660,7 @@ Creates a new pak_t in the search chain for the contents
|
|||
of a zip file.
|
||||
=================
|
||||
*/
|
||||
static pack_t *FS_LoadZipFile( char *zipfile, const char *basename )
|
||||
static pack_t *FS_LoadZipFile(const char *zipfile, const char *basename)
|
||||
{
|
||||
fileInPack_t *buildBuffer;
|
||||
pack_t *pack;
|
||||
|
@ -1683,8 +1683,6 @@ static pack_t *FS_LoadZipFile( char *zipfile, const char *basename )
|
|||
if (err != UNZ_OK)
|
||||
return NULL;
|
||||
|
||||
fs_packFiles += gi.number_entry;
|
||||
|
||||
len = 0;
|
||||
unzGoToFirstFile(uf);
|
||||
for (i = 0; i < gi.number_entry; i++)
|
||||
|
@ -1751,8 +1749,8 @@ static pack_t *FS_LoadZipFile( char *zipfile, const char *basename )
|
|||
unzGoToNextFile(uf);
|
||||
}
|
||||
|
||||
pack->checksum = Com_BlockChecksum( &fs_headerLongs[ 1 ], 4 * ( fs_numHeaderLongs - 1 ) );
|
||||
pack->pure_checksum = Com_BlockChecksum( fs_headerLongs, 4 * fs_numHeaderLongs );
|
||||
pack->checksum = Com_BlockChecksum( &fs_headerLongs[ 1 ], sizeof(*fs_headerLongs) * ( fs_numHeaderLongs - 1 ) );
|
||||
pack->pure_checksum = Com_BlockChecksum( fs_headerLongs, sizeof(*fs_headerLongs) * fs_numHeaderLongs );
|
||||
pack->checksum = LittleLong( pack->checksum );
|
||||
pack->pure_checksum = LittleLong( pack->pure_checksum );
|
||||
|
||||
|
@ -1762,6 +1760,50 @@ static pack_t *FS_LoadZipFile( char *zipfile, const char *basename )
|
|||
return pack;
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
FS_FreePak
|
||||
|
||||
Frees a pak structure and releases all associated resources
|
||||
=================
|
||||
*/
|
||||
|
||||
static void FS_FreePak(pack_t *thepak)
|
||||
{
|
||||
unzClose(thepak->handle);
|
||||
Z_Free(thepak->buildBuffer);
|
||||
Z_Free(thepak);
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
FS_GetZipChecksum
|
||||
|
||||
Compares whether the given pak file matches a referenced checksum
|
||||
=================
|
||||
*/
|
||||
qboolean FS_CompareZipChecksum(const char *zipfile)
|
||||
{
|
||||
pack_t *thepak;
|
||||
int index, checksum;
|
||||
|
||||
thepak = FS_LoadZipFile(zipfile, "");
|
||||
|
||||
if(!thepak)
|
||||
return qfalse;
|
||||
|
||||
checksum = thepak->checksum;
|
||||
FS_FreePak(thepak);
|
||||
|
||||
for(index = 0; index < fs_numServerReferencedPaks; index++)
|
||||
{
|
||||
if(checksum == fs_serverReferencedPaks[index])
|
||||
return qtrue;
|
||||
}
|
||||
|
||||
return qfalse;
|
||||
}
|
||||
|
||||
/*
|
||||
=================================================================================
|
||||
|
||||
|
@ -2466,6 +2508,8 @@ void FS_AddGameDirectory( const char *path, const char *dir ) {
|
|||
continue;
|
||||
// store the game name for downloading
|
||||
strcpy(pak->pakGamename, dir);
|
||||
|
||||
fs_packFiles += pak->numfiles;
|
||||
|
||||
search = Z_Malloc (sizeof(searchpath_t));
|
||||
search->pack = pak;
|
||||
|
@ -2655,18 +2699,16 @@ void FS_Shutdown( qboolean closemfp ) {
|
|||
}
|
||||
|
||||
// free everything
|
||||
for ( p = fs_searchpaths ; p ; p = next ) {
|
||||
for(p = fs_searchpaths; p; p = next)
|
||||
{
|
||||
next = p->next;
|
||||
|
||||
if ( p->pack ) {
|
||||
unzClose(p->pack->handle);
|
||||
Z_Free( p->pack->buildBuffer );
|
||||
Z_Free( p->pack );
|
||||
}
|
||||
if ( p->dir ) {
|
||||
Z_Free( p->dir );
|
||||
}
|
||||
Z_Free( p );
|
||||
if(p->pack)
|
||||
FS_FreePak(p->pack);
|
||||
if (p->dir)
|
||||
Z_Free(p->dir);
|
||||
|
||||
Z_Free(p);
|
||||
}
|
||||
|
||||
// any FS_ calls will now be an error until reinitialized
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue