Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions libmspack/mspack/cabd.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ static int cabd_read_headers(struct mspack_system *sys,
cab->base.set_id = EndGetI16(&buf[cfhead_SetID]);
cab->base.set_index = EndGetI16(&buf[cfhead_CabinetIndex]);

unsigned long long cfile_offset = (unsigned long long) EndGetI32(&buf[cfhead_FileOffset]);

/* get the number of folders */
num_folders = EndGetI16(&buf[cfhead_NumFolders]);
if (num_folders == 0) {
Expand Down Expand Up @@ -439,6 +441,13 @@ static int cabd_read_headers(struct mspack_system *sys,
linkfol = fol;
}

if ((unsigned long long)(sys->tell(fh) - cab->base.base_offset) < cfile_offset
&& cfile_offset < (unsigned long long)cab->base.length) {
if (sys->seek(fh, cfile_offset, MSPACK_SYS_SEEK_START)) {
return MSPACK_ERR_SEEK;
}
}

/* read files */
for (i = 0; i < num_files; i++) {
if (sys->read(fh, &buf[0], cffile_SIZEOF) != cffile_SIZEOF) {
Expand Down