]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Enable the iso9660 reader to seek a file pointer for reading
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Tue, 9 Oct 2012 06:44:26 +0000 (15:44 +0900)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Tue, 9 Oct 2012 07:22:30 +0000 (16:22 +0900)
its contents.

libarchive/archive_read_support_format_iso9660.c

index 9fe3a82e2f03efe8b8f099a6249b68c293f5b6d5..17dec73e6acf52cd57423798ce4ad4bed3ad9fd7 100644 (file)
@@ -1305,32 +1305,31 @@ archive_read_format_iso9660_read_header(struct archive_read *a,
                return (rd_r);
        }
 
-       /* Except for the hardlink case above, if the offset of the
-        * next entry is before our current position, we can't seek
-        * backwards to extract it, so issue a warning.  Note that
-        * this can only happen if this entry was added to the heap
-        * after we passed this offset, that is, only if the directory
-        * mentioning this entry is later than the body of the entry.
-        * Such layouts are very unusual; most ISO9660 writers lay out
-        * and record all directory information first, then store
-        * all file bodies. */
-       /* TODO: Someday, libarchive's I/O core will support optional
-        * seeking.  When that day comes, this code should attempt to
-        * seek and only return the error if the seek fails.  That
-        * will give us support for whacky ISO images that require
-        * seeking while retaining the ability to read almost all ISO
-        * images in a streaming fashion. */
        if ((file->mode & AE_IFMT) != AE_IFDIR &&
            file->offset < iso9660->current_position) {
-               archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
-                   "Ignoring out-of-order file @%jx (%s) %jd < %jd",
-                   (intmax_t)file->number,
-                   iso9660->pathname.s,
-                   (intmax_t)file->offset,
-                   (intmax_t)iso9660->current_position);
-               iso9660->entry_bytes_remaining = 0;
-               iso9660->entry_sparse_offset = 0;
-               return (ARCHIVE_WARN);
+               int64_t r64;
+
+               r64 = __archive_read_seek(a, file->offset, SEEK_SET);
+               if (r64 != (int64_t)file->offset) {
+                       /* We can't seek backwards to extract it, so issue
+                        * a warning.  Note that this can only happen if
+                        * this entry was added to the heap after we passed
+                        * this offset, that is, only if the directory
+                        * mentioning this entry is later than the body of
+                        * the entry. Such layouts are very unusual; most
+                        * ISO9660 writers lay out and record all directory
+                        * information first, then store all file bodies. */
+                       archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+                           "Ignoring out-of-order file @%jx (%s) %jd < %jd",
+                           (intmax_t)file->number,
+                           iso9660->pathname.s,
+                           (intmax_t)file->offset,
+                           (intmax_t)iso9660->current_position);
+                       iso9660->entry_bytes_remaining = 0;
+                       iso9660->entry_sparse_offset = 0;
+                       return (ARCHIVE_WARN);
+               }
+               iso9660->current_position = (uint64_t)r64;
        }
 
        /* Initialize zisofs variables. */
@@ -2882,8 +2881,9 @@ next_cache_entry(struct archive_read *a, struct iso9660 *iso9660,
 
 fatal_rr:
        archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
-           "Failed to connect 'CL' pointer to 'RE' rr_moved pointer of"
-           "Rockridge extensions");
+           "Failed to connect 'CL' pointer to 'RE' rr_moved pointer of "
+           "Rockridge extensions: current position = %jd, CL offset = %jd",
+           iso9660->current_position, file->cl_offset);
        return (ARCHIVE_FATAL);
 }