Skip to content

Commit

Permalink
slb: be more aggressive about rejecting non-SLB files.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Jul 20, 2017
1 parent 7e30657 commit 32ed71d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/archiver_slb.c
Expand Up @@ -66,6 +66,13 @@ static void *SLB_openArchive(PHYSFS_Io *io, const char *name, int forWriting)
PHYSFS_uint32 tocPos;
void *unpkarc;

/* There's no identifier on an SLB file, so we assume it's _not_ if the
file count or tocPos is zero. Beyond that, we'll assume it's
bogus/corrupt if the entries' filenames don't start with '\' or the
tocPos is past the end of the file (seek will fail). This probably
covers all meaningful cases where we would accidentally accept a non-SLB
file with this archiver. */

assert(io != NULL); /* shouldn't ever happen. */

BAIL_IF(forWriting, PHYSFS_ERR_READ_ONLY, NULL);
Expand All @@ -76,10 +83,12 @@ static void *SLB_openArchive(PHYSFS_Io *io, const char *name, int forWriting)

BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &count, sizeof (count)), NULL);
count = PHYSFS_swapULE32(count);
BAIL_IF(!count, PHYSFS_ERR_UNSUPPORTED, NULL);

/* offset of the table of contents */
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &tocPos, sizeof (tocPos)), NULL);
tocPos = PHYSFS_swapULE32(tocPos);
BAIL_IF(!tocPos, PHYSFS_ERR_UNSUPPORTED, NULL);

/* seek to the table of contents */
BAIL_IF_ERRPASS(!io->seek(io, tocPos), NULL);
Expand Down

0 comments on commit 32ed71d

Please sign in to comment.