summaryrefslogtreecommitdiffstats
path: root/lib/libarchive/archive_read_support_format_tar.c
diff options
context:
space:
mode:
authorkientzle <kientzle@FreeBSD.org>2008-01-13 23:50:30 +0000
committerkientzle <kientzle@FreeBSD.org>2008-01-13 23:50:30 +0000
commitb6542d8353b3ad10699c9f97df8205a16c9be554 (patch)
treea9c50ea066713a1999645932aac250bc51f8dcfb /lib/libarchive/archive_read_support_format_tar.c
parent4c2abb46e1d39e4e00c74e7fff03f65fd830047e (diff)
downloadFreeBSD-src-b6542d8353b3ad10699c9f97df8205a16c9be554.zip
FreeBSD-src-b6542d8353b3ad10699c9f97df8205a16c9be554.tar.gz
Since the tar bidder can never get called more than once, it
doesn't need to compensate for this situation. While here, fix a minor longstanding bug that empty tar archives (which begin with at least 512 zero bytes) never properly reported their format. In particular, this fixes the output of: bsdtar tvvf /dev/zero And, of course, a new test to verify that libarchive correctly recognizes the format of such files.
Diffstat (limited to 'lib/libarchive/archive_read_support_format_tar.c')
-rw-r--r--lib/libarchive/archive_read_support_format_tar.c35
1 files changed, 12 insertions, 23 deletions
diff --git a/lib/libarchive/archive_read_support_format_tar.c b/lib/libarchive/archive_read_support_format_tar.c
index fc6de4a..cda113b 100644
--- a/lib/libarchive/archive_read_support_format_tar.c
+++ b/lib/libarchive/archive_read_support_format_tar.c
@@ -295,24 +295,8 @@ archive_read_format_tar_bid(struct archive_read *a)
const void *h;
const struct archive_entry_header_ustar *header;
- /*
- * If we're already reading a non-tar file, don't
- * bother to bid.
- */
- if (a->archive.archive_format != 0 &&
- (a->archive.archive_format & ARCHIVE_FORMAT_BASE_MASK) !=
- ARCHIVE_FORMAT_TAR)
- return (0);
bid = 0;
- /*
- * If we're already reading a tar format, start the bid at 1 as
- * a failsafe.
- */
- if ((a->archive.archive_format & ARCHIVE_FORMAT_BASE_MASK) ==
- ARCHIVE_FORMAT_TAR)
- bid++;
-
/* Now let's look at the actual header and see if it matches. */
if (a->decompressor->read_ahead != NULL)
bytes_read = (a->decompressor->read_ahead)(a, &h, 512);
@@ -324,13 +308,14 @@ archive_read_format_tar_bid(struct archive_read *a)
return (0);
/* If it's an end-of-archive mark, we can handle it. */
- if ((*(const char *)h) == 0 && archive_block_is_null((const unsigned char *)h)) {
- /* If it's a known tar file, end-of-archive is definite. */
- if ((a->archive.archive_format & ARCHIVE_FORMAT_BASE_MASK) ==
- ARCHIVE_FORMAT_TAR)
- return (512);
- /* Empty archive? */
- return (1);
+ if ((*(const char *)h) == 0
+ && archive_block_is_null((const unsigned char *)h)) {
+ /*
+ * Usually, I bid the number of bits verified, but
+ * in this case, 4096 seems excessive so I picked 10 as
+ * an arbitrary but reasonable-seeming value.
+ */
+ return (10);
}
/* If it's not an end-of-archive mark, it must have a valid checksum.*/
@@ -590,6 +575,10 @@ tar_read_header(struct archive_read *a, struct tar *tar,
if (bytes > 0)
(a->decompressor->consume)(a, bytes);
archive_set_error(&a->archive, 0, NULL);
+ if (a->archive.archive_format_name == NULL) {
+ a->archive.archive_format = ARCHIVE_FORMAT_TAR;
+ a->archive.archive_format_name = "tar";
+ }
return (ARCHIVE_EOF);
}
OpenPOWER on IntegriCloud