aboutsummaryrefslogtreecommitdiffstats
path: root/libarchive/test
diff options
context:
space:
mode:
authorMartin Matuska <mm@FreeBSD.org>2019-05-20 12:32:00 +0000
committerMartin Matuska <mm@FreeBSD.org>2019-05-20 12:32:00 +0000
commit8e97bbedaebab6c0c9e87545b8424c95f206f148 (patch)
treeebde61e13d7849a1bdad8146f7528a586b64ddcc /libarchive/test
parentf9b2e63a44664e352e4a767f2822ca3eda65f540 (diff)
downloadsrc-8e97bbedaebab6c0c9e87545b8424c95f206f148.tar.gz
src-8e97bbedaebab6c0c9e87545b8424c95f206f148.zip
Update vendor/libarchive/dist to git b5818e39e128eca4951e2ab10467d4d850a2ba57
Relevant vendor changes: Issue #795: XAR - do not try to add xattrs without an allocated name PR #812: non-recursive option for extract and list PR #958: support reading metadata from compressed files PR #999: add --exclude-vcs option to bsdtar Issue #1062: treat empty archives with a GNU volume header as valid PR #1074: Handle ZIP files with trailing 0s in the extra fields (Android APK archives) PR #1109: Ignore padding in Zip extra field data (Android APK archives) PR #1167: fix problems related to unreadable directories Issue #1168: fix handling of strtol() and strtoul() PR #1172: RAR5 - fix invalid window buffer read in E8E9 filter PR #1174: ZIP reader - fix of MSZIP signature parsing PR #1175: gzip filter - fix reading files larger than 4GB from memory PR #1177: gzip filter - fix memory leak with repeated header reads PR #1180: ZIP reader - add support for Info-ZIP Unicode Path Extra Field PR #1181: RAR5 - fix merge_block() recursion (OSS-Fuzz 12999, 13029, 13144, 13478, 13490) PR #1183: fix memory leak when decompressing ZIP files with LZMA PR #1184: fix RAR5 OSS-Fuzz issues 12466, 14490, 14491, 12817 OSS-Fuzz 12466: RAR5 - fix buffer overflow when parsing huffman tables OSS-Fuzz 14490, 14491: RAR5 - fix bad shift-left operations OSS-Fuzz 12817: RAR5 - handle a case with truncated huffman tables PR #1186: RAR5 - fix invalid type used for dictionary size mask (OSS-Fuzz 14537) PR #1187: RAR5 - fix integer overflow (OSS-Fuzz 14555) PR #1190: RAR5 - RAR5 don't try to unpack entries marked as directories (OSS-Fuzz 14574) PR #1196: RAR5 - fix a potential SIGSEGV on 32-bit builds OSS-Fuzz 2582: RAR - fix use after free if there is an invalid entry OSS-Fuzz 14331: RAR5 - fix maximum owner name length OSS-Fuzz 13965: RAR5 - use unsigned int for volume number + range check Additional RAR5 reader changes: - support symlinks, hardlinks, file owner, file group, versioned files - change ARCHIVE_FORMAT_RAR_V5 to 0x100000 - set correct mode for readonly directories - support readonly, hidden and system Windows file attributes NOTE: a version bump of libarchive will happen in the following days
Notes
Notes: svn path=/vendor/libarchive/dist/; revision=347989
Diffstat (limited to 'libarchive/test')
-rw-r--r--libarchive/test/CMakeLists.txt3
-rw-r--r--libarchive/test/test_entry.c37
-rw-r--r--libarchive/test/test_fuzz.c8
-rw-r--r--libarchive/test/test_read_disk_directory_traversals.c299
-rw-r--r--libarchive/test/test_read_extract.c2
-rw-r--r--libarchive/test/test_read_format_mtree.c24
-rw-r--r--libarchive/test/test_read_format_mtree_noprint.mtree.uu4
-rw-r--r--libarchive/test/test_read_format_rar.c39
-rw-r--r--libarchive/test/test_read_format_rar5.c1622
-rw-r--r--libarchive/test/test_read_format_rar5_distance_overflow.rar.uu9
-rw-r--r--libarchive/test/test_read_format_rar5_extra_field_version.rar.uu10
-rw-r--r--libarchive/test/test_read_format_rar5_fileattr.rar.uu13
-rw-r--r--libarchive/test/test_read_format_rar5_hardlink.rar.uu6
-rw-r--r--libarchive/test/test_read_format_rar5_invalid_dict_reference.rar.uu9
-rw-r--r--libarchive/test/test_read_format_rar5_leftshift1.rar.uu9
-rw-r--r--libarchive/test/test_read_format_rar5_leftshift2.rar.uu6
-rw-r--r--libarchive/test/test_read_format_rar5_nonempty_dir_stream.rar.uu9
-rw-r--r--libarchive/test/test_read_format_rar5_owner.rar.uu8
-rw-r--r--libarchive/test/test_read_format_rar5_readtables_overflow.rar.uu15
-rw-r--r--libarchive/test/test_read_format_rar5_symlink.rar.uu8
-rw-r--r--libarchive/test/test_read_format_rar5_truncated_huff.rar.uu7
-rw-r--r--libarchive/test/test_read_format_rar5_win32.rar.uu131
-rw-r--r--libarchive/test/test_read_format_rar_ppmd_use_after_free.rar.uu10
-rw-r--r--libarchive/test/test_read_format_raw.c27
-rw-r--r--libarchive/test/test_read_format_raw.data.gz.uu4
-rw-r--r--libarchive/test/test_read_format_tar_empty_with_gnulabel.c53
-rw-r--r--libarchive/test/test_read_format_tar_empty_with_gnulabel.tar.uu231
-rw-r--r--libarchive/test/test_read_format_zip.c165
-rw-r--r--libarchive/test/test_read_format_zip_7075_utf8_paths.c102
-rw-r--r--libarchive/test/test_read_format_zip_7075_utf8_paths.zip.uu20
-rw-r--r--libarchive/test/test_read_format_zip_extra_padding.c93
-rw-r--r--libarchive/test/test_read_format_zip_extra_padding.zip.uu7
-rw-r--r--libarchive/test/test_read_format_zip_lzma_alone_leak.zipx.uu5
-rw-r--r--libarchive/test/test_sparse_basic.c81
-rw-r--r--libarchive/test/test_write_disk_symlink.c156
35 files changed, 2483 insertions, 749 deletions
diff --git a/libarchive/test/CMakeLists.txt b/libarchive/test/CMakeLists.txt
index 690a83c5cd60..2f451d2a0649 100644
--- a/libarchive/test/CMakeLists.txt
+++ b/libarchive/test/CMakeLists.txt
@@ -154,6 +154,7 @@ IF(ENABLE_TEST)
test_read_format_tar.c
test_read_format_tar_concatenated.c
test_read_format_tar_empty_filename.c
+ test_read_format_tar_empty_with_gnulabel.c
test_read_format_tar_empty_pax.c
test_read_format_tar_filename.c
test_read_format_tbz.c
@@ -165,10 +166,12 @@ IF(ENABLE_TEST)
test_read_format_warc.c
test_read_format_xar.c
test_read_format_zip.c
+ test_read_format_zip_7075_utf8_paths.c
test_read_format_zip_comment_stored.c
test_read_format_zip_encryption_data.c
test_read_format_zip_encryption_header.c
test_read_format_zip_encryption_partially.c
+ test_read_format_zip_extra_padding.c
test_read_format_zip_filename.c
test_read_format_zip_high_compression.c
test_read_format_zip_jar.c
diff --git a/libarchive/test/test_entry.c b/libarchive/test/test_entry.c
index a0a2607a156c..0cf13e825afc 100644
--- a/libarchive/test/test_entry.c
+++ b/libarchive/test/test_entry.c
@@ -27,6 +27,10 @@ __FBSDID("$FreeBSD: head/lib/libarchive/test/test_entry.c 201247 2009-12-30 05:5
#include <locale.h>
+#ifdef HAVE_LINUX_FS_H
+#include <linux/fs.h> /* for Linux file flags */
+#endif
+
#ifndef HAVE_WCSCPY
static wchar_t * wcscpy(wchar_t *s1, const wchar_t *s2)
{
@@ -337,16 +341,37 @@ DEFINE_TEST(test_entry)
/* TODO: Make this system-independent. */
assertEqualString(archive_entry_fflags_text(e),
"uappnd,nouchg,nodump,noopaque,uunlnk,nosystem");
+#endif
+
+#if defined(__FreeBSD__) || defined(__APPLE__)
/* Test archive_entry_copy_fflags_text_w() */
- archive_entry_copy_fflags_text_w(e, L" ,nouappnd, nouchg, dump,uunlnk");
+ archive_entry_copy_fflags_text_w(e, L" ,nouappnd, nouchg, dump,hidden");
archive_entry_fflags(e, &set, &clear);
- assertEqualInt(16, set);
- assertEqualInt(7, clear);
+ assertEqualInt(UF_HIDDEN, set);
+ assertEqualInt(UF_NODUMP | UF_IMMUTABLE | UF_APPEND, clear);
/* Test archive_entry_copy_fflags_text() */
- archive_entry_copy_fflags_text(e, " ,nouappnd, nouchg, dump,uunlnk");
+ archive_entry_copy_fflags_text(e, " ,nouappnd, nouchg, dump,hidden");
+ archive_entry_fflags(e, &set, &clear);
+ assertEqualInt(UF_HIDDEN, set);
+ assertEqualInt(UF_NODUMP | UF_IMMUTABLE | UF_APPEND, clear);
+#elif defined(_WIN32) && !defined(CYGWIN)
+ archive_entry_copy_fflags_text_w(e, L"rdonly,hidden,nosystem");
+ archive_entry_fflags(e, &set, &clear);
+ assertEqualInt(FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN, set);
+ assertEqualInt(FILE_ATTRIBUTE_SYSTEM, clear);
+ archive_entry_copy_fflags_text(e, "rdonly,hidden,nosystem");
+ archive_entry_fflags(e, &set, &clear);
+ assertEqualInt(FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN, set);
+ assertEqualInt(FILE_ATTRIBUTE_SYSTEM, clear);
+#elif defined FS_IOC_GETFLAGS /* Linux */
+ archive_entry_copy_fflags_text_w(e, L"sappnd,schg,dump,noundel");
+ archive_entry_fflags(e, &set, &clear);
+ assertEqualInt(FS_APPEND_FL | FS_IMMUTABLE_FL, set);
+ assertEqualInt(FS_NODUMP_FL | FS_UNRM_FL, clear);
+ archive_entry_copy_fflags_text(e, "sappnd,schg,dump,noundel");
archive_entry_fflags(e, &set, &clear);
- assertEqualInt(16, set);
- assertEqualInt(7, clear);
+ assertEqualInt(FS_APPEND_FL | FS_IMMUTABLE_FL, set);
+ assertEqualInt(FS_NODUMP_FL | FS_UNRM_FL, clear);
#endif
/* See test_acl_basic.c for tests of ACL set/get consistency. */
diff --git a/libarchive/test/test_fuzz.c b/libarchive/test/test_fuzz.c
index 2025834ca424..d02fd993f972 100644
--- a/libarchive/test/test_fuzz.c
+++ b/libarchive/test/test_fuzz.c
@@ -58,6 +58,14 @@ test_fuzz(const struct files *filesets)
size_t blk_size;
int64_t blk_offset;
int n;
+ const char *skip_fuzz_tests;
+
+ skip_fuzz_tests = getenv("SKIP_TEST_FUZZ");
+ if (skip_fuzz_tests != NULL) {
+ skipping("Skipping fuzz tests due to SKIP_TEST_FUZZ "
+ "environment variable");
+ return;
+ }
for (n = 0; filesets[n].names != NULL; ++n) {
const size_t buffsize = 30000000;
diff --git a/libarchive/test/test_read_disk_directory_traversals.c b/libarchive/test/test_read_disk_directory_traversals.c
index 705b3d989cd5..7dd19157d4d2 100644
--- a/libarchive/test/test_read_disk_directory_traversals.c
+++ b/libarchive/test/test_read_disk_directory_traversals.c
@@ -40,7 +40,30 @@ atimeIsUpdated(void)
{
const char *fn = "fs_noatime";
struct stat st;
-
+#if defined(_WIN32) && !defined(CYGWIN)
+ char *buff = NULL;
+ char *ptr;
+ int r;
+
+ r = systemf("fsutil behavior query disableLastAccess > query_atime");
+ if (r == 0) {
+ buff = slurpfile(NULL, "query_atime");
+ if (buff != NULL) {
+ ptr = buff;
+ while(*ptr != '\0' && !isdigit(*ptr)) {
+ ptr++;
+ }
+ if (*ptr == '0') {
+ free(buff);
+ return(1);
+ } else if (*ptr == '1' || *ptr == '2') {
+ free(buff);
+ return(0);
+ }
+ free(buff);
+ }
+ }
+#endif
if (!assertMakeFile(fn, 0666, "a"))
return (0);
if (!assertUtimes(fn, 1, 0, 1, 0))
@@ -570,13 +593,13 @@ test_symlink_hybrid(void)
assertMakeDir("h", 0755);
assertChdir("h");
assertMakeDir("d1", 0755);
- assertMakeSymlink("ld1", "d1");
+ assertMakeSymlink("ld1", "d1", 1);
assertMakeFile("d1/file1", 0644, "d1/file1");
assertMakeFile("d1/file2", 0644, "d1/file2");
- assertMakeSymlink("d1/link1", "file1");
- assertMakeSymlink("d1/linkX", "fileX");
- assertMakeSymlink("link2", "d1/file2");
- assertMakeSymlink("linkY", "d1/fileY");
+ assertMakeSymlink("d1/link1", "file1", 0);
+ assertMakeSymlink("d1/linkX", "fileX", 0);
+ assertMakeSymlink("link2", "d1/file2", 0);
+ assertMakeSymlink("linkY", "d1/fileY", 0);
assertChdir("..");
assert((ae = archive_entry_new()) != NULL);
@@ -727,13 +750,13 @@ test_symlink_logical(void)
assertMakeDir("l", 0755);
assertChdir("l");
assertMakeDir("d1", 0755);
- assertMakeSymlink("ld1", "d1");
+ assertMakeSymlink("ld1", "d1", 1);
assertMakeFile("d1/file1", 0644, "d1/file1");
assertMakeFile("d1/file2", 0644, "d1/file2");
- assertMakeSymlink("d1/link1", "file1");
- assertMakeSymlink("d1/linkX", "fileX");
- assertMakeSymlink("link2", "d1/file2");
- assertMakeSymlink("linkY", "d1/fileY");
+ assertMakeSymlink("d1/link1", "file1", 0);
+ assertMakeSymlink("d1/linkX", "fileX", 0);
+ assertMakeSymlink("link2", "d1/file2", 0);
+ assertMakeSymlink("linkY", "d1/fileY", 0);
assertChdir("..");
/* Note: this test uses archive_read_next_header()
@@ -961,8 +984,8 @@ test_symlink_logical_loop(void)
assertMakeDir("d1/d2/d3", 0755);
assertMakeDir("d2", 0755);
assertMakeFile("d2/file1", 0644, "d2/file1");
- assertMakeSymlink("d1/d2/ld1", "../../d1");
- assertMakeSymlink("d1/d2/ld2", "../../d2");
+ assertMakeSymlink("d1/d2/ld1", "../../d1", 1);
+ assertMakeSymlink("d1/d2/ld2", "../../d2", 1);
assertChdir("..");
assert((ae = archive_entry_new()) != NULL);
@@ -1567,6 +1590,254 @@ test_nodump(void)
archive_entry_free(ae);
}
+static void
+test_parent(void)
+{
+ struct archive *a;
+ struct archive_entry *ae;
+ const void *p;
+ size_t size;
+ int64_t offset;
+ int file_count;
+ int match_count;
+ int r;
+
+ assertMakeDir("lock", 0311);
+ assertMakeDir("lock/dir1", 0755);
+ assertMakeFile("lock/dir1/f1", 0644, "0123456789");
+ assertMakeDir("lock/lock2", 0311);
+ assertMakeDir("lock/lock2/dir1", 0755);
+ assertMakeFile("lock/lock2/dir1/f1", 0644, "0123456789");
+
+ assert((ae = archive_entry_new()) != NULL);
+ assert((a = archive_read_disk_new()) != NULL);
+
+ /*
+ * Test1: Traverse lock/dir1 as .
+ */
+ assertChdir("lock/dir1");
+
+ failure("Directory traversals should work as well");
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_disk_open(a, "."));
+
+ file_count = 2;
+ match_count = 0;
+ while (file_count--) {
+ archive_entry_clear(ae);
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header2(a, ae));
+ if (strcmp(archive_entry_pathname(ae), ".") == 0) {
+ assertEqualInt(archive_entry_filetype(ae), AE_IFDIR);
+ ++match_count;
+ } else if (strcmp(archive_entry_pathname(ae), "./f1") == 0) {
+ assertEqualInt(archive_entry_filetype(ae), AE_IFREG);
+ assertEqualInt(archive_entry_size(ae), 10);
+ assertEqualIntA(a, ARCHIVE_OK,
+ archive_read_data_block(a, &p, &size, &offset));
+ assertEqualInt((int)size, 10);
+ assertEqualInt((int)offset, 0);
+ assertEqualMem(p, "0123456789", 10);
+ assertEqualInt(ARCHIVE_EOF,
+ archive_read_data_block(a, &p, &size, &offset));
+ assertEqualInt((int)size, 0);
+ assertEqualInt((int)offset, 10);
+ ++match_count;
+ }
+ if (archive_read_disk_can_descend(a)) {
+ /* Descend into the current object */
+ assertEqualIntA(a, ARCHIVE_OK,
+ archive_read_disk_descend(a));
+ }
+ }
+ failure("Did not match expected filenames");
+ assertEqualInt(match_count, 2);
+ /*
+ * There is no entry. This will however fail if the directory traverse
+ * tries to ascend past the initial directory, since it lacks permission
+ * to do so.
+ */
+ failure("There should be no entry and no error");
+ assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header2(a, ae));
+
+ /* Close the disk object. */
+ assertEqualInt(ARCHIVE_OK, archive_read_close(a));
+
+ assertChdir("../..");
+
+ /*
+ * Test2: Traverse lock/dir1 directly
+ */
+ failure("Directory traversals should work as well");
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_disk_open(a, "lock/dir1"));
+
+ file_count = 2;
+ match_count = 0;
+ while (file_count--) {
+ archive_entry_clear(ae);
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header2(a, ae));
+ if (strcmp(archive_entry_pathname(ae), "lock/dir1") == 0) {
+ assertEqualInt(archive_entry_filetype(ae), AE_IFDIR);
+ ++match_count;
+ } else if (strcmp(archive_entry_pathname(ae), "lock/dir1/f1") == 0) {
+ assertEqualInt(archive_entry_filetype(ae), AE_IFREG);
+ assertEqualInt(archive_entry_size(ae), 10);
+ assertEqualIntA(a, ARCHIVE_OK,
+ archive_read_data_block(a, &p, &size, &offset));
+ assertEqualInt((int)size, 10);
+ assertEqualInt((int)offset, 0);
+ assertEqualMem(p, "0123456789", 10);
+ assertEqualInt(ARCHIVE_EOF,
+ archive_read_data_block(a, &p, &size, &offset));
+ assertEqualInt((int)size, 0);
+ assertEqualInt((int)offset, 10);
+ ++match_count;
+ }
+ if (archive_read_disk_can_descend(a)) {
+ /* Descend into the current object */
+ assertEqualIntA(a, ARCHIVE_OK,
+ archive_read_disk_descend(a));
+ }
+ }
+ failure("Did not match expected filenames");
+ assertEqualInt(match_count, 2);
+ /*
+ * There is no entry. This will however fail if the directory traverse
+ * tries to ascend past the initial directory, since it lacks permission
+ * to do so.
+ */
+ failure("There should be no entry and no error");
+ assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header2(a, ae));
+
+ /* Close the disk object. */
+ assertEqualInt(ARCHIVE_OK, archive_read_close(a));
+
+ /*
+ * Test3: Traverse lock/dir1/.
+ */
+ failure("Directory traversals should work as well");
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_disk_open(a, "lock/dir1/."));
+
+ file_count = 2;
+ match_count = 0;
+ while (file_count--) {
+ archive_entry_clear(ae);
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header2(a, ae));
+ if (strcmp(archive_entry_pathname(ae), "lock/dir1/.") == 0) {
+ assertEqualInt(archive_entry_filetype(ae), AE_IFDIR);
+ ++match_count;
+ } else if (strcmp(archive_entry_pathname(ae), "lock/dir1/./f1") == 0) {
+ assertEqualInt(archive_entry_filetype(ae), AE_IFREG);
+ assertEqualInt(archive_entry_size(ae), 10);
+ assertEqualIntA(a, ARCHIVE_OK,
+ archive_read_data_block(a, &p, &size, &offset));
+ assertEqualInt((int)size, 10);
+ assertEqualInt((int)offset, 0);
+ assertEqualMem(p, "0123456789", 10);
+ assertEqualInt(ARCHIVE_EOF,
+ archive_read_data_block(a, &p, &size, &offset));
+ assertEqualInt((int)size, 0);
+ assertEqualInt((int)offset, 10);
+ ++match_count;
+ }
+ if (archive_read_disk_can_descend(a)) {
+ /* Descend into the current object */
+ assertEqualIntA(a, ARCHIVE_OK,
+ archive_read_disk_descend(a));
+ }
+ }
+ failure("Did not match expected filenames");
+ assertEqualInt(match_count, 2);
+ /*
+ * There is no entry. This will however fail if the directory traverse
+ * tries to ascend past the initial directory, since it lacks permission
+ * to do so.
+ */
+ failure("There should be no entry and no error");
+ assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header2(a, ae));
+
+ /* Close the disk object. */
+ assertEqualInt(ARCHIVE_OK, archive_read_close(a));
+
+ /*
+ * Test4: Traverse lock/lock2/dir1 from inside lock.
+ *
+ * This test is expected to fail on platforms with no O_EXEC or
+ * equivalent (e.g. O_PATH on Linux or O_SEARCH on SunOS), because
+ * the current traversal code can't handle the case where it can't
+ * obtain an open fd for the initial current directory. We need to
+ * check that condition here, because if O_EXEC _does_ exist, we don't
+ * want to overlook any failure.
+ */
+ assertChdir("lock");
+
+ failure("Directory traversals should work as well");
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_disk_open(a, "lock2/dir1"));
+
+ archive_entry_clear(ae);
+ r = archive_read_next_header2(a, ae);
+ if (r == ARCHIVE_FAILED) {
+#if defined(O_PATH) || defined(O_SEARCH) || defined(O_EXEC)
+ assertEqualIntA(a, ARCHIVE_OK, r);
+#endif
+ /* Close the disk object. */
+ archive_read_close(a);
+ } else {
+ file_count = 2;
+ match_count = 0;
+ while (file_count--) {
+ if (file_count == 0)
+ assertEqualIntA(a, ARCHIVE_OK,
+ archive_read_next_header2(a, ae));
+ if (strcmp(archive_entry_pathname(ae),
+ "lock2/dir1") == 0) {
+ assertEqualInt(archive_entry_filetype(ae),
+ AE_IFDIR);
+ ++match_count;
+ } else if (strcmp(archive_entry_pathname(ae),
+ "lock2/dir1/f1") == 0) {
+ assertEqualInt(archive_entry_filetype(ae),
+ AE_IFREG);
+ assertEqualInt(archive_entry_size(ae), 10);
+ assertEqualIntA(a, ARCHIVE_OK,
+ archive_read_data_block(a, &p, &size,
+ &offset));
+ assertEqualInt((int)size, 10);
+ assertEqualInt((int)offset, 0);
+ assertEqualMem(p, "0123456789", 10);
+ assertEqualInt(ARCHIVE_EOF,
+ archive_read_data_block(a, &p, &size,
+ &offset));
+ assertEqualInt((int)size, 0);
+ assertEqualInt((int)offset, 10);
+ ++match_count;
+ }
+ if (archive_read_disk_can_descend(a)) {
+ /* Descend into the current object */
+ assertEqualIntA(a, ARCHIVE_OK,
+ archive_read_disk_descend(a));
+ }
+ }
+ failure("Did not match expected filenames");
+ assertEqualInt(match_count, 2);
+ /*
+ * There is no entry. This will however fail if the directory
+ * traverse tries to ascend past the initial directory, since
+ * it lacks permission to do so.
+ */
+ failure("There should be no entry and no error");
+ assertEqualIntA(a, ARCHIVE_EOF,
+ archive_read_next_header2(a, ae));
+
+ /* Close the disk object. */
+ assertEqualInt(ARCHIVE_OK, archive_read_close(a));
+ }
+
+ assertChdir("..");
+
+ /* Destroy the disk object. */
+ assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+ archive_entry_free(ae);
+}
+
DEFINE_TEST(test_read_disk_directory_traversals)
{
/* Basic test. */
@@ -1583,4 +1854,6 @@ DEFINE_TEST(test_read_disk_directory_traversals)
test_callbacks();
/* Test nodump. */
test_nodump();
+ /* Test parent overshoot. */
+ test_parent();
}
diff --git a/libarchive/test/test_read_extract.c b/libarchive/test/test_read_extract.c
index c537e4f936c4..cd06096eff69 100644
--- a/libarchive/test/test_read_extract.c
+++ b/libarchive/test/test_read_extract.c
@@ -161,7 +161,7 @@ DEFINE_TEST(test_read_extract)
assertIsDir("dir4/b", 0755);
assertIsDir("dir4/c", 0711);
if (canSymlink())
- assertIsSymlink("symlink", "file");
+ assertIsSymlink("symlink", "file", 0);
free(buff);
free(file_buff);
diff --git a/libarchive/test/test_read_format_mtree.c b/libarchive/test/test_read_format_mtree.c
index 8576d579f9c6..df6f6cde0cdb 100644
--- a/libarchive/test/test_read_format_mtree.c
+++ b/libarchive/test/test_read_format_mtree.c
@@ -717,4 +717,28 @@ DEFINE_TEST(test_read_format_mtree_nonexistent_contents_file)
assertEqualInt(ARCHIVE_OK, archive_read_close(a));
assertEqualInt(ARCHIVE_OK, archive_read_free(a));
}
+/*
+ * Check mtree file with non-printable ascii characters
+ */
+DEFINE_TEST(test_read_format_mtree_noprint)
+{
+ const char reffile[] = "test_read_format_mtree_noprint.mtree";
+ struct archive_entry *ae;
+ struct archive *a;
+ extract_reference_file(reffile);
+
+ assert((a = archive_read_new()) != NULL);
+ assertEqualIntA(a, ARCHIVE_OK,
+ archive_read_support_filter_all(a));
+ assertEqualIntA(a, ARCHIVE_OK,
+ archive_read_support_format_all(a));
+ assertEqualIntA(a, ARCHIVE_OK,
+ archive_read_open_filename(a, reffile, 11));
+
+ assertEqualIntA(a, ARCHIVE_FATAL, archive_read_next_header(a, &ae));
+ assertEqualString("Can't parse line 3", archive_error_string(a));
+
+ assertEqualInt(ARCHIVE_OK, archive_read_close(a));
+ assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+}
diff --git a/libarchive/test/test_read_format_mtree_noprint.mtree.uu b/libarchive/test/test_read_format_mtree_noprint.mtree.uu
new file mode 100644
index 000000000000..7965cdf29aec
--- /dev/null
+++ b/libarchive/test/test_read_format_mtree_noprint.mtree.uu
@@ -0,0 +1,4 @@
+begin 644 test_read_format_mtree_noprint.mtree
+K(VUT<F5E"F1I<E]O:R!T>7!E/61I<@ID:7)?P[;%H<2'('1Y<&4]9&ER"@``
+`
+end
diff --git a/libarchive/test/test_read_format_rar.c b/libarchive/test/test_read_format_rar.c
index 6392d8f50ff8..f08b06bc69a3 100644
--- a/libarchive/test/test_read_format_rar.c
+++ b/libarchive/test/test_read_format_rar.c
@@ -28,6 +28,22 @@
#include <locale.h>
+DEFINE_TEST(test_read_format_rar_set_format)
+{
+ struct archive *a;
+ struct archive_entry *ae;
+ const char reffile[] = "test_read_format_rar.rar";
+
+ extract_reference_file(reffile);
+ assert((a = archive_read_new()) != NULL);
+ assertA(0 == archive_read_support_filter_all(a));
+ assertA(0 == archive_read_set_format(a, ARCHIVE_FORMAT_RAR));
+ assertA(0 == archive_read_open_filename(a, reffile, 10240));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
+ assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+}
+
DEFINE_TEST(test_read_format_rar_basic)
{
char buff[64];
@@ -3740,3 +3756,26 @@ DEFINE_TEST(test_read_format_rar_multivolume_uncompressed_files)
assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
}
+
+DEFINE_TEST(test_read_format_rar_ppmd_use_after_free)
+{
+ uint8_t buf[16];
+ const char* reffile = "test_read_format_rar_ppmd_use_after_free.rar";
+
+ struct archive_entry *ae;
+ struct archive *a;
+
+ extract_reference_file(reffile);
+ assert((a = archive_read_new()) != NULL);
+ assertA(0 == archive_read_support_filter_all(a));
+ assertA(0 == archive_read_support_format_all(a));
+ assertA(0 == archive_read_open_filename(a, reffile, 10240));
+
+ assertA(ARCHIVE_OK == archive_read_next_header(a, &ae));
+ assertA(archive_read_data(a, buf, sizeof(buf)) <= 0);
+ assertA(ARCHIVE_OK == archive_read_next_header(a, &ae));
+ assertA(archive_read_data(a, buf, sizeof(buf)) <= 0);
+
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
+ assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+}
diff --git a/libarchive/test/test_read_format_rar5.c b/libarchive/test/test_read_format_rar5.c
index 0be9c45a5d49..1408f37c49dc 100644
--- a/libarchive/test/test_read_format_rar5.c
+++ b/libarchive/test/test_read_format_rar5.c
@@ -31,171 +31,186 @@
#include <archive_endian.h>
#define PROLOGUE(reffile) \
- struct archive_entry *ae; \
- struct archive *a; \
- \
- (void) a; /* Make the compiler happy if we won't use this variables */ \
- (void) ae; /* in the test cases. */ \
- \
- extract_reference_file(reffile); \
- assert((a = archive_read_new()) != NULL); \
- assertA(0 == archive_read_support_filter_all(a)); \
- assertA(0 == archive_read_support_format_all(a)); \
- assertA(0 == archive_read_open_filename(a, reffile, 10240))
+ struct archive_entry *ae; \
+ struct archive *a; \
+ \
+ (void) a; /* Make the compiler happy if we won't use this variables */ \
+ (void) ae; /* in the test cases. */ \
+ \
+ extract_reference_file(reffile); \
+ assert((a = archive_read_new()) != NULL); \
+ assertA(0 == archive_read_support_filter_all(a)); \
+ assertA(0 == archive_read_support_format_all(a)); \
+ assertA(0 == archive_read_open_filename(a, reffile, 10240))
#define PROLOGUE_MULTI(reffile) \
- struct archive_entry *ae; \
- struct archive *a; \
- \
- (void) a; \
- (void) ae; \
- \
- extract_reference_files(reffile); \
- assert((a = archive_read_new()) != NULL); \
- assertA(0 == archive_read_support_filter_all(a)); \
- assertA(0 == archive_read_support_format_all(a)); \
- assertA(0 == archive_read_open_filenames(a, reffile, 10240))
+ struct archive_entry *ae; \
+ struct archive *a; \
+ \
+ (void) a; \
+ (void) ae; \
+ \
+ extract_reference_files(reffile); \
+ assert((a = archive_read_new()) != NULL); \
+ assertA(0 == archive_read_support_filter_all(a)); \
+ assertA(0 == archive_read_support_format_all(a)); \
+ assertA(0 == archive_read_open_filenames(a, reffile, 10240))
#define EPILOGUE() \
- assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); \
- assertEqualInt(ARCHIVE_OK, archive_read_free(a))
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); \
+ assertEqualInt(ARCHIVE_OK, archive_read_free(a))
static
int verify_data(const uint8_t* data_ptr, int magic, int size) {
- int i = 0;
+ int i = 0;
- /* This is how the test data inside test files was generated;
- * we are re-generating it here and we check if our re-generated
- * test data is the same as in the test file. If this test is
- * failing it's either because there's a bug in the test case,
- * or the unpacked data is corrupted. */
+ /* This is how the test data inside test files was generated;
+ * we are re-generating it here and we check if our re-generated
+ * test data is the same as in the test file. If this test is
+ * failing it's either because there's a bug in the test case,
+ * or the unpacked data is corrupted. */
- for(i = 0; i < size / 4; ++i) {
- const int k = i + 1;
- const signed int* lptr = (const signed int*) &data_ptr[i * 4];
- signed int val = k * k - 3 * k + (1 + magic);
+ for(i = 0; i < size / 4; ++i) {
+ const int k = i + 1;
+ const signed int* lptr = (const signed int*) &data_ptr[i * 4];
+ signed int val = k * k - 3 * k + (1 + magic);
- if(val < 0)
- val = 0;
+ if(val < 0)
+ val = 0;
- /* *lptr is a value inside unpacked test file, val is the
- * value that should be in the unpacked test file. */
+ /* *lptr is a value inside unpacked test file, val is the
+ * value that should be in the unpacked test file. */
- if(archive_le32dec(lptr) != (uint32_t) val)
- return 0;
- }
+ if(archive_le32dec(lptr) != (uint32_t) val)
+ return 0;
+ }
- return 1;
+ return 1;
}
static
int extract_one(struct archive* a, struct archive_entry* ae, uint32_t crc) {
- la_ssize_t fsize, bytes_read;
- uint8_t* buf;
- int ret = 1;
- uint32_t computed_crc;
-
- fsize = (la_ssize_t) archive_entry_size(ae);
- buf = malloc(fsize);
- if(buf == NULL)
- return 1;
-
- bytes_read = archive_read_data(a, buf, fsize);
- if(bytes_read != fsize) {
- assertEqualInt(bytes_read, fsize);
- goto fn_exit;
- }
-
- computed_crc = crc32(0, buf, fsize);
- assertEqualInt(computed_crc, crc);
- ret = 0;
+ la_ssize_t fsize, bytes_read;
+ uint8_t* buf;
+ int ret = 1;
+ uint32_t computed_crc;
+
+ fsize = (la_ssize_t) archive_entry_size(ae);
+ buf = malloc(fsize);
+ if(buf == NULL)
+ return 1;
+
+ bytes_read = archive_read_data(a, buf, fsize);
+ if(bytes_read != fsize) {
+ assertEqualInt(bytes_read, fsize);
+ goto fn_exit;
+ }
+
+ computed_crc = crc32(0, buf, fsize);
+ assertEqualInt(computed_crc, crc);
+ ret = 0;
fn_exit:
- free(buf);
- return ret;
+ free(buf);
+ return ret;
}
-DEFINE_TEST(test_read_format_rar5_stored)
+DEFINE_TEST(test_read_format_rar5_set_format)
{
- const char helloworld_txt[] = "hello libarchive test suite!\n";
- la_ssize_t file_size = sizeof(helloworld_txt) - 1;
- char buff[64];
-
- PROLOGUE("test_read_format_rar5_stored.rar");
-
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("helloworld.txt", archive_entry_pathname(ae));
- assertA((int) archive_entry_mtime(ae) > 0);
- assertA((int) archive_entry_ctime(ae) == 0);
- assertA((int) archive_entry_atime(ae) == 0);
- assertEqualInt(file_size, archive_entry_size(ae));
- assertEqualInt(33188, archive_entry_mode(ae));
- assertA(file_size == archive_read_data(a, buff, file_size));
- assertEqualMem(buff, helloworld_txt, file_size);
- assertEqualInt(archive_entry_is_encrypted(ae), 0);
-
- assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
+ struct archive *a;
+ struct archive_entry *ae;
+ const char reffile[] = "test_read_format_rar5_stored.rar";
+
+ extract_reference_file(reffile);
+ assert((a = archive_read_new()) != NULL);
+ assertA(0 == archive_read_support_filter_all(a));
+ assertA(0 == archive_read_set_format(a, ARCHIVE_FORMAT_RAR_V5));
+ assertA(0 == archive_read_open_filename(a, reffile, 10240));
+ assertA(0 == archive_read_next_header(a, &ae));
+ EPILOGUE();
+}
- EPILOGUE();
+DEFINE_TEST(test_read_format_rar5_stored)
+{
+ const char helloworld_txt[] = "hello libarchive test suite!\n";
+ la_ssize_t file_size = sizeof(helloworld_txt) - 1;
+ char buff[64];
+
+ PROLOGUE("test_read_format_rar5_stored.rar");
+
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("helloworld.txt", archive_entry_pathname(ae));
+ assertA((int) archive_entry_mtime(ae) > 0);
+ assertA((int) archive_entry_ctime(ae) == 0);
+ assertA((int) archive_entry_atime(ae) == 0);
+ assertEqualInt(file_size, archive_entry_size(ae));
+ assertEqualInt(33188, archive_entry_mode(ae));
+ assertA(file_size == archive_read_data(a, buff, file_size));
+ assertEqualMem(buff, helloworld_txt, file_size);
+ assertEqualInt(archive_entry_is_encrypted(ae), 0);
+
+ assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
+
+ EPILOGUE();
}
DEFINE_TEST(test_read_format_rar5_compressed)
{
- const int DATA_SIZE = 1200;
- uint8_t buff[1200];
+ const int DATA_SIZE = 1200;
+ uint8_t buff[1200];
- PROLOGUE("test_read_format_rar5_compressed.rar");
+ PROLOGUE("test_read_format_rar5_compressed.rar");
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test.bin", archive_entry_pathname(ae));
- assertA((int) archive_entry_mtime(ae) > 0);
- assertEqualInt(DATA_SIZE, archive_entry_size(ae));
- assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
- assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
- verify_data(buff, 0, DATA_SIZE);
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test.bin", archive_entry_pathname(ae));
+ assertA((int) archive_entry_mtime(ae) > 0);
+ assertEqualInt(DATA_SIZE, archive_entry_size(ae));
+ assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
+ assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
+ verify_data(buff, 0, DATA_SIZE);
- EPILOGUE();
+ EPILOGUE();
}
DEFINE_TEST(test_read_format_rar5_multiple_files)
{
- const int DATA_SIZE = 4096;
- uint8_t buff[4096];
-
- PROLOGUE("test_read_format_rar5_multiple_files.rar");
-
- /* There should be 4 files inside this test file. Check for their
- * existence, and also check the contents of those test files. */
-
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test1.bin", archive_entry_pathname(ae));
- assertEqualInt(DATA_SIZE, archive_entry_size(ae));
- assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
- assertA(verify_data(buff, 1, DATA_SIZE));
-
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test2.bin", archive_entry_pathname(ae));
- assertEqualInt(DATA_SIZE, archive_entry_size(ae));
- assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
- assertA(verify_data(buff, 2, DATA_SIZE));
-
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test3.bin", archive_entry_pathname(ae));
- assertEqualInt(DATA_SIZE, archive_entry_size(ae));
- assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
- assertA(verify_data(buff, 3, DATA_SIZE));
-
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test4.bin", archive_entry_pathname(ae));
- assertEqualInt(DATA_SIZE, archive_entry_size(ae));
- assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
- assertA(verify_data(buff, 4, DATA_SIZE));
-
- /* There should be no more files in this archive. */
-
- assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
- EPILOGUE();
+ const int DATA_SIZE = 4096;
+ uint8_t buff[4096];
+
+ PROLOGUE("test_read_format_rar5_multiple_files.rar");
+
+ /* There should be 4 files inside this test file. Check for their
+ * existence, and also check the contents of those test files. */
+
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test1.bin", archive_entry_pathname(ae));
+ assertEqualInt(DATA_SIZE, archive_entry_size(ae));
+ assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
+ assertA(verify_data(buff, 1, DATA_SIZE));
+
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test2.bin", archive_entry_pathname(ae));
+ assertEqualInt(DATA_SIZE, archive_entry_size(ae));
+ assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
+ assertA(verify_data(buff, 2, DATA_SIZE));
+
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test3.bin", archive_entry_pathname(ae));
+ assertEqualInt(DATA_SIZE, archive_entry_size(ae));
+ assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
+ assertA(verify_data(buff, 3, DATA_SIZE));
+
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test4.bin", archive_entry_pathname(ae));
+ assertEqualInt(DATA_SIZE, archive_entry_size(ae));
+ assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
+ assertA(verify_data(buff, 4, DATA_SIZE));
+
+ /* There should be no more files in this archive. */
+
+ assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
+ EPILOGUE();
}
/* This test is really the same as the test above, but it deals with a solid
@@ -206,291 +221,342 @@ DEFINE_TEST(test_read_format_rar5_multiple_files)
DEFINE_TEST(test_read_format_rar5_multiple_files_solid)
{
- const int DATA_SIZE = 4096;
- uint8_t buff[4096];
-
- PROLOGUE("test_read_format_rar5_multiple_files_solid.rar");
-
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test1.bin", archive_entry_pathname(ae));
- assertEqualInt(DATA_SIZE, archive_entry_size(ae));
- assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
- assertA(verify_data(buff, 1, DATA_SIZE));
-
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test2.bin", archive_entry_pathname(ae));
- assertEqualInt(DATA_SIZE, archive_entry_size(ae));
- assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
- assertA(verify_data(buff, 2, DATA_SIZE));
-
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test3.bin", archive_entry_pathname(ae));
- assertEqualInt(DATA_SIZE, archive_entry_size(ae));
- assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
- assertA(verify_data(buff, 3, DATA_SIZE));
-
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test4.bin", archive_entry_pathname(ae));
- assertEqualInt(DATA_SIZE, archive_entry_size(ae));
- assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
- assertA(verify_data(buff, 4, DATA_SIZE));
-
- assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
- EPILOGUE();
+ const int DATA_SIZE = 4096;
+ uint8_t buff[4096];
+
+ PROLOGUE("test_read_format_rar5_multiple_files_solid.rar");
+
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test1.bin", archive_entry_pathname(ae));
+ assertEqualInt(DATA_SIZE, archive_entry_size(ae));
+ assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
+ assertA(verify_data(buff, 1, DATA_SIZE));
+
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test2.bin", archive_entry_pathname(ae));
+ assertEqualInt(DATA_SIZE, archive_entry_size(ae));
+ assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
+ assertA(verify_data(buff, 2, DATA_SIZE));
+
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test3.bin", archive_entry_pathname(ae));
+ assertEqualInt(DATA_SIZE, archive_entry_size(ae));
+ assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
+ assertA(verify_data(buff, 3, DATA_SIZE));
+
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test4.bin", archive_entry_pathname(ae));
+ assertEqualInt(DATA_SIZE, archive_entry_size(ae));
+ assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
+ assertA(verify_data(buff, 4, DATA_SIZE));
+
+ assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
+ EPILOGUE();
}
DEFINE_TEST(test_read_format_rar5_multiarchive_skip_all)
{
- const char* reffiles[] = {
- "test_read_format_rar5_multiarchive.part01.rar",
- "test_read_format_rar5_multiarchive.part02.rar",
- "test_read_format_rar5_multiarchive.part03.rar",
- "test_read_format_rar5_multiarchive.part04.rar",
- "test_read_format_rar5_multiarchive.part05.rar",
- "test_read_format_rar5_multiarchive.part06.rar",
- "test_read_format_rar5_multiarchive.part07.rar",
- "test_read_format_rar5_multiarchive.part08.rar",
- NULL
- };
-
- PROLOGUE_MULTI(reffiles);
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("home/antek/temp/build/unrar5/libarchive/bin/bsdcat_test", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("home/antek/temp/build/unrar5/libarchive/bin/bsdtar_test", archive_entry_pathname(ae));
- assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
- EPILOGUE();
+ const char* reffiles[] = {
+ "test_read_format_rar5_multiarchive.part01.rar",
+ "test_read_format_rar5_multiarchive.part02.rar",
+ "test_read_format_rar5_multiarchive.part03.rar",
+ "test_read_format_rar5_multiarchive.part04.rar",
+ "test_read_format_rar5_multiarchive.part05.rar",
+ "test_read_format_rar5_multiarchive.part06.rar",
+ "test_read_format_rar5_multiarchive.part07.rar",
+ "test_read_format_rar5_multiarchive.part08.rar",
+ NULL
+ };
+
+ PROLOGUE_MULTI(reffiles);
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("home/antek/temp/build/unrar5/libarchive/bin/bsdcat_test", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("home/antek/temp/build/unrar5/libarchive/bin/bsdtar_test", archive_entry_pathname(ae));
+ assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
+ EPILOGUE();
}
DEFINE_TEST(test_read_format_rar5_multiarchive_skip_all_but_first)
{
- const char* reffiles[] = {
- "test_read_format_rar5_multiarchive.part01.rar",
- "test_read_format_rar5_multiarchive.part02.rar",
- "test_read_format_rar5_multiarchive.part03.rar",
- "test_read_format_rar5_multiarchive.part04.rar",
- "test_read_format_rar5_multiarchive.part05.rar",
- "test_read_format_rar5_multiarchive.part06.rar",
- "test_read_format_rar5_multiarchive.part07.rar",
- "test_read_format_rar5_multiarchive.part08.rar",
- NULL
- };
-
- PROLOGUE_MULTI(reffiles);
- assertA(0 == archive_read_next_header(a, &ae));
- assertA(0 == extract_one(a, ae, 0x35277473));
- assertA(0 == archive_read_next_header(a, &ae));
- assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
- EPILOGUE();
+ const char* reffiles[] = {
+ "test_read_format_rar5_multiarchive.part01.rar",
+ "test_read_format_rar5_multiarchive.part02.rar",
+ "test_read_format_rar5_multiarchive.part03.rar",
+ "test_read_format_rar5_multiarchive.part04.rar",
+ "test_read_format_rar5_multiarchive.part05.rar",
+ "test_read_format_rar5_multiarchive.part06.rar",
+ "test_read_format_rar5_multiarchive.part07.rar",
+ "test_read_format_rar5_multiarchive.part08.rar",
+ NULL
+ };
+
+ PROLOGUE_MULTI(reffiles);
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertA(0 == extract_one(a, ae, 0x35277473));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
+ EPILOGUE();
}
DEFINE_TEST(test_read_format_rar5_multiarchive_skip_all_but_second)
{
- const char* reffiles[] = {
- "test_read_format_rar5_multiarchive.part01.rar",
- "test_read_format_rar5_multiarchive.part02.rar",
- "test_read_format_rar5_multiarchive.part03.rar",
- "test_read_format_rar5_multiarchive.part04.rar",
- "test_read_format_rar5_multiarchive.part05.rar",
- "test_read_format_rar5_multiarchive.part06.rar",
- "test_read_format_rar5_multiarchive.part07.rar",
- "test_read_format_rar5_multiarchive.part08.rar",
- NULL
- };
-
- PROLOGUE_MULTI(reffiles);
- assertA(0 == archive_read_next_header(a, &ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertA(0 == extract_one(a, ae, 0xE59665F8));
- assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
- EPILOGUE();
+ const char* reffiles[] = {
+ "test_read_format_rar5_multiarchive.part01.rar",
+ "test_read_format_rar5_multiarchive.part02.rar",
+ "test_read_format_rar5_multiarchive.part03.rar",
+ "test_read_format_rar5_multiarchive.part04.rar",
+ "test_read_format_rar5_multiarchive.part05.rar",
+ "test_read_format_rar5_multiarchive.part06.rar",
+ "test_read_format_rar5_multiarchive.part07.rar",
+ "test_read_format_rar5_multiarchive.part08.rar",
+ NULL
+ };
+
+ PROLOGUE_MULTI(reffiles);
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertA(0 == extract_one(a, ae, 0xE59665F8));
+ assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
+ EPILOGUE();
}
DEFINE_TEST(test_read_format_rar5_blake2)
{
- const la_ssize_t proper_size = 814;
- uint8_t buf[814];
+ const la_ssize_t proper_size = 814;
+ uint8_t buf[814];
- PROLOGUE("test_read_format_rar5_blake2.rar");
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualInt(proper_size, archive_entry_size(ae));
+ PROLOGUE("test_read_format_rar5_blake2.rar");
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualInt(proper_size, archive_entry_size(ae));
- /* Should blake2 calculation fail, we'll get a failure return
- * value from archive_read_data(). */
+ /* Should blake2 calculation fail, we'll get a failure return
+ * value from archive_read_data(). */
- assertA(proper_size == archive_read_data(a, buf, proper_size));
+ assertA(proper_size == archive_read_data(a, buf, proper_size));
- /* To be extra pedantic, let's also check crc32 of the poem. */
- assertEqualInt(crc32(0, buf, proper_size), 0x7E5EC49E);
+ /* To be extra pedantic, let's also check crc32 of the poem. */
+ assertEqualInt(crc32(0, buf, proper_size), 0x7E5EC49E);
- assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
- EPILOGUE();
+ assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
+ EPILOGUE();
}
DEFINE_TEST(test_read_format_rar5_arm_filter)
{
- /* This test unpacks a file that uses an ARM filter. The DELTA
- * and X86 filters are tested implicitly in the "multiarchive_skip"
- * test. */
+ /* This test unpacks a file that uses an ARM filter. The DELTA
+ * and X86 filters are tested implicitly in the "multiarchive_skip"
+ * test. */
- const la_ssize_t proper_size = 90808;
- uint8_t buf[90808];
+ const la_ssize_t proper_size = 90808;
+ uint8_t buf[90808];
- PROLOGUE("test_read_format_rar5_arm.rar");
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualInt(proper_size, archive_entry_size(ae));
- assertA(proper_size == archive_read_data(a, buf, proper_size));
+ PROLOGUE("test_read_format_rar5_arm.rar");
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualInt(proper_size, archive_entry_size(ae));
+ assertA(proper_size == archive_read_data(a, buf, proper_size));
- /* Yes, RARv5 unpacker itself should calculate the CRC, but in case
- * the DONT_FAIL_ON_CRC_ERROR define option is enabled during compilation,
- * let's still fail the test if the unpacked data is wrong. */
- assertEqualInt(crc32(0, buf, proper_size), 0x886F91EB);
+ /* Yes, RARv5 unpacker itself should calculate the CRC, but in case
+ * the DONT_FAIL_ON_CRC_ERROR define option is enabled during compilation,
+ * let's still fail the test if the unpacked data is wrong. */
+ assertEqualInt(crc32(0, buf, proper_size), 0x886F91EB);
- assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
- EPILOGUE();
+ assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
+ EPILOGUE();
}
DEFINE_TEST(test_read_format_rar5_stored_skip_all)
{
- const char* fname = "test_read_format_rar5_stored_manyfiles.rar";
-
- PROLOGUE(fname);
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("make_uue.tcl", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("cebula.txt", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test.bin", archive_entry_pathname(ae));
- assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
- EPILOGUE();
+ const char* fname = "test_read_format_rar5_stored_manyfiles.rar";
+
+ PROLOGUE(fname);
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("make_uue.tcl", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("cebula.txt", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test.bin", archive_entry_pathname(ae));
+ assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
+ EPILOGUE();
}
DEFINE_TEST(test_read_format_rar5_stored_skip_in_part)
{
- const char* fname = "test_read_format_rar5_stored_manyfiles.rar";
- char buf[6];
-
- /* Skip first, extract in part rest. */
-
- PROLOGUE(fname);
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("make_uue.tcl", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("cebula.txt", archive_entry_pathname(ae));
- assertA(6 == archive_read_data(a, buf, 6));
- assertEqualInt(0, memcmp(buf, "Cebula", 6));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test.bin", archive_entry_pathname(ae));
- assertA(4 == archive_read_data(a, buf, 4));
- assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
- EPILOGUE();
+ const char* fname = "test_read_format_rar5_stored_manyfiles.rar";
+ char buf[6];
+
+ /* Skip first, extract in part rest. */
+
+ PROLOGUE(fname);
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("make_uue.tcl", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("cebula.txt", archive_entry_pathname(ae));
+ assertA(6 == archive_read_data(a, buf, 6));
+ assertEqualInt(0, memcmp(buf, "Cebula", 6));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test.bin", archive_entry_pathname(ae));
+ assertA(4 == archive_read_data(a, buf, 4));
+ assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
+ EPILOGUE();
}
DEFINE_TEST(test_read_format_rar5_stored_skip_all_but_first)
{
- const char* fname = "test_read_format_rar5_stored_manyfiles.rar";
- char buf[405];
-
- /* Extract first, skip rest. */
-
- PROLOGUE(fname);
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("make_uue.tcl", archive_entry_pathname(ae));
- assertA(405 == archive_read_data(a, buf, sizeof(buf)));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("cebula.txt", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test.bin", archive_entry_pathname(ae));
- assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
- EPILOGUE();
+ const char* fname = "test_read_format_rar5_stored_manyfiles.rar";
+ char buf[405];
+
+ /* Extract first, skip rest. */
+
+ PROLOGUE(fname);
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("make_uue.tcl", archive_entry_pathname(ae));
+ assertA(405 == archive_read_data(a, buf, sizeof(buf)));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("cebula.txt", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test.bin", archive_entry_pathname(ae));
+ assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
+ EPILOGUE();
}
DEFINE_TEST(test_read_format_rar5_stored_skip_all_in_part)
{
- const char* fname = "test_read_format_rar5_stored_manyfiles.rar";
- char buf[4];
-
- /* Extract in part all */
+ const char* fname = "test_read_format_rar5_stored_manyfiles.rar";
+ char buf[4];
+
+ /* Extract in part all */
+
+ PROLOGUE(fname);
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("make_uue.tcl", archive_entry_pathname(ae));
+ assertA(4 == archive_read_data(a, buf, 4));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("cebula.txt", archive_entry_pathname(ae));
+ assertA(4 == archive_read_data(a, buf, 4));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test.bin", archive_entry_pathname(ae));
+ assertA(4 == archive_read_data(a, buf, 4));
+ assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
+ EPILOGUE();
+}
- PROLOGUE(fname);
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("make_uue.tcl", archive_entry_pathname(ae));
- assertA(4 == archive_read_data(a, buf, 4));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("cebula.txt", archive_entry_pathname(ae));
- assertA(4 == archive_read_data(a, buf, 4));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test.bin", archive_entry_pathname(ae));
- assertA(4 == archive_read_data(a, buf, 4));
- assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
- EPILOGUE();
+DEFINE_TEST(test_read_format_rar5_multiarchive_solid_extr_all)
+{
+ const char* reffiles[] = {
+ "test_read_format_rar5_multiarchive_solid.part01.rar",
+ "test_read_format_rar5_multiarchive_solid.part02.rar",
+ "test_read_format_rar5_multiarchive_solid.part03.rar",
+ "test_read_format_rar5_multiarchive_solid.part04.rar",
+ NULL
+ };
+
+ PROLOGUE_MULTI(reffiles);
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("cebula.txt", archive_entry_pathname(ae));
+ assertA(0 == extract_one(a, ae, 0x7E5EC49E));
+
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test.bin", archive_entry_pathname(ae));
+ assertA(0 == extract_one(a, ae, 0x7cca70cd));
+
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test1.bin", archive_entry_pathname(ae));
+ assertA(0 == extract_one(a, ae, 0x7e13b2c6));
+
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test2.bin", archive_entry_pathname(ae));
+ assertA(0 == extract_one(a, ae, 0xf166afcb));
+
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test3.bin", archive_entry_pathname(ae));
+ assertA(0 == extract_one(a, ae, 0x9fb123d9));
+
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test4.bin", archive_entry_pathname(ae));
+ assertA(0 == extract_one(a, ae, 0x10c43ed4));
+
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test5.bin", archive_entry_pathname(ae));
+ assertA(0 == extract_one(a, ae, 0xb9d155f2));
+
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test6.bin", archive_entry_pathname(ae));
+ assertA(0 == extract_one(a, ae, 0x36a448ff));
+
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("elf-Linux-ARMv7-ls", archive_entry_pathname(ae));
+ assertA(0 == extract_one(a, ae, 0x886F91EB));
+
+ assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
+ EPILOGUE();
}
DEFINE_TEST(test_read_format_rar5_multiarchive_solid_skip_all)
{
- const char* reffiles[] = {
- "test_read_format_rar5_multiarchive_solid.part01.rar",
- "test_read_format_rar5_multiarchive_solid.part02.rar",
- "test_read_format_rar5_multiarchive_solid.part03.rar",
- "test_read_format_rar5_multiarchive_solid.part04.rar",
- NULL
- };
-
- PROLOGUE_MULTI(reffiles);
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("cebula.txt", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test1.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test2.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test3.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test4.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test5.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test6.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("elf-Linux-ARMv7-ls", archive_entry_pathname(ae));
- assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
- EPILOGUE();
+ const char* reffiles[] = {
+ "test_read_format_rar5_multiarchive_solid.part01.rar",
+ "test_read_format_rar5_multiarchive_solid.part02.rar",
+ "test_read_format_rar5_multiarchive_solid.part03.rar",
+ "test_read_format_rar5_multiarchive_solid.part04.rar",
+ NULL
+ };
+
+ PROLOGUE_MULTI(reffiles);
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("cebula.txt", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test1.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test2.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test3.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test4.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test5.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test6.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("elf-Linux-ARMv7-ls", archive_entry_pathname(ae));
+ assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
+ EPILOGUE();
}
DEFINE_TEST(test_read_format_rar5_multiarchive_solid_skip_all_but_first)
{
- const char* reffiles[] = {
- "test_read_format_rar5_multiarchive_solid.part01.rar",
- "test_read_format_rar5_multiarchive_solid.part02.rar",
- "test_read_format_rar5_multiarchive_solid.part03.rar",
- "test_read_format_rar5_multiarchive_solid.part04.rar",
- NULL
- };
-
- PROLOGUE_MULTI(reffiles);
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("cebula.txt", archive_entry_pathname(ae));
- assertA(0 == extract_one(a, ae, 0x7E5EC49E));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test1.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test2.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test3.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test4.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test5.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test6.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("elf-Linux-ARMv7-ls", archive_entry_pathname(ae));
- assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
- EPILOGUE();
+ const char* reffiles[] = {
+ "test_read_format_rar5_multiarchive_solid.part01.rar",
+ "test_read_format_rar5_multiarchive_solid.part02.rar",
+ "test_read_format_rar5_multiarchive_solid.part03.rar",
+ "test_read_format_rar5_multiarchive_solid.part04.rar",
+ NULL
+ };
+
+ PROLOGUE_MULTI(reffiles);
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("cebula.txt", archive_entry_pathname(ae));
+ assertA(0 == extract_one(a, ae, 0x7E5EC49E));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test1.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test2.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test3.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test4.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test5.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test6.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("elf-Linux-ARMv7-ls", archive_entry_pathname(ae));
+ assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
+ EPILOGUE();
}
/* "skip_all_but_scnd" -> am I hitting the test name limit here after
@@ -498,273 +564,633 @@ DEFINE_TEST(test_read_format_rar5_multiarchive_solid_skip_all_but_first)
DEFINE_TEST(test_read_format_rar5_multiarchive_solid_skip_all_but_scnd)
{
- const char* reffiles[] = {
- "test_read_format_rar5_multiarchive_solid.part01.rar",
- "test_read_format_rar5_multiarchive_solid.part02.rar",
- "test_read_format_rar5_multiarchive_solid.part03.rar",
- "test_read_format_rar5_multiarchive_solid.part04.rar",
- NULL
- };
-
- PROLOGUE_MULTI(reffiles);
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("cebula.txt", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test.bin", archive_entry_pathname(ae));
- assertA(0 == extract_one(a, ae, 0x7CCA70CD));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test1.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test2.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test3.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test4.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test5.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test6.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("elf-Linux-ARMv7-ls", archive_entry_pathname(ae));
- assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
- EPILOGUE();
+ const char* reffiles[] = {
+ "test_read_format_rar5_multiarchive_solid.part01.rar",
+ "test_read_format_rar5_multiarchive_solid.part02.rar",
+ "test_read_format_rar5_multiarchive_solid.part03.rar",
+ "test_read_format_rar5_multiarchive_solid.part04.rar",
+ NULL
+ };
+
+ PROLOGUE_MULTI(reffiles);
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("cebula.txt", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test.bin", archive_entry_pathname(ae));
+ assertA(0 == extract_one(a, ae, 0x7CCA70CD));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test1.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test2.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test3.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test4.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test5.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test6.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("elf-Linux-ARMv7-ls", archive_entry_pathname(ae));
+ assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
+ EPILOGUE();
}
DEFINE_TEST(test_read_format_rar5_multiarchive_solid_skip_all_but_third)
{
- const char* reffiles[] = {
- "test_read_format_rar5_multiarchive_solid.part01.rar",
- "test_read_format_rar5_multiarchive_solid.part02.rar",
- "test_read_format_rar5_multiarchive_solid.part03.rar",
- "test_read_format_rar5_multiarchive_solid.part04.rar",
- NULL
- };
-
- PROLOGUE_MULTI(reffiles);
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("cebula.txt", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test1.bin", archive_entry_pathname(ae));
- assertA(0 == extract_one(a, ae, 0x7E13B2C6));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test2.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test3.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test4.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test5.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test6.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("elf-Linux-ARMv7-ls", archive_entry_pathname(ae));
- assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
- EPILOGUE();
+ const char* reffiles[] = {
+ "test_read_format_rar5_multiarchive_solid.part01.rar",
+ "test_read_format_rar5_multiarchive_solid.part02.rar",
+ "test_read_format_rar5_multiarchive_solid.part03.rar",
+ "test_read_format_rar5_multiarchive_solid.part04.rar",
+ NULL
+ };
+
+ PROLOGUE_MULTI(reffiles);
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("cebula.txt", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test1.bin", archive_entry_pathname(ae));
+ assertA(0 == extract_one(a, ae, 0x7E13B2C6));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test2.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test3.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test4.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test5.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test6.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("elf-Linux-ARMv7-ls", archive_entry_pathname(ae));
+ assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
+ EPILOGUE();
}
DEFINE_TEST(test_read_format_rar5_multiarchive_solid_skip_all_but_last)
{
- const char* reffiles[] = {
- "test_read_format_rar5_multiarchive_solid.part01.rar",
- "test_read_format_rar5_multiarchive_solid.part02.rar",
- "test_read_format_rar5_multiarchive_solid.part03.rar",
- "test_read_format_rar5_multiarchive_solid.part04.rar",
- NULL
- };
-
- PROLOGUE_MULTI(reffiles);
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("cebula.txt", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test1.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test2.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test3.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test4.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test5.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test6.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("elf-Linux-ARMv7-ls", archive_entry_pathname(ae));
- assertA(0 == extract_one(a, ae, 0x886F91EB));
- assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
- EPILOGUE();
+ const char* reffiles[] = {
+ "test_read_format_rar5_multiarchive_solid.part01.rar",
+ "test_read_format_rar5_multiarchive_solid.part02.rar",
+ "test_read_format_rar5_multiarchive_solid.part03.rar",
+ "test_read_format_rar5_multiarchive_solid.part04.rar",
+ NULL
+ };
+
+ PROLOGUE_MULTI(reffiles);
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("cebula.txt", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test1.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test2.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test3.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test4.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test5.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test6.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("elf-Linux-ARMv7-ls", archive_entry_pathname(ae));
+ assertA(0 == extract_one(a, ae, 0x886F91EB));
+ assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
+ EPILOGUE();
}
DEFINE_TEST(test_read_format_rar5_solid_skip_all)
{
- const char* reffile = "test_read_format_rar5_solid.rar";
-
- /* Skip all */
-
- PROLOGUE(reffile);
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test1.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test2.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test3.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test4.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test5.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test6.bin", archive_entry_pathname(ae));
- assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
- EPILOGUE();
+ const char* reffile = "test_read_format_rar5_solid.rar";
+
+ /* Skip all */
+
+ PROLOGUE(reffile);
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test1.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test2.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test3.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test4.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test5.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test6.bin", archive_entry_pathname(ae));
+ assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
+ EPILOGUE();
}
DEFINE_TEST(test_read_format_rar5_solid_skip_all_but_first)
{
- const char* reffile = "test_read_format_rar5_solid.rar";
-
- /* Extract first, skip rest */
-
- PROLOGUE(reffile);
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test.bin", archive_entry_pathname(ae));
- assertA(0 == extract_one(a, ae, 0x7CCA70CD));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test1.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test2.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test3.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test4.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test5.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test6.bin", archive_entry_pathname(ae));
- assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
- EPILOGUE();
+ const char* reffile = "test_read_format_rar5_solid.rar";
+
+ /* Extract first, skip rest */
+
+ PROLOGUE(reffile);
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test.bin", archive_entry_pathname(ae));
+ assertA(0 == extract_one(a, ae, 0x7CCA70CD));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test1.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test2.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test3.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test4.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test5.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test6.bin", archive_entry_pathname(ae));
+ assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
+ EPILOGUE();
}
DEFINE_TEST(test_read_format_rar5_solid_skip_all_but_second)
{
- const char* reffile = "test_read_format_rar5_solid.rar";
-
- /* Skip first, extract second, skip rest */
-
- PROLOGUE(reffile);
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test1.bin", archive_entry_pathname(ae));
- assertA(0 == extract_one(a, ae, 0x7E13B2C6));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test2.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test3.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test4.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test5.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test6.bin", archive_entry_pathname(ae));
- assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
- EPILOGUE();
+ const char* reffile = "test_read_format_rar5_solid.rar";
+
+ /* Skip first, extract second, skip rest */
+
+ PROLOGUE(reffile);
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test1.bin", archive_entry_pathname(ae));
+ assertA(0 == extract_one(a, ae, 0x7E13B2C6));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test2.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test3.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test4.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test5.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test6.bin", archive_entry_pathname(ae));
+ assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
+ EPILOGUE();
}
DEFINE_TEST(test_read_format_rar5_solid_skip_all_but_last)
{
- const char* reffile = "test_read_format_rar5_solid.rar";
-
- /* Skip all but last, extract last */
-
- PROLOGUE(reffile);
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test1.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test2.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test3.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test4.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test5.bin", archive_entry_pathname(ae));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test6.bin", archive_entry_pathname(ae));
- assertA(0 == extract_one(a, ae, 0x36A448FF));
- assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
- EPILOGUE();
+ const char* reffile = "test_read_format_rar5_solid.rar";
+
+ /* Skip all but last, extract last */
+
+ PROLOGUE(reffile);
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test1.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test2.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test3.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test4.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test5.bin", archive_entry_pathname(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test6.bin", archive_entry_pathname(ae));
+ assertA(0 == extract_one(a, ae, 0x36A448FF));
+ assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
+ EPILOGUE();
}
DEFINE_TEST(test_read_format_rar5_extract_win32)
{
- PROLOGUE("test_read_format_rar5_win32.rar");
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test.bin", archive_entry_pathname(ae));
- assertA(0 == extract_one(a, ae, 0x7CCA70CD));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test1.bin", archive_entry_pathname(ae));
- assertA(0 == extract_one(a, ae, 0x7E13B2C6));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test2.bin", archive_entry_pathname(ae));
- assertA(0 == extract_one(a, ae, 0xF166AFCB));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test3.bin", archive_entry_pathname(ae));
- assertA(0 == extract_one(a, ae, 0x9FB123D9));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test4.bin", archive_entry_pathname(ae));
- assertA(0 == extract_one(a, ae, 0x10C43ED4));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test5.bin", archive_entry_pathname(ae));
- assertA(0 == extract_one(a, ae, 0xB9D155F2));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test6.bin", archive_entry_pathname(ae));
- assertA(0 == extract_one(a, ae, 0x36A448FF));
- EPILOGUE();
+ PROLOGUE("test_read_format_rar5_win32.rar");
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("testdir", archive_entry_pathname(ae));
+ assertEqualInt(archive_entry_mode(ae), AE_IFDIR | 0755);
+ assertA(0 == extract_one(a, ae, 0));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test.bin", archive_entry_pathname(ae));
+ assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0644);
+ assertA(0 == extract_one(a, ae, 0x7CCA70CD));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test1.bin", archive_entry_pathname(ae));
+ assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0644);
+ assertA(0 == extract_one(a, ae, 0x7E13B2C6));
+ assertA(0 == archive_read_next_header(a, &ae));
+ /* Read only file */
+ assertEqualString("test2.bin", archive_entry_pathname(ae));
+ assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0444);
+ assertA(0 == extract_one(a, ae, 0xF166AFCB));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test3.bin", archive_entry_pathname(ae));
+ assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0644);
+ assertA(0 == extract_one(a, ae, 0x9FB123D9));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test4.bin", archive_entry_pathname(ae));
+ assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0644);
+ assertA(0 == extract_one(a, ae, 0x10C43ED4));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test5.bin", archive_entry_pathname(ae));
+ assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0644);
+ assertA(0 == extract_one(a, ae, 0xB9D155F2));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test6.bin", archive_entry_pathname(ae));
+ assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0644);
+ assertA(0 == extract_one(a, ae, 0x36A448FF));
+ EPILOGUE();
}
DEFINE_TEST(test_read_format_rar5_block_by_block)
{
- /* This test uses strange buffer sizes intentionally. */
-
- struct archive_entry *ae;
- struct archive *a;
- uint8_t buf[173];
- int bytes_read;
- uint32_t computed_crc = 0;
-
- extract_reference_file("test_read_format_rar5_compressed.rar");
- assert((a = archive_read_new()) != NULL);
- assertA(0 == archive_read_support_filter_all(a));
- assertA(0 == archive_read_support_format_all(a));
- assertA(0 == archive_read_open_filename(a, "test_read_format_rar5_compressed.rar", 130));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test.bin", archive_entry_pathname(ae));
- assertEqualInt(1200, archive_entry_size(ae));
-
- /* File size is 1200 bytes, we're reading it using a buffer of 173 bytes.
- * Libarchive is configured to use a buffer of 130 bytes. */
-
- while(1) {
- /* archive_read_data should return one of:
- * a) 0, if there is no more data to be read,
- * b) negative value, if there was an error,
- * c) positive value, meaning how many bytes were read.
- */
-
- bytes_read = archive_read_data(a, buf, sizeof(buf));
- assertA(bytes_read >= 0);
- if(bytes_read <= 0)
- break;
-
- computed_crc = crc32(computed_crc, buf, bytes_read);
- }
-
- assertEqualInt(computed_crc, 0x7CCA70CD);
- EPILOGUE();
+ /* This test uses strange buffer sizes intentionally. */
+
+ struct archive_entry *ae;
+ struct archive *a;
+ uint8_t buf[173];
+ int bytes_read;
+ uint32_t computed_crc = 0;
+
+ extract_reference_file("test_read_format_rar5_compressed.rar");
+ assert((a = archive_read_new()) != NULL);
+ assertA(0 == archive_read_support_filter_all(a));
+ assertA(0 == archive_read_support_format_all(a));
+ assertA(0 == archive_read_open_filename(a, "test_read_format_rar5_compressed.rar", 130));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test.bin", archive_entry_pathname(ae));
+ assertEqualInt(1200, archive_entry_size(ae));
+
+ /* File size is 1200 bytes, we're reading it using a buffer of 173 bytes.
+ * Libarchive is configured to use a buffer of 130 bytes. */
+
+ while(1) {
+ /* archive_read_data should return one of:
+ * a) 0, if there is no more data to be read,
+ * b) negative value, if there was an error,
+ * c) positive value, meaning how many bytes were read.
+ */
+
+ bytes_read = archive_read_data(a, buf, sizeof(buf));
+ assertA(bytes_read >= 0);
+ if(bytes_read <= 0)
+ break;
+
+ computed_crc = crc32(computed_crc, buf, bytes_read);
+ }
+
+ assertEqualInt(computed_crc, 0x7CCA70CD);
+ EPILOGUE();
+}
+
+DEFINE_TEST(test_read_format_rar5_owner)
+{
+ const int DATA_SIZE = 5;
+ uint8_t buff[5];
+
+ PROLOGUE("test_read_format_rar5_owner.rar");
+
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("root.txt", archive_entry_pathname(ae));
+ assertEqualString("root", archive_entry_uname(ae));
+ assertEqualString("wheel", archive_entry_gname(ae));
+ assertA((int) archive_entry_mtime(ae) > 0);
+ assertEqualInt(DATA_SIZE, archive_entry_size(ae));
+ assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
+
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("nobody.txt", archive_entry_pathname(ae));
+ assertEqualString("nobody", archive_entry_uname(ae));
+ assertEqualString("nogroup", archive_entry_gname(ae));
+ assertA((int) archive_entry_mtime(ae) > 0);
+ assertEqualInt(DATA_SIZE, archive_entry_size(ae));
+ assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
+
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("numeric.txt", archive_entry_pathname(ae));
+ assertEqualInt(9999, archive_entry_uid(ae));
+ assertEqualInt(8888, archive_entry_gid(ae));
+ assertA((int) archive_entry_mtime(ae) > 0);
+ assertEqualInt(DATA_SIZE, archive_entry_size(ae));
+ assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
+
+ assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
+
+ EPILOGUE();
+}
+
+DEFINE_TEST(test_read_format_rar5_symlink)
+{
+ const int DATA_SIZE = 5;
+ uint8_t buff[5];
+
+ PROLOGUE("test_read_format_rar5_symlink.rar");
+
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("file.txt", archive_entry_pathname(ae));
+ assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
+ assertA((int) archive_entry_mtime(ae) > 0);
+ assertEqualInt(DATA_SIZE, archive_entry_size(ae));
+ assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
+
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("symlink.txt", archive_entry_pathname(ae));
+ assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
+ assertEqualString("file.txt", archive_entry_symlink(ae));
+ assertEqualInt(AE_SYMLINK_TYPE_FILE, archive_entry_symlink_type(ae));
+ assertA(0 == archive_read_data(a, NULL, archive_entry_size(ae)));
+
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("dirlink", archive_entry_pathname(ae));
+ assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
+ assertEqualString("dir", archive_entry_symlink(ae));
+ assertEqualInt(AE_SYMLINK_TYPE_DIRECTORY, archive_entry_symlink_type(ae));
+ assertA(0 == archive_read_data(a, NULL, archive_entry_size(ae)));
+
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("dir", archive_entry_pathname(ae));
+ assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
+ assertA(0 == archive_read_data(a, NULL, archive_entry_size(ae)));
+
+ assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
+
+ EPILOGUE();
+}
+
+DEFINE_TEST(test_read_format_rar5_hardlink)
+{
+ const int DATA_SIZE = 5;
+ uint8_t buff[5];
+
+ PROLOGUE("test_read_format_rar5_hardlink.rar");
+
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("file.txt", archive_entry_pathname(ae));
+ assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
+ assertA((int) archive_entry_mtime(ae) > 0);
+ assertEqualInt(DATA_SIZE, archive_entry_size(ae));
+ assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
+
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("hardlink.txt", archive_entry_pathname(ae));
+ assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
+ assertEqualString("file.txt", archive_entry_hardlink(ae));
+ assertA(0 == archive_read_data(a, NULL, archive_entry_size(ae)));
+
+ assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
+
+ EPILOGUE();
+}
+
+DEFINE_TEST(test_read_format_rar5_extra_field_version)
+{
+ PROLOGUE("test_read_format_rar5_extra_field_version.rar");
+
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("bin/2to3;1", archive_entry_pathname(ae));
+ assertA(0 == extract_one(a, ae, 0xF24181B7));
+
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("bin/2to3", archive_entry_pathname(ae));
+ assertA(0 == extract_one(a, ae, 0xF24181B7));
+
+ assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
+
+ EPILOGUE();
+}
+
+DEFINE_TEST(test_read_format_rar5_readtables_overflow)
+{
+ uint8_t buf[16];
+
+ PROLOGUE("test_read_format_rar5_readtables_overflow.rar");
+
+ assertA(0 == archive_read_next_header(a, &ae));
+ /* This archive is invalid. However, processing it shouldn't cause any
+ * buffer overflow errors during reading rar5 tables. */
+ assertA(archive_read_data(a, buf, sizeof(buf)) <= 0);
+
+ /* This test only cares about not returning success here. */
+ assertA(ARCHIVE_OK != archive_read_next_header(a, &ae));
+
+ EPILOGUE();
+}
+
+DEFINE_TEST(test_read_format_rar5_leftshift1)
+{
+ uint8_t buf[16];
+
+ PROLOGUE("test_read_format_rar5_leftshift1.rar");
+
+ assertA(0 == archive_read_next_header(a, &ae));
+ /* This archive is invalid. However, processing it shouldn't cause any
+ * errors related to undefined operations when using -fsanitize. */
+ assertA(archive_read_data(a, buf, sizeof(buf)) <= 0);
+
+ /* This test only cares about not returning success here. */
+ assertA(ARCHIVE_OK != archive_read_next_header(a, &ae));
+
+ EPILOGUE();
+}
+
+DEFINE_TEST(test_read_format_rar5_leftshift2)
+{
+ uint8_t buf[16];
+
+ PROLOGUE("test_read_format_rar5_leftshift2.rar");
+
+ assertA(0 == archive_read_next_header(a, &ae));
+
+ /* This archive is invalid. However, processing it shouldn't cause any
+ * errors related to undefined operations when using -fsanitize. */
+ assertA(archive_read_data(a, buf, sizeof(buf)) <= 0);
+
+ /* This test only cares about not returning success here. */
+ assertA(ARCHIVE_OK != archive_read_next_header(a, &ae));
+
+ EPILOGUE();
+}
+
+DEFINE_TEST(test_read_format_rar5_truncated_huff)
+{
+ uint8_t buf[16];
+
+ PROLOGUE("test_read_format_rar5_truncated_huff.rar");
+
+ assertA(0 == archive_read_next_header(a, &ae));
+
+ /* This archive is invalid. However, processing it shouldn't cause any
+ * errors related to undefined operations when using -fsanitize. */
+ assertA(archive_read_data(a, buf, sizeof(buf)) <= 0);
+
+ /* This test only cares about not returning success here. */
+ assertA(ARCHIVE_OK != archive_read_next_header(a, &ae));
+
+ EPILOGUE();
+}
+
+DEFINE_TEST(test_read_format_rar5_invalid_dict_reference)
+{
+ uint8_t buf[16];
+
+ PROLOGUE("test_read_format_rar5_invalid_dict_reference.rar");
+
+ /* This test should fail on parsing the header. */
+ assertA(archive_read_next_header(a, &ae) != ARCHIVE_OK);
+
+ /* This archive is invalid. However, processing it shouldn't cause any
+ * errors related to buffer underflow when using -fsanitize. */
+ assertA(archive_read_data(a, buf, sizeof(buf)) <= 0);
+
+ /* This test only cares about not returning success here. */
+ assertA(ARCHIVE_OK != archive_read_next_header(a, &ae));
+
+ EPILOGUE();
+}
+
+DEFINE_TEST(test_read_format_rar5_distance_overflow)
+{
+ uint8_t buf[16];
+
+ PROLOGUE("test_read_format_rar5_distance_overflow.rar");
+
+ assertA(0 == archive_read_next_header(a, &ae));
+
+ /* This archive is invalid. However, processing it shouldn't cause any
+ * errors related to variable overflows when using -fsanitize. */
+ assertA(archive_read_data(a, buf, sizeof(buf)) <= 0);
+
+ /* This test only cares about not returning success here. */
+ assertA(ARCHIVE_OK != archive_read_next_header(a, &ae));
+
+ EPILOGUE();
+}
+
+DEFINE_TEST(test_read_format_rar5_nonempty_dir_stream)
+{
+ uint8_t buf[16];
+
+ PROLOGUE("test_read_format_rar5_nonempty_dir_stream.rar");
+
+ assertA(0 == archive_read_next_header(a, &ae));
+
+ /* This archive is invalid. However, processing it shouldn't cause any
+ * errors related to buffer overflows when using -fsanitize. */
+ assertA(archive_read_data(a, buf, sizeof(buf)) <= 0);
+
+ /* This test only cares about not returning success here. */
+ assertA(ARCHIVE_OK != archive_read_next_header(a, &ae));
+
+ EPILOGUE();
+}
+
+DEFINE_TEST(test_read_format_rar5_fileattr)
+{
+ unsigned long set, clear, flag;
+
+ flag = 0;
+
+ PROLOGUE("test_read_format_rar5_fileattr.rar");
+
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualInt(archive_entry_mode(ae), 0444 | AE_IFREG);
+ assertEqualString("readonly.txt", archive_entry_pathname(ae));
+ assertEqualString("rdonly", archive_entry_fflags_text(ae));
+ archive_entry_fflags(ae, &set, &clear);
+#if defined(__FreeBSD__)
+ flag = UF_READONLY;
+#elif defined(_WIN32) && !defined(CYGWIN)
+ flag = FILE_ATTRIBUTE_READONLY;
+#endif
+ assertEqualInt(flag, set & flag);
+
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualInt(archive_entry_mode(ae), 0644 | AE_IFREG);
+ assertEqualString("hidden.txt", archive_entry_pathname(ae));
+ assertEqualString("hidden", archive_entry_fflags_text(ae));
+ archive_entry_fflags(ae, &set, &clear);
+#if defined(__FreeBSD__)
+ flag = UF_HIDDEN;
+#elif defined(_WIN32) && !defined(CYGWIN)
+ flag = FILE_ATTRIBUTE_HIDDEN;
+#endif
+ assertEqualInt(flag, set & flag);
+
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualInt(archive_entry_mode(ae), 0644 | AE_IFREG);
+ assertEqualString("system.txt", archive_entry_pathname(ae));
+ assertEqualString("system", archive_entry_fflags_text(ae));
+ archive_entry_fflags(ae, &set, &clear);
+#if defined(__FreeBSD__)
+ flag = UF_SYSTEM;;
+#elif defined(_WIN32) && !defined(CYGWIN)
+ flag = FILE_ATTRIBUTE_SYSTEM;
+#endif
+ assertEqualInt(flag, set & flag);
+
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualInt(archive_entry_mode(ae), 0444 | AE_IFREG);
+ assertEqualString("ro_hidden.txt", archive_entry_pathname(ae));
+ assertEqualString("rdonly,hidden", archive_entry_fflags_text(ae));
+ archive_entry_fflags(ae, &set, &clear);
+#if defined(__FreeBSD__)
+ flag = UF_READONLY | UF_HIDDEN;
+#elif defined(_WIN32) && !defined(CYGWIN)
+ flag = FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN;
+#endif
+ assertEqualInt(flag, set & flag);
+
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualInt(archive_entry_mode(ae), 0555 | AE_IFDIR);
+ assertEqualString("dir_readonly", archive_entry_pathname(ae));
+ assertEqualString("rdonly", archive_entry_fflags_text(ae));
+ archive_entry_fflags(ae, &set, &clear);
+#if defined(__FreeBSD__)
+ flag = UF_READONLY;
+#elif defined(_WIN32) && !defined(CYGWIN)
+ flag = FILE_ATTRIBUTE_READONLY;
+#endif
+ assertEqualInt(flag, set & flag);
+
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualInt(archive_entry_mode(ae), 0755 | AE_IFDIR);
+ assertEqualString("dir_hidden", archive_entry_pathname(ae));
+ assertEqualString("hidden", archive_entry_fflags_text(ae));
+ archive_entry_fflags(ae, &set, &clear);
+#if defined(__FreeBSD__)
+ flag = UF_HIDDEN;
+#elif defined(_WIN32) && !defined(CYGWIN)
+ flag = FILE_ATTRIBUTE_HIDDEN;
+#endif
+ assertEqualInt(flag, set & flag);
+
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualInt(archive_entry_mode(ae), 0755 | AE_IFDIR);
+ assertEqualString("dir_system", archive_entry_pathname(ae));
+ assertEqualString("system", archive_entry_fflags_text(ae));
+ archive_entry_fflags(ae, &set, &clear);
+#if defined(__FreeBSD__)
+ flag = UF_SYSTEM;
+#elif defined(_WIN32) && !defined(CYGWIN)
+ flag = FILE_ATTRIBUTE_SYSTEM;
+#endif
+ assertEqualInt(flag, set & flag);
+
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualInt(archive_entry_mode(ae), 0555 | AE_IFDIR);
+ assertEqualString("dir_rohidden", archive_entry_pathname(ae));
+ assertEqualString("rdonly,hidden", archive_entry_fflags_text(ae));
+ archive_entry_fflags(ae, &set, &clear);
+#if defined(__FreeBSD__)
+ flag = UF_READONLY | UF_HIDDEN;
+#elif defined(_WIN32) && !defined(CYGWIN)
+ flag = FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN;
+#endif
+ assertEqualInt(flag, set & flag);
+
+ EPILOGUE();
}
diff --git a/libarchive/test/test_read_format_rar5_distance_overflow.rar.uu b/libarchive/test/test_read_format_rar5_distance_overflow.rar.uu
new file mode 100644
index 000000000000..8fefa282e733
--- /dev/null
+++ b/libarchive/test/test_read_format_rar5_distance_overflow.rar.uu
@@ -0,0 +1,9 @@
+begin 644 test_read_format_rar5_distance_overflow.rar
+M4F%R(1H'`0"-[P+2``(''/\@("`@_R4``B`@("`@("`@("`@(/__("`@("`@
+M(/\@("`@("`@((9ML63,PX"&AK%:S+?_(/\@_R#_(/\@_R#_(/\@`"``!R`@
+MR<G)``#_(,G)R?___R#___\@____(/___R#___\@____R4#)R<G___\@____
+M(/\@____("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@(/__________
+M____________________________________________________("`@("`@
+.("`@("`@("`@("#_("``
+`
+end
diff --git a/libarchive/test/test_read_format_rar5_extra_field_version.rar.uu b/libarchive/test/test_read_format_rar5_extra_field_version.rar.uu
new file mode 100644
index 000000000000..f9a5ce6926a8
--- /dev/null
+++ b/libarchive/test/test_read_format_rar5_extra_field_version.rar.uu
@@ -0,0 +1,10 @@
+begin 644 test_read_format_rar5_extra_field_version.rar
+M4F%R(1H'`0`SDK7E"@$%!@`%`0&`@`"BNGU4(0(#!%D&7^V#`I?:-URW@4'R
+M@`,!"&)I;B\R=&\S`P0``<7)5B550C]U!#WY13&:5TJ$=$IZ(*3`C\#F0%O\
+M)$)*@]X[RK.Z.G*HUT;V5FO&;:X/FDW,W`95I8T%@@C:DD="_8Z.9+CQH^IG
+M8!ZF0N)JSY2?R(W@25K`U&W)Q1X"`MD`!M\`[8,"E]HW7+>!0?*``P$(8FEN
+M+S)T;S/%R58E54(_=00]^44QFE=*A'1*>B"DP(_`YD!;_"1"2H/>.\JSNCIR
+MJ-=&]E9KQFVN#YI-S-P&5:6-!8((VI)'0OV.CF2X\:/J9V`>ID+B:L^4G\B-
+,X$E:P!UW5E$#!00`
+`
+end
diff --git a/libarchive/test/test_read_format_rar5_fileattr.rar.uu b/libarchive/test/test_read_format_rar5_fileattr.rar.uu
new file mode 100644
index 000000000000..456b02504066
--- /dev/null
+++ b/libarchive/test/test_read_format_rar5_fileattr.rar.uu
@@ -0,0 +1,13 @@
+begin 640 test_read_format_rar5_fileattr.rar
+M4F%R(1H'`0#SX8+K"P$%!P`&`0&`@(``-$;*1"@"`PN+``2+`"&+W8Z;@```
+M#')E861O;FQY+G1X=`H#`J*C5`BE!M4!,3(S-#4V-S@@#0JYZ,#-)@(#"XL`
+M!(L`(F^$/86````*:&ED9&5N+G1X=`H#`G(Q.0^E!M4!,C,T-38W.#D@#0H>
+M%_EV)@(#"XL`!(L`)"V,TBB````*<WES=&5M+G1X=`H#`F:K01.E!M4!,S0U
+M-C<X.3`@#0HQ>$42*0(#"XL`!(L`(RZ?$!V````-<F]?:&ED9&5N+G1X=`H#
+M`JIEBD2M!M4!-C<X.3`Q,C,@#0HQAL?6)@(#"P`%`!$`````@```#&1I<E]R
+M96%D;VYL>0H#`HS,%ABE!M4!Q!O^+"0"`PL`!0`2`````(````ID:7)?:&ED
+M9&5N"@,">JRV&:4&U0'&L*8=)`(#"P`%`!0`````@```"F1I<E]S>7-T96T*
+M`P(@+D4;I0;5`2YJ1$0F`@,+``4`$P````"````,9&ER7W)O:&ED9&5N"@,"
+0CW7S@JT&U0$==U91`P4$````
+`
+end
diff --git a/libarchive/test/test_read_format_rar5_hardlink.rar.uu b/libarchive/test/test_read_format_rar5_hardlink.rar.uu
new file mode 100644
index 000000000000..0ec085d478d5
--- /dev/null
+++ b/libarchive/test/test_read_format_rar5_hardlink.rar.uu
@@ -0,0 +1,6 @@
+begin 644 test_read_format_rar5_hardlink.rar
+M4F%R(1H'`0`SDK7E"@$%!@`%`0&`@`!KI,1X'@("A0`&A0"D@P(XC;=<(1>3
+M?8```0AF:6QE+G1X=#$R,S0*[8@"T2X"`PT`!@6D@P(XC;=<`````(```0QH
+@87)D;&EN:RYT>'0,!00`"&9I;&4N='AT'7=640,%!```
+`
+end
diff --git a/libarchive/test/test_read_format_rar5_invalid_dict_reference.rar.uu b/libarchive/test/test_read_format_rar5_invalid_dict_reference.rar.uu
new file mode 100644
index 000000000000..9b78c9b36cef
--- /dev/null
+++ b/libarchive/test/test_read_format_rar5_invalid_dict_reference.rar.uu
@@ -0,0 +1,9 @@
+begin 644 test_read_format_rar5_invalid_dict_reference.rar
+M4F%R(1H'`0"-[P+2``+#!QR`!P`F^P#_^_O[^_O[^R4``B$<`0(`#@```0``
+M`"#2````_____QH(`/__^P#_W5)04(#_`(:&;;%DS+?,L0```````````+%D
+MS+*RLK*R/@``____Y`"R````XP```````!4``````.X`````````````````
+M%5<M;&@W;3$W"2!S;'$2C5L`_____@D0````$"('``"8F)@+````/__?````
+M@```2$A(2$A(2$A(2$A(2$A(2$A(2$A(2$A(2$A(2$A(2$@S2(``2$A(2$A(
+>2$A(2$A(2$A(2$A(2$A(2$Q(2$A(2$A(2$A(2)](
+`
+end
diff --git a/libarchive/test/test_read_format_rar5_leftshift1.rar.uu b/libarchive/test/test_read_format_rar5_leftshift1.rar.uu
new file mode 100644
index 000000000000..694a27f6ff6c
--- /dev/null
+++ b/libarchive/test/test_read_format_rar5_leftshift1.rar.uu
@@ -0,0 +1,9 @@
+begin 644 test_read_format_rar5_leftshift1.rar
+M4F%R(1H'`0"-[P+2``(''(`'`"``_R4``B$<`0(`#@```0```"#2````____
+M_P`(`/__^P#_W0`"(8#_`(:&;;%DS+?,L=:NL0#(3`$`````````````````
+M``"``````````+!DS+*RL[*RL@```-P``````````````````(``````````
+ML&3,LK*RLK*R````W`````#X____````````````````````````%5H>;&@T
+M+3HW"2!SB^)_<Z3_`````?40'Q\?'Q\?'Q\?'Q\?'Q\?'Q\?'Q\?'Q\`````
+5`````````````````/H`>@``````
+`
+end
diff --git a/libarchive/test/test_read_format_rar5_leftshift2.rar.uu b/libarchive/test/test_read_format_rar5_leftshift2.rar.uu
new file mode 100644
index 000000000000..57ffad725643
--- /dev/null
+++ b/libarchive/test/test_read_format_rar5_leftshift2.rar.uu
@@ -0,0 +1,6 @@
+begin 644 test_read_format_rar5_leftshift2.rar
+M4F%R(1H'`0"-[P+2``(''(`'`2``_RL``B'+`0(`,O__````-WJ\KR<<)0`"
+M(;<*`BY*`!```&;%T#%24%"`_R4`[@K+(2Y*`&$``'__`/\E``(N2@`0`0(`
+0(?__`%N&?Q2UH.CHZ.CHZ```
+`
+end
diff --git a/libarchive/test/test_read_format_rar5_nonempty_dir_stream.rar.uu b/libarchive/test/test_read_format_rar5_nonempty_dir_stream.rar.uu
new file mode 100644
index 000000000000..c508c1f97ffd
--- /dev/null
+++ b/libarchive/test/test_read_format_rar5_nonempty_dir_stream.rar.uu
@@ -0,0 +1,9 @@
+begin 644 test_read_format_rar5_nonempty_dir_stream.rar
+M4F%R(1H'`0"-[P+2``(''($'$7\`_R4``BP<`0(`(0#_Y@```"#2````____
+M_P`(`/__^P#_W0`"(8#_`(:&;;%DS+?,L8```!;(&P#>``#__^_P```4```&
+M`````````````+`!`@`A`/_F````(-(```#_____``@`___[`/_=``(A``++
+M``"`]/^`!P!#^_____\"(2$!`@`A````_R4``B$A`0(`@````0```"#&`/_=
+M``(A@/\`AH9ML63,M\R`_P```,@;`````!@`````_0`````````!87(A&@<`
+5`(WO`M(``O8'&X`'`#C[_X`E``(A
+`
+end
diff --git a/libarchive/test/test_read_format_rar5_owner.rar.uu b/libarchive/test/test_read_format_rar5_owner.rar.uu
new file mode 100644
index 000000000000..285bdb91caf9
--- /dev/null
+++ b/libarchive/test/test_read_format_rar5_owner.rar.uu
@@ -0,0 +1,8 @@
+begin 644 test_read_format_rar5_owner.rar
+M4F%R(1H'`0`SDK7E"@$%!@`%`0&`@`!W:E-^+0(##H4`!H4`I(,"_8VW7"$7
+MDWV```$(<F]O="YT>'0-!@,$<F]O=`5W:&5E;#$R,S0*2J"P0S,"`Q*%``:%
+M`*2#`FZ-MUQFP<VL@``!"FYO8F]D>2YT>'01!@,&;F]B;V1Y!VYO9W)O=7`U
+M-C<X"L=81/8I`@,'A0`&A0"D@P)LD[=<>B#;(H```0MN=6UE<FEC+G1X=`8&
+2#(].N$4Y.3DY"AUW5E$#!00`
+`
+end
diff --git a/libarchive/test/test_read_format_rar5_readtables_overflow.rar.uu b/libarchive/test/test_read_format_rar5_readtables_overflow.rar.uu
new file mode 100644
index 000000000000..611c2af237d2
--- /dev/null
+++ b/libarchive/test/test_read_format_rar5_readtables_overflow.rar.uu
@@ -0,0 +1,15 @@
+begin 644 test_read_format_rar5_readtables_overflow.rar
+M4F%R(1H'`0"-[P+2`)3+'_4`C>\"T@`"T@"4RQ_5]0#O0````,L?Q_T``(`"
+MT@"4RQ_=V-C8`)3+']W=]0"-\`+2`)3+']WU`(WO`M(``M(`E,L?U?4`[P+2
+M`)3+'\?]``"``M(`E,L?W=C8V`"4RQ_=]0#V`(WO`M'UV,?8V-C8$=C8V-C8
+MV(W8V-C8V-C8V-C8V-C8V-C8V-C8V-C8V-C8!]C8V-C8V-C8V-C8V-C8V-C8
+MV-C8V-C8V-C(V-C8V-C2`)3+']W8V-C8V-C8V-C8V-C8V-C8@-C8V-C8V-C8
+MV/+8V-C8V-C8V-C8`038V-C8V-C8V-C8V-C8V-C8V`?8V-C8V-C8V-C8!-C8
+MV-C8V-C8V-C8V-C8V-C8V`?8V-C8V-C8V-C8V-C8`(`"V`7V`(WO`M'U`]L?
+MW?4`C>\"T@`"T@"4'__U`(WO`N``E,L?W84`C0`0T@"4RQ_=V-C8V-C8V`"4
+MR_\R]0#V`(W8V-C8V-C8V-C8V-C8V-C8V-C8V-C8V`?8V-C8V-C8V-C8V-C8
+MV-C8V-C8V-C8V-C8R-C8V-C8T@"4RQ_=V-C8V-C8V-C8V-C8V-C8V(#8V-C8
+MV-C8````9-C8V-C8V!'8V-C8V-C8]]C8V-C8V-C8V-C8V/+8V-C8V-C8V-C8
+=`038V-C8V-C8V-C8V-C8V-C8V`?8V-C8V-C8V-@`
+`
+end
diff --git a/libarchive/test/test_read_format_rar5_symlink.rar.uu b/libarchive/test/test_read_format_rar5_symlink.rar.uu
new file mode 100644
index 000000000000..f603e3c04db5
--- /dev/null
+++ b/libarchive/test/test_read_format_rar5_symlink.rar.uu
@@ -0,0 +1,8 @@
+begin 644 test_read_format_rar5_symlink.rar
+M4F%R(1H'`0`SDK7E"@$%!@`%`0&`@`"$O8RN'@("A0`&A0"D@P(XC;=<(1>3
+M?8!``0AF:6QE+G1X=#$R,S0*8QI3.2T"`PT`!@CMPP)7C;=<`````(!``0MS
+M>6UL:6YK+G1X=`P%`0`(9FEL92YT>'2.NOQU)`(#"``&`^W#`DF6MUP`````
+M@$`!!V1I<FQI;FL'!0$!`V1I<J/_?\87`@(`!P#M@P%&EK=<`````(```0-D
+*:7(==U91`P4$````
+`
+end
diff --git a/libarchive/test/test_read_format_rar5_truncated_huff.rar.uu b/libarchive/test/test_read_format_rar5_truncated_huff.rar.uu
new file mode 100644
index 000000000000..12d9e2550d30
--- /dev/null
+++ b/libarchive/test/test_read_format_rar5_truncated_huff.rar.uu
@@ -0,0 +1,7 @@
+begin 644 test_read_format_rar5_truncated_huff.rar
+M4F%R(1H'`0"-[P+2``'#]#P\7P$'`0"-[P+2``+2`!;#M#Q::7!)2?__'`!I
+M?_O_0B\*0RX-,'%O.\(#!-'^T#4````0`P1_``!#(3`P,./H`P```*^OKZ^O
+MKZ^OKZ^OKZ^OKZ^OKZ^OKZ^OKZ^OKZ^OKZ^OKZ\0`*^OKZ^A``KZ``$`2^\#
+9T>WMNP$+-5H*^@`!`$OOB]$````0"S5:*@``
+`
+end
diff --git a/libarchive/test/test_read_format_rar5_win32.rar.uu b/libarchive/test/test_read_format_rar5_win32.rar.uu
index 59920490e998..16d9fce1d381 100644
--- a/libarchive/test/test_read_format_rar5_win32.rar.uu
+++ b/libarchive/test/test_read_format_rar5_win32.rar.uu
@@ -1,68 +1,69 @@
begin 644 test_read_format_rar5_win32.rar
-M4F%R(1H'`0#SX8+K"P$%!P`&`0&`@(``/^"F5B0"`POI`@2P"2#-<,I\@`4`
-M"'1E<W0N8FEN"@,"/.U\@0U:U`'*]&4!)V5@5!]5=EV_E))QR<]EEED,<-EE
-MDQC%DA.&0DDDX9"0DDDD)..222$(220A"220DDA"$A+-M6][?3,.@'T=`ZX_
-MGKJ?]T'^]]KWW7FO.E_H`$`!`,@@GY^/;U]/+Q[^[LZ^KIZ.?EY./BX>#?W=
-MS:V=?6U=33TM#/S<S*R<C'QL7$P\&_O;R[N;BWMK6TL[*QKZZMJZJIIZ6DHZ
-M*AH)^=G)N9EY:4DTLE(R$>A0'XZ,BHF'.G#9J&A(*`?GQ[>GAV='-R<6]M:V
-MEG96-A7UU;65=54R$W]?R/T"4^B4Y_A$ET6*,&>6%VHX*:8IE!?F0M%VG48R
-MPSC`J$?_H)3&:0I?95"L5E8+BP&1:#<N!W7A!L`/,02,@GF85C0+IJ&6V#>;
-MAX.`8'(/KF$3H*9V&`\#;>A[O8=7T(W\6$"-&#'G"AY-"8-B^.#F.APB!*GA
-MA18[8T/Y\5"`;"$-"(32,9R0+R4`8B?AZB4"`POG`@2`("#&LA-^@`4`"71E
-M<W0Q+F)I;@H#`A*5H8`-6M0!R/!C`1!D168O5P5_4DDDDDDDDDDDDDDDDDDD
-MDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD^_/D;F=O/:[?;Z2Z_N
-M[6[OF=&;N]._TF,S#.GS#C<WS/.'/XKG;\@`@`@!L,/'3AM\>_MZ^GGY>/AW
-M]W;V=?5T]'/S<O)Q\7#P;^]N[FWM;.QKZVKJ:>EHZ&?G9N9EY63D8^-BXF'A
-M8.!?WU[>7=U<W%O;6MI9V5C85]=6UE755-13TU+24=%0T$_/3LY-S4S,2\M*
-MRDG)2,A'QT;&1<5$Q$/#0L)!P4#`/[\^^]['VA2X4M7TE0H#.Q@!;-"-XC0$
-M.A"U@6`X1/;M+3@AZ=F@%F`%LT(W2-`0Z$+6!8#A$]N4M."'IR:`68`6S0C<
-M(T!#H0M8%@.$3VW2TX(>FYH!9@!;-"-LC0$.A"U@6`X1-8__0K^QS*_>TU/6
-MRJ_(8IKGE-.XIH6GK_HGV@`)6BG`)0(#"^8"!(`@(,NO9O&`!0`)=&5S=#(N
-M8FEN"@,"A/;"@`U:U`'/]F(!$&1%9B]7!7]2222222222222222222222222
-M2222222222222222222222222222222222223[\^1N9V\]KM]OI+K^[M;N^9
-MT9N[T[_28S,,Z?,.-S?,\X<_BN=OR`"`"`&IAXZ<-OCW]O7T\_+Q\._N[>SK
-MZNGHY^;EY./BX>#?WMW<V]K9V-?6U=33TM'0S\[-S,O*R<C'QL7$P\+!P+^^
-MO;R[NKFXM[:UM+.RL;"OKJVLJZJIJ*>FI:2CHJ&@GYZ=G)N:F9B7EI64DY*1
-MD(^.C8R+BHF(AX:%A(."@8!_?GWWO8^T*7"EJ^DJ%`9V,`+9H1O$:`AT(6L"
-MP'")[=I:<$/3LT`LP`MFA&Z1H"'0A:P+`<(GMREIP0].30"S`"V:$;A&@(="
-M%K`L!PB>VZ6G!#TW-`+,`+9H1MD:`AT(6L"P'")K'_Z%?V.97[VFIZV57Y#%
-M-<\IIW%-"T]?]$^TVMWAVR4"`POT`@2`("#9([&?@`4`"71E<W0S+F)I;@H#
-M`H1PWX`-6M0!RN%P`1!D554O5P5^))))))))))))))))))))))))))))))))
-M))))))))))))))))))))))))))))))SO.\[S<:UGCPYS=>O+LEY]]M9^&\\,
-MWO7CO^DQF89X_9MAKF??:-?Q7/7Y`!`!`#848765^/?V]?3S\O'P[^[M[.OJ
-MZ>CGYN7DX^+AX-_>W=S;VMG8U];5U-/2T=#/SLW,R\K)R,?&Q<3#PL'`O[Z]
-MO+NZN;BWMK6TL[*QL*^NK:RKJJFHIZ:EI*.BH:"?GIV<FYJ9F)>6E923DI&0
-MCXZ-C(N*B8B'AH6$@X*!@']^??=]3[8AOPALOH4&#J;"`FDX$V"95@TP3;@P
-MF6DRPI=O")0\&G@!T,0$TG`FN3*KFER;<&$RTF6%+MV1*'@T[`.AB`FDX$UB
-M958T/&FX`#:3+"EVZ(E#P:=`'0Q`32<":I,JJ:'C3<`!M)EA2^4__8C^QK(_
-M>\:'K=J/R*(<ZY#CV(<&IZ_]"_:`$R,0$"4"`POT`@2`("#4/L00@`4`"71E
-M<W0T+F)I;@H#`@*,&8$-6M0!R^!P`1!D554O5P5^I)))))))))))))))))))
-M))))))))))))))))))))))))))))))))))))))))))SO.\YS<:UGCPYS=>O+
-MLEY]]M9^&\\,WO7CO^DQF89X_9MAKF??:-?Q7/7Y`!`!`#7=,+*J?'O[>OIY
-M^7CX=_=V]G7U=/1S\W+R<?%P\&_O;NYM[6SL:^MJZFGI:.AGYV;F9>5DY&/C
-M8N)AX6#@7]]>WEW=7-Q;VUK:6=E8V%?75M95U5344]-2TE'14-!/ST[.3<U,
-MS$O+2LI)R4C(1\=&QD7%1,1#PT+"0<%`P#^_/ON^Z^V(;\(;+Z%!@ZFP@)I.
-M!-@F58-,$VX,)EI,L*7:Y$H>#2X!T,0$TG`FL3*K&EB;<&$RTF6%+MX1*'@T
-M\`.AB`FDX$U2954T/&FX`#:3+"EV[(E#P:=@'0Q`32<":A,JH:'C3<`!M)EA
-M2^=?_L1_8UD?O>-#UNU'Y%$.=<AQ[$.#4]?^A?M`Y!DD9R4"`PO\`@2`("#R
-M5=&Y@`4`"71E<W0U+F)I;@H#`BI\2($-6M0!S.]X`1!D554O=6ZDDDDDDDDD
-MDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDG.\[SO-Q
-MFM>/..;N7KV[)>??;>LS[/'-[UX[_28S,,\?L,TUS/OM&_Q7/7Y`!`!`#6<+
-MK*J?'O[>OIY^7CX=_=V]G7U=/1S\W+R<?%P\&_O;NYM[6SL:^MJZFGI:.AGY
-MV;F9>5DY&/C8N)AX6#@7]]>WEW=7-Q;VUK:6=E8V%?75M95U5344]-2TE'14
-M-!/ST[.3<U,S$O+2LI)R4C(1\=&QD7%1,1#PT+"0<%`P#^_/ON^X^W$)PA)M
-MD@@5^H.&2UDI2.+AC"BYI<-/"!MIL`Z/;L$0M;)V8*FSADM9*4CBP8PHL:6#
-M3P@;:;`.CVZ!$+6R=&"ILX9+62E(XJ&,**FE0T\(&VFP#H]N01"ULG)@J;.&
-M2UDI2.*!C"BAI0-/"!MIL`Z/G'_[B/[&LC][QH>MVH_(HAYUR'CV(>#4]?^@
-M_:`_"MBZ)0(#"_P"!(`@(/](I#:`!0`)=&5S=#8N8FEN"@,"%79G@0U:U`'-
-M[G@!$&1552]U;J2222222222222222222222222222222222222222222222
-M222222222222222<[SO.\W&:UX\XYNY>O;LEY]]MZS/L\<WO7CO])C,PSQ^P
-MS37,^^T;_%<]?D`$`$`-TX7654^/?V]?3S\O'P[^[M[.OJZ>CGYN7DX^+AX-
-M_>W=S;VMG8U];5U-/2T=#/SLW,R\K)R,?&Q<3#PL'`O[Z]O+NZN;BWMK6TL[
-M*QL*^NK:RKJJFHIZ:EI*.BH:"?GIV<FYJ9F)>6E923DI&0CXZ-C(N*B8B'AH
-M6$@X*!@']^??=]Q]N(3A"3;)!`K]0<,EK)2D<7#&%%S2X:>$#;38!T>W8(A:
-MV3LP5-G#):R4I'%@QA18TL&GA`VTV`='MT"(6MDZ,%39PR6LE*1Q4,845-*A
-MIX0-M-@'1[<@B%K9.3!4V<,EK)2D<4#&%%#2@:>$#;38!T?./_W$?V-9'[WC
-;0];M1^11#SKD/'L0\&IZ_]!^T!UW5E$#!00`
+M4F%R(1H'`0#SX8+K"P$%!P`&`0&`@(``EV&"+"$"`PL`!0`0`````(````=T
+M97-T9&ER"@,"5N<QTHH!U0&_NE<D)`(#"^D"!+`)(,UPRGR``P`(=&5S="YB
+M:6X*`P(\[7R!#5K4`<KT90$G96!4'U5V7;^4DG')SV6660QPV663&,62$X9"
+M223AD)"2220DXY))(0A))"$)))"22$(2$LVU;WM],PZ`?1T#KC^>NI_W0?[W
+MVO?=>:\Z7^@`0`$`R""?GX]O7T\O'O[NSKZNGHY^7DX^+AX-_=W-K9U];5U-
+M/2T,_-S,K)R,?&Q<3#P;^]O+NYN+>VM;2SLK&OKJVKJJFGI:2CHJ&@GYV<FY
+MF7EI232R4C(1Z%`?CHR*B8<Z<-FH:$@H!^?'MZ>'9T<W)Q;VUK:6=E8V%?75
+MM95U53(3?U_(_0)3Z)3G^$2718HP9Y87:C@IIBF4%^9"T7:=1C+#.,"H1_^@
+ME,9I"E]E4*Q65@N+`9%H-RX'=>$&P`\Q!(R">9A6-`NFH9;8-YN'@X!@<@^N
+M81.@IG88#P-MZ'N]AU?0C?Q80(T8,><*'DT)@V+XX.8Z'"($J>&%%CMC0_GQ
+M4(!L(0T(A-(QG)`O)0`QGD%J)0(#"^L"!(`@(,:R$WZ``P`)=&5S=#$N8FEN
+M"@,"$I6A@`U:U`'-\6<!$&1&92]7!7^22222222222222222222222222222
+M222222222222222222222222222222223GY^RW,[??J[><7#G7SNUN[YG1F[
+MO3O]%F,,Z?#,/6YOF>>GO;]_`_=OV`"`"`&PPZ<-FGU\_'O[>OIY^7CX=_=V
+M]G7U=/1S\W+R<?%P\&_O;NYM[6SL:^MJZFGI:.AGYV;F9>5DY&/C8N)AX6#@
+M7]]>WEW=7-Q;VUK:6=E8V%?75M95U5344]-2TE'14-!/ST[.3<U,S$O+2LI)
+MR4C(1\=&QD7%1,1#PT+"0<%`P#_[WL?R%+A2U?J5"@,[&`%LT(W2-`0Z$+6!
+M8#A$]N4M."'IR:`68`6S0C<(T!#H0M8%@.$3VW2TX(>FYH!9@!;-"-LC0$.A
+M"U@6`X1/;5+3@AZ:F@%F`%LT(VB-`0Z$+6!8#A$UA]Z%,?GS*>SVE?X8*>=C
+M4\-BG=.J=HXIZ?]R?M!(:PP')0(#"^L"!(`@(<NO9O&``P`)=&5S=#(N8FEN
+M"@,"A/;"@`U:U`',\&<!$&1&92]7!7^22222222222222222222222222222
+M222222222222222222222222222222223GY^RW,[??J[><7#G7SNUN[YG1F[
+MO3O]%F,,Z?#,/6YOF>>GO;]_`_=OV`"`"`&IATX;-/KY^/?V]?3S\O'P[^[M
+M[.OJZ>CGYN7DX^+AX-_>W=S;VMG8U];5U-/2T=#/SLW,R\K)R,?&Q<3#PL'`
+MO[Z]O+NZN;BWMK6TL[*QL*^NK:RKJJFHIZ:EI*.BH:"?GIV<FYJ9F)>6E923
+MDI&0CXZ-C(N*B8B'AH6$@X*!@'_WO8_D*7"EJ_4J%`9V,`+9H1ND:`AT(6L"
+MP'")[<I:<$/3DT`LP`MFA&X1H"'0A:P+`<(GMNEIP0]-S0"S`"V:$;9&@(="
+M%K`L!PB>VJ6G!#TU-`+,`+9H1M$:`AT(6L"P'")K#[T*8_/F4]GM*_PP4\[&
+MIX;%.Z=4[1Q3T_[D_:#Z7*U;)0(#"_<"!(`@(-DCL9^``P`)=&5S=#,N8FEN
+M"@,"A'#?@`U:U`'.YG,!$&1552]7!7XDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
+MDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDG>\[SO-RUK/'AS>Z]>]72\[VUGX;
+MSPS6]^._Z+,89X_&9MAOF??:->O/X'?K\@`@`@!LK,L+N/CW]O7T\_+Q\._N
+M[>SKZNGHY^;EY./BX>#?WMW<V]K9V-?6U=33TM'0S\[-S,O*R<C'QL7$P\+!
+MP+^^O;R[NKFXM[:UM+.RL;"OKJVLJZJIJ*>FI:2CHJ&@GYZ=G)N:F9B7EI64
+MDY*1D(^.C8R+BHF(AX:%A(."@8!_?O_[[UOQB$^$)+[%!@ZJP@)I6!-DF59-
+M,DTP85+::84MW9$H?1AV`=#$!-*P)L$RK!I@FF#"I;33"ENZ(E#Z,.@#H8@)
+MI6!-<F57-#AI,`!MIIA2W<D2A]&'(!T,0$TK`FX)E7!H<-)@`-M-,*7RW][$
+M+?7[(?3[2/T-$/>UH>G1#RK4/$L0^/_<7F@SHER0)0(#"_<"!(`@(-0^Q!"`
+M`P`)=&5S=#0N8FEN"@,"`HP9@0U:U`'/YW,!$&1552]7!7XDDDDDDDDDDDDD
+MDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDG.\[SG-RUK/'
+MASFZ]>]72\[VUGX;SPS6]^._Z+,89X_&9MAOF??:->O/X'?K\@`@`@!L*,KK
+M*_'O[>OIY^7CX=_=V]G7U=/1S\W+R<?%P\&_O;NYM[6SL:^MJZFGI:.AGYV;
+MF9>5DY&/C8N)AX6#@7]]>WEW=7-Q;VUK:6=E8V%?75M95U5344]-2TE'14-!
+M/ST[.3<U,S$O+2LI)R4C(1\=&QD7%1,1#PT+"0<%`P#^_?_WWJ?C$.>$.%]B
+M@P=380$TG`FR3*LFF2;D&$RVFF%+=@B4/HPP`=#$!-)P)KDRJYI<FY!A,MII
+MA2W=D2A]&'8!T,0$TG`FL3*K&APTY``;::84MW1$H?1AT`=#$!-)P)JDRJIH
+M<-.0`&VFF%+Y3^]B%/K]D/I]I'Z&B'O:T/3HAY5J'B6(?'_N+S0M?'0I)0(#
+M"X`#!(`@(/)5T;F``P`)=&5S=#4N8FEN"@,"*GQ(@0U:U`'([WP!$&1552]U
+M;J2222222222222222222222222222222222222222222222222222222222
+M222<[SO.\W+-:\><<W<O7O5TO.]MYF?9XZUO?CO]%F,,\?C,,TUW/OM&_7OX
+M'GK\@`@`@!K.%UE5/CW]O7T\_+Q\._N[>SKZNGHY^;EY./BX>#?WMW<V]K9V
+M-?6U=33TM'0S\[-S,O*R<C'QL7$P\+!P+^^O;R[NKFXM[:UM+.RL;"OKJVLJ
+MZJIJ*>FI:2CHJ&@GYZ=G)N:F9B7EI64DY*1D(^.C8R+BHF(AX:%A(."@8!_?
+MO_[[W'XXA.D)1LT$"OW!PR6LE*QQ<,847-+AIH@;:C`.CV[!$+6S=F"ILX9+
+M62E8XL&,*+&E@TT0-M1@'1[=`B%K9NC!4V<,EK)2L<5#&%%32H::(&VHP#H]
+MN01"ULW)@J;.&2UDI6.*!C"BAI0--$#;48!T?G'][B''U_9#Z?:1^AHA[VM#
+MT\$/*RH>)D0^/_</F@#V;XCT)0(#"X`#!(`@(/](I#:``P`)=&5S=#8N8FEN
+M"@,"%79G@0U:U`')[GP!$&1552]U;J222222222222222222222222222222
+M2222222222222222222222222222222<[SO.\W+-:\><<W<O7O5TO.]MYF?9
+MXZUO?CO]%F,,\?C,,TUW/OM&_7OX'GK\@`@`@!NG"ZRJGQ[^WKZ>?EX^'?W=
+MO9U]73T<_-R\G'Q</!O[V[N;>UL[&OK:NIIZ6CH9^=FYF7E9.1CXV+B8>%@X
+M%_?7MY=W5S<6]M:VEG96-A7UU;65=54U%/34M)1T5#03\].SDW-3,Q+RTK*2
+M<E(R$?'1L9%Q43$0\-"PD'!0,`_OW_]][C\<0G2$HV:"!7[@X9+62E8XN&,*
+M+FEPTT0-M1@'1[=@B%K9NS!4V<,EK)2L<6#&%%C2P::(&VHP#H]N@1"ULW1@
+MJ;.&2UDI6.*AC"BII4--$#;48!T>W((A:V;DP5-G#):R4K'%`QA10TH&FB!M
+KJ,`Z/SC^]Q#CZ_LA]/M(_0T0][6AZ>"'E94/$R(?'_N'S0`==U91`P4$````
`
end
diff --git a/libarchive/test/test_read_format_rar_ppmd_use_after_free.rar.uu b/libarchive/test/test_read_format_rar_ppmd_use_after_free.rar.uu
new file mode 100644
index 000000000000..1363386530bb
--- /dev/null
+++ b/libarchive/test/test_read_format_rar_ppmd_use_after_free.rar.uu
@@ -0,0 +1,10 @@
+begin 644 test_read_format_rar_ppmd_use_after_free.rar
+M4F%R(1H'``1G=$Q26`!W````>U!+`P0R`'#_J7\`+@TU'`#]`0`7__]"0D)"
+M+W5N<V5T"6=I9`UD#1T+``!"`````````&%R(1H'``1G>TQ26`!W=&@`[E!+
+M`P0Q`'#_(````"`@(+<@!/T`("`@("`@("`@("`@("`@("`@("`@("`@("`@
+M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@
+M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@(`1G=$Q26`!W````
+M>U!+`P0R`'#_J7\`+@TU'`#]`0`7__]"0D)"+W5N<V5T"6=I9`UD#1T+``!"
+@`````````&%R(1H'``1G>TQ26`!W=&@`[E!+`P0Q`'``
+`
+end
diff --git a/libarchive/test/test_read_format_raw.c b/libarchive/test/test_read_format_raw.c
index 831bcec11de3..0dac8bfbab4a 100644
--- a/libarchive/test/test_read_format_raw.c
+++ b/libarchive/test/test_read_format_raw.c
@@ -36,6 +36,7 @@ DEFINE_TEST(test_read_format_raw)
const char *reffile1 = "test_read_format_raw.data";
const char *reffile2 = "test_read_format_raw.data.Z";
const char *reffile3 = "test_read_format_raw.bufr";
+ const char *reffile4 = "test_read_format_raw.data.gz";
/* First, try pulling data out of an uninterpretable file. */
extract_reference_file(reffile1);
@@ -117,4 +118,30 @@ DEFINE_TEST(test_read_format_raw)
assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+
+ /* Fourth, try with gzip which has metadata. */
+ extract_reference_file(reffile4);
+ assert((a = archive_read_new()) != NULL);
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_raw(a));
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
+ assertEqualIntA(a, ARCHIVE_OK,
+ archive_read_open_filename(a, reffile4, 1));
+
+ /* First (and only!) Entry */
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
+ assertEqualString("test-file-name.data", archive_entry_pathname(ae));
+ assertEqualInt(archive_entry_is_encrypted(ae), 0);
+ assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED);
+ assert(archive_entry_mtime_is_set(ae));
+ assertEqualIntA(a, archive_entry_mtime(ae), 0x5cbafd25);
+ /* Most fields should be unset (unknown) */
+ assert(!archive_entry_size_is_set(ae));
+ assert(!archive_entry_atime_is_set(ae));
+ assert(!archive_entry_ctime_is_set(ae));
+
+ /* Test EOF */
+ assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
+ assertEqualInt(ARCHIVE_OK, archive_read_free(a));
}
diff --git a/libarchive/test/test_read_format_raw.data.gz.uu b/libarchive/test/test_read_format_raw.data.gz.uu
new file mode 100644
index 000000000000..cf1f7b307d4e
--- /dev/null
+++ b/libarchive/test/test_read_format_raw.data.gz.uu
@@ -0,0 +1,4 @@
+begin 644 test_read_format_raw.data.gz
+L'XL(""7]NEP``W1E<W0M9FEL92UN86UE+F1A=&$`2\O/YP(`J&4R?@0`````
+`
+end
diff --git a/libarchive/test/test_read_format_tar_empty_with_gnulabel.c b/libarchive/test/test_read_format_tar_empty_with_gnulabel.c
new file mode 100644
index 000000000000..83f20bb97115
--- /dev/null
+++ b/libarchive/test/test_read_format_tar_empty_with_gnulabel.c
@@ -0,0 +1,53 @@
+/*-
+ * Copyright (c) 2019 Martin Matuska
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+__FBSDID("$FreeBSD$");
+
+/*
+ * Tar archives with with just a GNU label (or ending with one) should
+ * be treated as valid (empty) archives
+ */
+DEFINE_TEST(test_read_format_tar_empty_with_gnulabel)
+{
+ char name[] = "test_read_format_tar_empty_with_gnulabel.tar";
+ struct archive_entry *ae;
+ struct archive *a;
+
+ assert((a = archive_read_new()) != NULL);
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
+ extract_reference_file(name);
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 10240));
+
+ /* Read first entry. */
+ assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
+
+ /* Verify that the format detection worked. */
+ assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_NONE);
+ assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR);
+
+ assertEqualInt(ARCHIVE_OK, archive_read_close(a));
+ assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+}
diff --git a/libarchive/test/test_read_format_tar_empty_with_gnulabel.tar.uu b/libarchive/test/test_read_format_tar_empty_with_gnulabel.tar.uu
new file mode 100644
index 000000000000..c5aa393db8ec
--- /dev/null
+++ b/libarchive/test/test_read_format_tar_empty_with_gnulabel.tar.uu
@@ -0,0 +1,231 @@
+begin 664 test_read_format_tar_empty_with_gnulabel.tar
+M;&%B96P`````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`#$S-#8W-S,V,C`S`#`P,C8R,``@5@``````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+9````````````````````````````````````
+`
+end
diff --git a/libarchive/test/test_read_format_zip.c b/libarchive/test/test_read_format_zip.c
index 14c5ada81053..b6e957a96cec 100644
--- a/libarchive/test/test_read_format_zip.c
+++ b/libarchive/test/test_read_format_zip.c
@@ -32,29 +32,29 @@ __FBSDID("$FreeBSD: head/lib/libarchive/test/test_read_format_zip.c 189482 2009-
static
int extract_one(struct archive* a, struct archive_entry* ae, uint32_t crc)
{
- la_ssize_t fsize, bytes_read;
- uint8_t* buf;
- int ret = 1;
- uint32_t computed_crc;
-
- fsize = (la_ssize_t) archive_entry_size(ae);
- buf = malloc(fsize);
- if(buf == NULL)
- return 1;
-
- bytes_read = archive_read_data(a, buf, fsize);
- if(bytes_read != fsize) {
- assertEqualInt(bytes_read, fsize);
- goto fn_exit;
- }
-
- computed_crc = crc32(0, buf, fsize);
- assertEqualInt(computed_crc, crc);
- ret = 0;
+ la_ssize_t fsize, bytes_read;
+ uint8_t* buf;
+ int ret = 1;
+ uint32_t computed_crc;
+
+ fsize = (la_ssize_t) archive_entry_size(ae);
+ buf = malloc(fsize);
+ if(buf == NULL)
+ return 1;
+
+ bytes_read = archive_read_data(a, buf, fsize);
+ if(bytes_read != fsize) {
+ assertEqualInt(bytes_read, fsize);
+ goto fn_exit;
+ }
+
+ computed_crc = crc32(0, buf, fsize);
+ assertEqualInt(computed_crc, crc);
+ ret = 0;
fn_exit:
- free(buf);
- return ret;
+ free(buf);
+ return ret;
}
static
@@ -111,7 +111,7 @@ verify_basic(struct archive *a, int seek_checks)
int64_t o;
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
- assertEqualString("ZIP 1.0 (uncompressed)", archive_format_name(a));
+ assertEqualString("ZIP 1.0 (uncompressed)", archive_format_name(a));
assertEqualString("dir/", archive_entry_pathname(ae));
assertEqualInt(1179604249, archive_entry_mtime(ae));
assertEqualInt(0, archive_entry_size(ae));
@@ -124,7 +124,7 @@ verify_basic(struct archive *a, int seek_checks)
assertEqualInt((int)s, 0);
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
- assertEqualString("ZIP 2.0 (deflation)", archive_format_name(a));
+ assertEqualString("ZIP 2.0 (deflation)", archive_format_name(a));
assertEqualString("file1", archive_entry_pathname(ae));
assertEqualInt(1179604289, archive_entry_mtime(ae));
if (seek_checks)
@@ -144,7 +144,7 @@ verify_basic(struct archive *a, int seek_checks)
}
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
- assertEqualString("ZIP 2.0 (deflation)", archive_format_name(a));
+ assertEqualString("ZIP 2.0 (deflation)", archive_format_name(a));
assertEqualString("file2", archive_entry_pathname(ae));
assertEqualInt(1179605932, archive_entry_mtime(ae));
assertEqualInt(archive_entry_is_encrypted(ae), 0);
@@ -166,7 +166,7 @@ verify_basic(struct archive *a, int seek_checks)
assert(archive_errno(a) != 0);
}
assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae));
- assertEqualString("ZIP 2.0 (deflation)", archive_format_name(a));
+ assertEqualString("ZIP 2.0 (deflation)", archive_format_name(a));
/* Verify the number of files read. */
failure("the archive file has three files");
assertEqualInt(3, archive_file_count(a));
@@ -493,9 +493,14 @@ DEFINE_TEST(test_read_format_zip_lzma_one_file)
struct archive *a;
struct archive_entry *ae;
+ assert((a = archive_read_new()) != NULL);
+ if (ARCHIVE_OK != archive_read_support_filter_lzma(a)) {
+ skipping("lzma reading not fully supported on this platform");
+ assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+ return;
+ }
extract_reference_file(refname);
- assert((a = archive_read_new()) != NULL);
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 37));
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
@@ -513,9 +518,14 @@ DEFINE_TEST(test_read_format_zip_lzma_one_file_blockread)
struct archive *a;
struct archive_entry *ae;
+ assert((a = archive_read_new()) != NULL);
+ if (ARCHIVE_OK != archive_read_support_filter_lzma(a)) {
+ skipping("lzma reading not fully supported on this platform");
+ assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+ return;
+ }
extract_reference_file(refname);
- assert((a = archive_read_new()) != NULL);
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 37));
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
@@ -533,9 +543,14 @@ DEFINE_TEST(test_read_format_zip_lzma_multi)
struct archive *a;
struct archive_entry *ae;
+ assert((a = archive_read_new()) != NULL);
+ if (ARCHIVE_OK != archive_read_support_filter_lzma(a)) {
+ skipping("lzma reading not fully supported on this platform");
+ assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+ return;
+ }
extract_reference_file(refname);
- assert((a = archive_read_new()) != NULL);
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 37));
@@ -565,9 +580,14 @@ DEFINE_TEST(test_read_format_zip_lzma_multi_blockread)
struct archive *a;
struct archive_entry *ae;
+ assert((a = archive_read_new()) != NULL);
+ if (ARCHIVE_OK != archive_read_support_filter_lzma(a)) {
+ skipping("lzma reading not fully supported on this platform");
+ assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+ return;
+ }
extract_reference_file(refname);
- assert((a = archive_read_new()) != NULL);
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 37));
@@ -598,9 +618,14 @@ DEFINE_TEST(test_read_format_zip_bzip2_one_file)
struct archive *a;
struct archive_entry *ae;
+ assert((a = archive_read_new()) != NULL);
+ if (ARCHIVE_OK != archive_read_support_filter_bzip2(a)) {
+ skipping("bzip2 is not fully supported on this platform");
+ archive_read_close(a);
+ return;
+ }
extract_reference_file(refname);
- assert((a = archive_read_new()) != NULL);
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 37));
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
@@ -618,9 +643,14 @@ DEFINE_TEST(test_read_format_zip_bzip2_one_file_blockread)
struct archive *a;
struct archive_entry *ae;
+ assert((a = archive_read_new()) != NULL);
+ if (ARCHIVE_OK != archive_read_support_filter_bzip2(a)) {
+ skipping("bzip2 is not fully supported on this platform");
+ archive_read_close(a);
+ return;
+ }
extract_reference_file(refname);
- assert((a = archive_read_new()) != NULL);
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 37));
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
@@ -638,9 +668,14 @@ DEFINE_TEST(test_read_format_zip_bzip2_multi)
struct archive *a;
struct archive_entry *ae;
+ assert((a = archive_read_new()) != NULL);
+ if (ARCHIVE_OK != archive_read_support_filter_bzip2(a)) {
+ skipping("bzip2 is not fully supported on this platform");
+ archive_read_close(a);
+ return;
+ }
extract_reference_file(refname);
- assert((a = archive_read_new()) != NULL);
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 37));
@@ -670,9 +705,14 @@ DEFINE_TEST(test_read_format_zip_bzip2_multi_blockread)
struct archive *a;
struct archive_entry *ae;
+ assert((a = archive_read_new()) != NULL);
+ if (ARCHIVE_OK != archive_read_support_filter_bzip2(a)) {
+ skipping("bzip2 is not fully supported on this platform");
+ archive_read_close(a);
+ return;
+ }
extract_reference_file(refname);
- assert((a = archive_read_new()) != NULL);
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 37));
@@ -702,9 +742,14 @@ DEFINE_TEST(test_read_format_zip_xz_multi)
struct archive *a;
struct archive_entry *ae;
+ assert((a = archive_read_new()) != NULL);
+ if (ARCHIVE_OK != archive_read_support_filter_lzma(a)) {
+ skipping("lzma reading not fully supported on this platform");
+ assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+ return;
+ }
extract_reference_file(refname);
- assert((a = archive_read_new()) != NULL);
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 37));
@@ -734,9 +779,14 @@ DEFINE_TEST(test_read_format_zip_xz_multi_blockread)
struct archive *a;
struct archive_entry *ae;
+ assert((a = archive_read_new()) != NULL);
+ if (ARCHIVE_OK != archive_read_support_filter_lzma(a)) {
+ skipping("lzma reading not fully supported on this platform");
+ assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+ return;
+ }
extract_reference_file(refname);
- assert((a = archive_read_new()) != NULL);
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 37));
@@ -789,9 +839,14 @@ DEFINE_TEST(test_read_format_zip_bz2_hang_on_invalid)
struct archive_entry *ae;
char buf[8];
+ assert((a = archive_read_new()) != NULL);
+ if (ARCHIVE_OK != archive_read_support_filter_bzip2(a)) {
+ skipping("bzip2 is not fully supported on this platform");
+ archive_read_close(a);
+ return;
+ }
extract_reference_file(refname);
- assert((a = archive_read_new()) != NULL);
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 37));
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
@@ -823,3 +878,41 @@ DEFINE_TEST(test_read_format_zip_ppmd8_crash_2)
assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
}
+
+DEFINE_TEST(test_read_format_zip_lzma_alone_leak)
+{
+ const char *refname = "test_read_format_zip_lzma_alone_leak.zipx";
+ struct archive *a;
+ struct archive_entry *ae;
+ char buf[64];
+
+ /* OSSFuzz #14470 sample file. */
+ extract_reference_file(refname);
+
+ assert((a = archive_read_new()) != NULL);
+ if(ARCHIVE_OK != archive_read_support_filter_lzma(a)) {
+ skipping("lzma reading is not fully supported on this platform");
+ archive_read_close(a);
+ return;
+ }
+
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 37));
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
+
+ /* Extraction of this file should fail, because the sample file is invalid.
+ * But it shouldn't crash. */
+ assertEqualIntA(a, ARCHIVE_FAILED, archive_read_data(a, buf, sizeof(buf)));
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
+
+ /* Extraction of this file should fail, because the sample file is invalid.
+ * But it shouldn't crash. */
+ assertEqualIntA(a, ARCHIVE_FATAL, archive_read_data(a, buf, sizeof(buf)));
+
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
+
+ /* This testcase shouldn't produce any memory leaks. When running test
+ * suite under Valgrind or ASan, the test runner won't return with
+ * exit code 0 in case if a memory leak. */
+}
diff --git a/libarchive/test/test_read_format_zip_7075_utf8_paths.c b/libarchive/test/test_read_format_zip_7075_utf8_paths.c
new file mode 100644
index 000000000000..7b78770aae43
--- /dev/null
+++ b/libarchive/test/test_read_format_zip_7075_utf8_paths.c
@@ -0,0 +1,102 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * Copyright (c) 2011 Michihiro NAKAJIMA
+ * Copyright (c) 2019 Mike Frysinger
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+__FBSDID("$FreeBSD$");
+
+#include <locale.h>
+
+static void
+verify(struct archive *a) {
+ struct archive_entry *ae;
+ const char *p;
+
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
+ assert((p = archive_entry_pathname_utf8(ae)) != NULL);
+ assertEqualUTF8String(p, "File 1.txt");
+
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
+ assert((p = archive_entry_pathname_utf8(ae)) != NULL);
+#if defined(__APPLE__)
+ /* Compare NFD string. */
+ assertEqualUTF8String(p, "File 2 - o\xCC\x88.txt");
+#else
+ /* Compare NFC string. */
+ assertEqualUTF8String(p, "File 2 - \xC3\xB6.txt");
+#endif
+
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
+ assert((p = archive_entry_pathname_utf8(ae)) != NULL);
+#if defined(__APPLE__)
+ /* Compare NFD string. */
+ assertEqualUTF8String(p, "File 3 - a\xCC\x88.txt");
+#else
+ /* Compare NFC string. */
+ assertEqualUTF8String(p, "File 3 - \xC3\xA4.txt");
+#endif
+
+ /* The CRC of the filename fails, so fall back to CDE. */
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
+ assert((p = archive_entry_pathname_utf8(ae)) != NULL);
+ assertEqualUTF8String(p, "File 4 - xx.txt");
+
+ assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
+}
+
+DEFINE_TEST(test_read_format_zip_utf8_paths)
+{
+ const char *refname = "test_read_format_zip_7075_utf8_paths.zip";
+ struct archive *a;
+ char *p;
+ size_t s;
+
+ extract_reference_file(refname);
+
+ if (NULL == setlocale(LC_ALL, "en_US.UTF-8")) {
+ skipping("en_US.UTF-8 locale not available on this system.");
+ return;
+ }
+
+ /* Verify with seeking reader. */
+ assert((a = archive_read_new()) != NULL);
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 10240));
+ verify(a);
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
+
+ /* Verify with streaming reader. */
+ p = slurpfile(&s, refname);
+ assert((a = archive_read_new()) != NULL);
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
+ assertEqualIntA(a, ARCHIVE_OK, read_open_memory(a, p, s, 31));
+ verify(a);
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
+ assertEqualIntA(a, ARCHIVE_OK, archive_free(a));
+ free(p);
+}
diff --git a/libarchive/test/test_read_format_zip_7075_utf8_paths.zip.uu b/libarchive/test/test_read_format_zip_7075_utf8_paths.zip.uu
new file mode 100644
index 000000000000..332f996898e0
--- /dev/null
+++ b/libarchive/test/test_read_format_zip_7075_utf8_paths.zip.uu
@@ -0,0 +1,20 @@
+begin 644 test_read_format_zip_7075_utf8_paths.zip
+M4$L#!!0````(`,$^9D5BZ95P"P````D````*````1FEL92`Q+G1X=`M)+2Y1
+M2,O,204`4$L#!!0````(`,$^9D5BZ95P"P````D````/`!@`1FEL92`R("T@
+M>'@N='AT=7`4``$NSPQQ1FEL92`R("T@P[8N='AT"TDM+E%(R\Q)!0!02P,$
+M%`````@`P3YF16+IE7`+````"0````\`&`!&:6QE(#,@+2!X>"YT>'1U<!0`
+M`1"DSIY&:6QE(#,@+2##I"YT>'0+22TN44C+S$D%`%!+`P04````"`#!/F9%
+M8NF5<`L````)````#P`8`$9I;&4@-"`M('AX+G1X='5P%``!G[AP'$9I;&4@
+M-"`M(,.E+G1X=`M)+2Y12,O,204`4$L!`A\`%`````@`P3YF16+IE7`+````
+M"0````H`)``````````@`````````$9I;&4@,2YT>'0*`"````````$`&``Q
+M6UASCOG/`5^OQVV.^<\!7Z_';8[YSP%02P$"'P`4````"`#!/F9%8NF5<`L`
+M```)````#@`\`````````"`````S````1FEL92`R("T@E"YT>'0*`"``````
+M``$`&``Q6UASCOG/`2M.B72.^<\!*TZ)=([YSP%U<!0``2[/#'%&:6QE(#(@
+M+2##MBYT>'102P$"'P`4````"`#!/F9%8NF5<`L````)````#@`\````````
+M`"````"#````1FEL92`S("T@A"YT>'0*`"````````$`&``Q6UASCOG/`5<$
+M&W>.^<\!5P0;=X[YSP%U<!0``1"DSIY&:6QE(#,@+2##I"YT>'102P$"'P`4
+M````"`#!/F9%8NF5<`L````)````#@`\`````````"````#3````1FEL92`T
+M("T@ABYT>'0*`"````````$`&``Q6UASCOG/`6#)ZG:.^<\!8,GJ=H[YSP%U
+M<!0``9^X<!Q&:6QE(#0@+2##I2YT>'102P4&``````0`!`#$`0``(P$`````
+`
+end
diff --git a/libarchive/test/test_read_format_zip_extra_padding.c b/libarchive/test/test_read_format_zip_extra_padding.c
new file mode 100644
index 000000000000..54f7fa04ee89
--- /dev/null
+++ b/libarchive/test/test_read_format_zip_extra_padding.c
@@ -0,0 +1,93 @@
+/*-
+ * Copyright (c) 2003-2018 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+/*
+ * Test archive verifies that we ignore padding in the extra field.
+ *
+ * APPNOTE.txt does not provide any provision for padding the extra
+ * field, so libarchive used to error when there were unconsumed
+ * bytes. Apparently, some Zip writers do routinely put zero padding
+ * in the extra field.
+ *
+ * The extra fields in this test (for both the local file header
+ * and the central directory entry) are formatted as follows:
+ *
+ * 0000 0000 - unrecognized field with type zero, zero bytes
+ * 5554 0900 03d258155cdb58155c - UX field with length 9
+ * 0000 0400 00000000 - unrecognized field with type zero, four bytes
+ * 000000 - three bytes padding
+ *
+ * The two valid type zero fields should be skipped and ignored, as
+ * should the three bytes padding (which is too short to be a valid
+ * extra data object). If there were no errors and we read the UX
+ * field correctly, then we've correctly handled all of the padding
+ * fields above.
+ */
+
+
+static void verify(struct archive *a) {
+ struct archive_entry *ae;
+
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
+ assertEqualString("a", archive_entry_pathname(ae));
+ assertEqualInt(AE_IFREG | 0664, archive_entry_mode(ae));
+ assertEqualInt(0x5c1558d2, archive_entry_mtime(ae));
+ assertEqualInt(0, archive_entry_ctime(ae));
+ assertEqualInt(0x5c1558db, archive_entry_atime(ae));
+
+ assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
+}
+
+DEFINE_TEST(test_read_format_zip_extra_padding)
+{
+ const char *refname = "test_read_format_zip_extra_padding.zip";
+ struct archive *a;
+ char *p;
+ size_t s;
+
+ extract_reference_file(refname);
+
+ /* Verify with seeking reader. */
+ assert((a = archive_read_new()) != NULL);
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 7));
+ verify(a);
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
+ assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+
+ /* Verify with streaming reader. */
+ p = slurpfile(&s, refname);
+ assert((a = archive_read_new()) != NULL);
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
+ assertEqualIntA(a, ARCHIVE_OK, read_open_memory(a, p, s, 3));
+ verify(a);
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
+ assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+
+ free(p);
+}
diff --git a/libarchive/test/test_read_format_zip_extra_padding.zip.uu b/libarchive/test/test_read_format_zip_extra_padding.zip.uu
new file mode 100644
index 000000000000..496bd3c49434
--- /dev/null
+++ b/libarchive/test/test_read_format_zip_extra_padding.zip.uu
@@ -0,0 +1,7 @@
+begin 644 test_read_format_zip_extra_padding.zip
+M4$L#!`H``````"-=CTW$\L?V`@````(````!`!P`80````!55`D``])8%5S;
+M6!5<```$``````````!B"E!+`0(>`PH``````"-=CTW$\L?V`@````(````!
+M`!@```````$```"D@0````!A`````%54"0`#TE@57-M8%5P```0``````$L%
+3!@`````!``$`1P```#T`````````
+`
+end
diff --git a/libarchive/test/test_read_format_zip_lzma_alone_leak.zipx.uu b/libarchive/test/test_read_format_zip_lzma_alone_leak.zipx.uu
new file mode 100644
index 000000000000..5fce21355069
--- /dev/null
+++ b/libarchive/test/test_read_format_zip_lzma_alone_leak.zipx.uu
@@ -0,0 +1,5 @@
+begin 644 test_read_format_zip_lzma_alone_leak.zipx
+M4$L#!"`@6B`.("`@("`@("`@%0```"`@("````4``0`!`"`@(`4``"``````
+J(/\@("`@("`@("!02P,$("`@(`X@(/________\@("`@("`@(``````@
+`
+end
diff --git a/libarchive/test/test_sparse_basic.c b/libarchive/test/test_sparse_basic.c
index 0df0f1d321ac..f12b6af4862a 100644
--- a/libarchive/test/test_sparse_basic.c
+++ b/libarchive/test/test_sparse_basic.c
@@ -68,6 +68,14 @@ struct sparse {
static void create_sparse_file(const char *, const struct sparse *);
+#if defined(__APPLE__)
+/* On APFS holes need to be at least 4096x4097 bytes */
+#define MIN_HOLE 16781312
+#else
+/* Elsewhere we work with 4096*10 bytes */
+#define MIN_HOLE 409600
+#endif
+
#if defined(_WIN32) && !defined(__CYGWIN__)
#include <winioctl.h>
/*
@@ -491,6 +499,7 @@ DEFINE_TEST(test_sparse_basic)
{
char *cwd;
struct archive *a;
+ const char *skip_sparse_tests;
/*
* The alignment of the hole of sparse files deeply depends
* on filesystem. In my experience, sparse_file2 test with
@@ -501,42 +510,42 @@ DEFINE_TEST(test_sparse_basic)
*/
const struct sparse sparse_file0[] = {
// 0 // 1024
- { DATA, 1024 }, { HOLE, 2048000 },
+ { DATA, 1024 }, { HOLE, MIN_HOLE + 1638400 },
// 2049024 // 2051072
- { DATA, 2048 }, { HOLE, 2048000 },
+ { DATA, 2048 }, { HOLE, MIN_HOLE + 1638400 },
// 4099072 // 4103168
- { DATA, 4096 }, { HOLE, 20480000 },
+ { DATA, 4096 }, { HOLE, MIN_HOLE + 20070400 },
// 24583168 // 24591360
- { DATA, 8192 }, { HOLE, 204800000 },
+ { DATA, 8192 }, { HOLE, MIN_HOLE + 204390400 },
// 229391360 // 229391361
{ DATA, 1 }, { END, 0 }
};
const struct sparse sparse_file1[] = {
- { HOLE, 409600 }, { DATA, 1 },
- { HOLE, 409600 }, { DATA, 1 },
- { HOLE, 409600 }, { END, 0 }
+ { HOLE, MIN_HOLE }, { DATA, 1 },
+ { HOLE, MIN_HOLE }, { DATA, 1 },
+ { HOLE, MIN_HOLE }, { END, 0 }
};
const struct sparse sparse_file2[] = {
- { HOLE, 409600 * 1 }, { DATA, 1024 },
- { HOLE, 409600 * 2 }, { DATA, 1024 },
- { HOLE, 409600 * 3 }, { DATA, 1024 },
- { HOLE, 409600 * 4 }, { DATA, 1024 },
- { HOLE, 409600 * 5 }, { DATA, 1024 },
- { HOLE, 409600 * 6 }, { DATA, 1024 },
- { HOLE, 409600 * 7 }, { DATA, 1024 },
- { HOLE, 409600 * 8 }, { DATA, 1024 },
- { HOLE, 409600 * 9 }, { DATA, 1024 },
- { HOLE, 409600 * 10}, { DATA, 1024 },/* 10 */
- { HOLE, 409600 * 1 }, { DATA, 1024 * 1 },
- { HOLE, 409600 * 2 }, { DATA, 1024 * 2 },
- { HOLE, 409600 * 3 }, { DATA, 1024 * 3 },
- { HOLE, 409600 * 4 }, { DATA, 1024 * 4 },
- { HOLE, 409600 * 5 }, { DATA, 1024 * 5 },
- { HOLE, 409600 * 6 }, { DATA, 1024 * 6 },
- { HOLE, 409600 * 7 }, { DATA, 1024 * 7 },
- { HOLE, 409600 * 8 }, { DATA, 1024 * 8 },
- { HOLE, 409600 * 9 }, { DATA, 1024 * 9 },
- { HOLE, 409600 * 10}, { DATA, 1024 * 10},/* 20 */
+ { HOLE, MIN_HOLE }, { DATA, 1024 },
+ { HOLE, MIN_HOLE + 409600 * 1 }, { DATA, 1024 },
+ { HOLE, MIN_HOLE + 409600 * 2 }, { DATA, 1024 },
+ { HOLE, MIN_HOLE + 409600 * 3 }, { DATA, 1024 },
+ { HOLE, MIN_HOLE + 409600 * 4 }, { DATA, 1024 },
+ { HOLE, MIN_HOLE + 409600 * 5 }, { DATA, 1024 },
+ { HOLE, MIN_HOLE + 409600 * 6 }, { DATA, 1024 },
+ { HOLE, MIN_HOLE + 409600 * 7 }, { DATA, 1024 },
+ { HOLE, MIN_HOLE + 409600 * 8 }, { DATA, 1024 },
+ { HOLE, MIN_HOLE + 409600 * 9}, { DATA, 1024 },/* 10 */
+ { HOLE, MIN_HOLE }, { DATA, 1024 * 1 },
+ { HOLE, MIN_HOLE + 409600 * 1 }, { DATA, 1024 * 2 },
+ { HOLE, MIN_HOLE + 409600 * 2 }, { DATA, 1024 * 3 },
+ { HOLE, MIN_HOLE + 409600 * 3 }, { DATA, 1024 * 4 },
+ { HOLE, MIN_HOLE + 409600 * 4 }, { DATA, 1024 * 5 },
+ { HOLE, MIN_HOLE + 409600 * 5 }, { DATA, 1024 * 6 },
+ { HOLE, MIN_HOLE + 409600 * 6 }, { DATA, 1024 * 7 },
+ { HOLE, MIN_HOLE + 409600 * 7 }, { DATA, 1024 * 8 },
+ { HOLE, MIN_HOLE + 409600 * 8 }, { DATA, 1024 * 9 },
+ { HOLE, MIN_HOLE + 409600 * 9}, { DATA, 1024 * 10},/* 20 */
{ END, 0 }
};
const struct sparse sparse_file3[] = {
@@ -553,6 +562,13 @@ DEFINE_TEST(test_sparse_basic)
*/
test_sparse_whole_file_data();
+ skip_sparse_tests = getenv("SKIP_TEST_SPARSE");
+ if (skip_sparse_tests != NULL) {
+ skipping("Skipping sparse tests due to SKIP_TEST_SPARSE "
+ "environment variable");
+ return;
+ }
+
/* Check if the filesystem where CWD on can
* report the number of the holes of a sparse file. */
#ifdef PATH_MAX
@@ -599,10 +615,19 @@ DEFINE_TEST(test_fully_sparse_files)
{
char *cwd;
struct archive *a;
+ const char *skip_sparse_tests;
const struct sparse sparse_file[] = {
- { HOLE, 409600 }, { END, 0 }
+ { HOLE, MIN_HOLE }, { END, 0 }
};
+
+ skip_sparse_tests = getenv("SKIP_TEST_SPARSE");
+ if (skip_sparse_tests != NULL) {
+ skipping("Skipping sparse tests due to SKIP_TEST_SPARSE "
+ "environment variable");
+ return;
+ }
+
/* Check if the filesystem where CWD on can
* report the number of the holes of a sparse file. */
#ifdef PATH_MAX
diff --git a/libarchive/test/test_write_disk_symlink.c b/libarchive/test/test_write_disk_symlink.c
index 13089c78d894..aeadfee8a4e9 100644
--- a/libarchive/test/test_write_disk_symlink.c
+++ b/libarchive/test/test_write_disk_symlink.c
@@ -99,6 +99,139 @@ DEFINE_TEST(test_write_disk_symlink)
assertEqualIntA(ad, 0, archive_write_finish_entry(ad));
archive_entry_free(ae);
+ /* Symbolic link: dot -> . */
+ assert((ae = archive_entry_new()) != NULL);
+ archive_entry_copy_pathname(ae, "dot");
+ archive_entry_set_mode(ae, AE_IFLNK | 0642);
+ archive_entry_unset_size(ae);
+ archive_entry_copy_symlink(ae, ".");
+ assertEqualIntA(ad, 0, r = archive_write_header(ad, ae));
+ if (r >= ARCHIVE_WARN)
+ assertEqualIntA(ad, 0, archive_write_finish_entry(ad));
+ archive_entry_free(ae);
+
+ /* Symbolic link: dotdot -> .. */
+ assert((ae = archive_entry_new()) != NULL);
+ archive_entry_copy_pathname(ae, "dotdot");
+ archive_entry_set_mode(ae, AE_IFLNK | 0642);
+ archive_entry_unset_size(ae);
+ archive_entry_copy_symlink(ae, "..");
+ assertEqualIntA(ad, 0, r = archive_write_header(ad, ae));
+ if (r >= ARCHIVE_WARN)
+ assertEqualIntA(ad, 0, archive_write_finish_entry(ad));
+ archive_entry_free(ae);
+
+ /* Symbolic link: slash -> / */
+ assert((ae = archive_entry_new()) != NULL);
+ archive_entry_copy_pathname(ae, "slash");
+ archive_entry_set_mode(ae, AE_IFLNK | 0642);
+ archive_entry_unset_size(ae);
+ archive_entry_copy_symlink(ae, "/");
+ assertEqualIntA(ad, 0, r = archive_write_header(ad, ae));
+ if (r >= ARCHIVE_WARN)
+ assertEqualIntA(ad, 0, archive_write_finish_entry(ad));
+ archive_entry_free(ae);
+
+ /* Symbolic link: sldot -> /. */
+ assert((ae = archive_entry_new()) != NULL);
+ archive_entry_copy_pathname(ae, "sldot");
+ archive_entry_set_mode(ae, AE_IFLNK | 0642);
+ archive_entry_unset_size(ae);
+ archive_entry_copy_symlink(ae, "/.");
+ assertEqualIntA(ad, 0, r = archive_write_header(ad, ae));
+ if (r >= ARCHIVE_WARN)
+ assertEqualIntA(ad, 0, archive_write_finish_entry(ad));
+ archive_entry_free(ae);
+
+ /* Symbolic link: sldotdot -> /.. */
+ assert((ae = archive_entry_new()) != NULL);
+ archive_entry_copy_pathname(ae, "sldotdot");
+ archive_entry_set_mode(ae, AE_IFLNK | 0642);
+ archive_entry_unset_size(ae);
+ archive_entry_copy_symlink(ae, "/..");
+ assertEqualIntA(ad, 0, r = archive_write_header(ad, ae));
+ if (r >= ARCHIVE_WARN)
+ assertEqualIntA(ad, 0, archive_write_finish_entry(ad));
+ archive_entry_free(ae);
+
+ /* Dir: d1 */
+ assert((ae = archive_entry_new()) != NULL);
+ archive_entry_copy_pathname(ae, "d1");
+ archive_entry_set_mode(ae, AE_IFDIR | 0777);
+ archive_entry_unset_size(ae);
+ assertEqualIntA(ad, 0, r = archive_write_header(ad, ae));
+ if (r >= ARCHIVE_WARN)
+ assertEqualIntA(ad, 0, archive_write_finish_entry(ad));
+ archive_entry_free(ae);
+
+ /* Symbolic link: d1nosl -> d1 */
+ assert((ae = archive_entry_new()) != NULL);
+ archive_entry_copy_pathname(ae, "d1nosl");
+ archive_entry_set_mode(ae, AE_IFLNK | 0642);
+ archive_entry_unset_size(ae);
+ archive_entry_copy_symlink(ae, "d1");
+ assertEqualIntA(ad, 0, r = archive_write_header(ad, ae));
+ if (r >= ARCHIVE_WARN)
+ assertEqualIntA(ad, 0, archive_write_finish_entry(ad));
+ archive_entry_free(ae);
+
+ /* Symbolic link: d1slash -> d1/ */
+ assert((ae = archive_entry_new()) != NULL);
+ archive_entry_copy_pathname(ae, "d1slash");
+ archive_entry_set_mode(ae, AE_IFLNK | 0642);
+ archive_entry_unset_size(ae);
+ archive_entry_copy_symlink(ae, "d1/");
+ assertEqualIntA(ad, 0, r = archive_write_header(ad, ae));
+ if (r >= ARCHIVE_WARN)
+ assertEqualIntA(ad, 0, archive_write_finish_entry(ad));
+ archive_entry_free(ae);
+
+ /* Symbolic link: d1sldot -> d1/. */
+ assert((ae = archive_entry_new()) != NULL);
+ archive_entry_copy_pathname(ae, "d1sldot");
+ archive_entry_set_mode(ae, AE_IFLNK | 0642);
+ archive_entry_unset_size(ae);
+ archive_entry_copy_symlink(ae, "d1/.");
+ assertEqualIntA(ad, 0, r = archive_write_header(ad, ae));
+ if (r >= ARCHIVE_WARN)
+ assertEqualIntA(ad, 0, archive_write_finish_entry(ad));
+ archive_entry_free(ae);
+
+ /* Symbolic link: d1slddot -> d1/.. */
+ assert((ae = archive_entry_new()) != NULL);
+ archive_entry_copy_pathname(ae, "d1slddot");
+ archive_entry_set_mode(ae, AE_IFLNK | 0642);
+ archive_entry_unset_size(ae);
+ archive_entry_copy_symlink(ae, "d1/..");
+ assertEqualIntA(ad, 0, r = archive_write_header(ad, ae));
+ if (r >= ARCHIVE_WARN)
+ assertEqualIntA(ad, 0, archive_write_finish_entry(ad));
+ archive_entry_free(ae);
+
+ /* Symbolic link: d1dir -> d1 */
+ assert((ae = archive_entry_new()) != NULL);
+ archive_entry_copy_pathname(ae, "d1dir");
+ archive_entry_set_mode(ae, AE_IFLNK | 0642);
+ archive_entry_set_symlink_type(ae, AE_SYMLINK_TYPE_DIRECTORY);
+ archive_entry_unset_size(ae);
+ archive_entry_copy_symlink(ae, "d1");
+ assertEqualIntA(ad, 0, r = archive_write_header(ad, ae));
+ if (r >= ARCHIVE_WARN)
+ assertEqualIntA(ad, 0, archive_write_finish_entry(ad));
+ archive_entry_free(ae);
+
+ /* Symbolic link: d1file -> d1 */
+ assert((ae = archive_entry_new()) != NULL);
+ archive_entry_copy_pathname(ae, "d1file");
+ archive_entry_set_mode(ae, AE_IFLNK | 0642);
+ archive_entry_set_symlink_type(ae, AE_SYMLINK_TYPE_FILE);
+ archive_entry_unset_size(ae);
+ archive_entry_copy_symlink(ae, "d1");
+ assertEqualIntA(ad, 0, r = archive_write_header(ad, ae));
+ if (r >= ARCHIVE_WARN)
+ assertEqualIntA(ad, 0, archive_write_finish_entry(ad));
+ archive_entry_free(ae);
+
assertEqualInt(ARCHIVE_OK, archive_write_free(ad));
/* Test the entries on disk. */
@@ -107,11 +240,30 @@ DEFINE_TEST(test_write_disk_symlink)
assertIsReg("link1a", -1);
assertFileSize("link1a", sizeof(data));
assertFileNLinks("link1a", 1);
- assertIsSymlink("link1b", "link1a");
+ assertIsSymlink("link1b", "link1a", 0);
/* Test #2: Should produce identical results to test #1 */
assertIsReg("link2a", -1);
assertFileSize("link2a", sizeof(data));
assertFileNLinks("link2a", 1);
- assertIsSymlink("link2b", "link2a");
+ assertIsSymlink("link2b", "link2a", 0);
+
+ /* Test #3: Special symlinks */
+ assertIsSymlink("dot", ".", 1);
+ assertIsSymlink("dotdot", "..", 1);
+ assertIsSymlink("slash", "/", 1);
+ assertIsSymlink("sldot", "/.", 1);
+ assertIsSymlink("sldotdot", "/..", 1);
+
+ /* Test #4: Directory symlink mixed with . and .. */
+ assertIsDir("d1", -1);
+ /* On Windows, d1nosl should be a file symlink */
+ assertIsSymlink("d1nosl", "d1", 0);
+ assertIsSymlink("d1slash", "d1/", 1);
+ assertIsSymlink("d1sldot", "d1/.", 1);
+ assertIsSymlink("d1slddot", "d1/..", 1);
+
+ /* Test #5: symlink_type is set */
+ assertIsSymlink("d1dir", "d1", 1);
+ assertIsSymlink("d1file", "d1", 0);
}