diff options
author | kientzle <kientzle@FreeBSD.org> | 2008-01-13 23:50:30 +0000 |
---|---|---|
committer | kientzle <kientzle@FreeBSD.org> | 2008-01-13 23:50:30 +0000 |
commit | b6542d8353b3ad10699c9f97df8205a16c9be554 (patch) | |
tree | a9c50ea066713a1999645932aac250bc51f8dcfb /lib/libarchive/test/test_read_format_tar.c | |
parent | 4c2abb46e1d39e4e00c74e7fff03f65fd830047e (diff) | |
download | FreeBSD-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/test/test_read_format_tar.c')
-rw-r--r-- | lib/libarchive/test/test_read_format_tar.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/libarchive/test/test_read_format_tar.c b/lib/libarchive/test/test_read_format_tar.c index 8f8b83b..bfe0b13 100644 --- a/lib/libarchive/test/test_read_format_tar.c +++ b/lib/libarchive/test/test_read_format_tar.c @@ -36,6 +36,52 @@ __FBSDID("$FreeBSD$"); * '2' is a symlink, '5' is a dir, etc. */ +/* Empty archive. */ +static unsigned char archiveEmpty[] = { + /* 512 zero bytes */ + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, + + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, + + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, + + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0 +}; + +static void verifyEmpty(void) +{ + struct archive_entry *ae; + struct archive *a; + + assert((a = archive_read_new()) != NULL); + assertA(0 == archive_read_support_compression_all(a)); + assertA(0 == archive_read_support_format_all(a)); + assertA(0 == archive_read_open_memory(a, archiveEmpty, 512)); + assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); + assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_NONE); + failure("512 zero bytes should be recognized as a tar archive."); + assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR); + + assert(0 == archive_read_close(a)); +#if ARCHIVE_API_VERSION > 1 + assert(0 == archive_read_finish(a)); +#else + archive_read_finish(a); +#endif +} + /* Single entry with a hardlink. */ static unsigned char archive1[] = { 'h','a','r','d','l','i','n','k',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, @@ -411,6 +457,7 @@ static void verify(unsigned char *d, size_t s, DEFINE_TEST(test_read_format_tar) { + verifyEmpty(); verify(archive1, sizeof(archive1), verify1, ARCHIVE_COMPRESSION_NONE, ARCHIVE_FORMAT_TAR_USTAR); verify(archive2, sizeof(archive2), verify2, |