Skip to content

Commit

Permalink
Add a safety measure when loading Quake .pak files
Browse files Browse the repository at this point in the history
  • Loading branch information
viciious authored Jul 11, 2019
1 parent 69b1fa6 commit 66ecb52
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions source/qcommon/files.c
Original file line number Diff line number Diff line change
Expand Up @@ -2718,6 +2718,7 @@ static pack_t *FS_LoadPK3File( const char *packfilename, bool silent ) {
*
* Quick and dirty
*/
#define IDPAKENTRY_NAME_SIZE 56
#define IDPAKHEADER ( ( 'K' << 24 ) + ( 'C' << 16 ) + ( 'A' << 8 ) + 'P' )
static pack_t *FS_LoadPakFile( const char *packfilename, bool silent ) {
unsigned int i, j;
Expand All @@ -2729,8 +2730,8 @@ static pack_t *FS_LoadPakFile( const char *packfilename, bool silent ) {
pack_t *pack = NULL;
// c++
typedef struct { int ident; int dirofs; int dirlen; } fs_header_t;
typedef struct { char name[56]; int filepos, filelen; } fs_info_t;
typedef struct { char name[56]; } fs_dirs_t;
typedef struct { char name[IDPAKENTRY_NAME_SIZE]; int filepos, filelen; } fs_info_t;
typedef struct { char name[IDPAKENTRY_NAME_SIZE]; } fs_dirs_t;
fs_header_t header;
fs_info_t *info = NULL;
fs_dirs_t *dirs = NULL;
Expand Down Expand Up @@ -2791,6 +2792,9 @@ static pack_t *FS_LoadPakFile( const char *packfilename, bool silent ) {
goto error; // something wrong occured

}

info[i].name[IDPAKENTRY_NAME_SIZE-1] = '\0'; // ensure the trailing \0 is there

len = strlen( info[i].name );
if( !len ) {
goto error; // something wrong occured
Expand Down

0 comments on commit 66ecb52

Please sign in to comment.