]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Github Issue #522: Detect cycles in the ISO directory tree
authorTim Kientzle <kientzle@acm.org>
Sun, 12 Apr 2015 05:57:58 +0000 (22:57 -0700)
committerTim Kientzle <kientzle@acm.org>
Sun, 12 Apr 2015 05:57:58 +0000 (22:57 -0700)
libarchive/archive_read_support_format_iso9660.c

index d3f19aa8b042900ecbd52a09335d03dc76206744..6934ceefe9db20b808aaf0d817b1bd904f511284 100644 (file)
@@ -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;
 
@@ -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) {
@@ -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;