From 2c33cbd1a4af3e0d70e12110cf84c5841cee41f0 Mon Sep 17 00:00:00 2001 From: Michihiro NAKAJIMA Date: Tue, 9 Oct 2012 15:44:26 +0900 Subject: [PATCH] Enable the iso9660 reader to seek a file pointer for reading its contents. --- .../archive_read_support_format_iso9660.c | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/libarchive/archive_read_support_format_iso9660.c b/libarchive/archive_read_support_format_iso9660.c index 9fe3a82e2..17dec73e6 100644 --- a/libarchive/archive_read_support_format_iso9660.c +++ b/libarchive/archive_read_support_format_iso9660.c @@ -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); } -- 2.47.2