Skip to content

Commit

Permalink
Github Issue #522: Detect cycles in the ISO directory tree
Browse files Browse the repository at this point in the history
  • Loading branch information
kientzle committed Apr 12, 2015
1 parent 39fc593 commit 01cfbca
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions libarchive/archive_read_support_format_iso9660.c
Expand Up @@ -1752,12 +1752,12 @@ parse_file_info(struct archive_read *a, struct file_info *parent,
const unsigned char *isodirrec)
{
struct iso9660 *iso9660;
struct file_info *file;
struct file_info *file, *filep;
size_t name_len;
const unsigned char *rr_start, *rr_end;
const unsigned char *p;
size_t dr_len;
uint64_t fsize;
uint64_t fsize, offset;
int32_t location;
int flags;

Expand Down Expand Up @@ -1801,6 +1801,16 @@ parse_file_info(struct archive_read *a, struct file_info *parent,
return (NULL);
}

/* Sanity check that this entry does not create a cycle. */
offset = iso9660->logical_block_size * (uint64_t)location;
for (filep = parent; filep != NULL; filep = filep->parent) {
if (filep->offset == offset) {
archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
"Directory structure contains loop");
return (NULL);
}
}

/* Create a new file entry and copy data from the ISO dir record. */
file = (struct file_info *)calloc(1, sizeof(*file));
if (file == NULL) {
Expand All @@ -1809,7 +1819,7 @@ parse_file_info(struct archive_read *a, struct file_info *parent,
return (NULL);
}
file->parent = parent;
file->offset = iso9660->logical_block_size * (uint64_t)location;
file->offset = offset;
file->size = fsize;
file->mtime = isodate7(isodirrec + DR_date_offset);
file->ctime = file->atime = file->mtime;
Expand Down

0 comments on commit 01cfbca

Please sign in to comment.