/* * Verify that test_read_extract correctly works with * Zip entries that use length-at-end. */ static void verify_extract_length_at_end(struct archive *a, int seek_checks) { struct archive_entry *ae; assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualInt(archive_entry_is_encrypted(ae), 0); assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0); assertEqualString("hello.txt", archive_entry_pathname(ae)); if (seek_checks) { assertEqualInt(AE_IFREG | 0644, archive_entry_mode(ae)); assert(archive_entry_size_is_set(ae)); assertEqualInt(6, archive_entry_size(ae)); } else { assert(!archive_entry_size_is_set(ae)); assertEqualInt(0, archive_entry_size(ae)); } if (archive_zlib_version() != NULL) { assertEqualIntA(a, ARCHIVE_OK, archive_read_extract(a, ae, 0)); assertFileContents("hello\x0A", 6, "hello.txt"); } else { assertEqualIntA(a, ARCHIVE_FAILED, archive_read_extract(a, ae, 0)); assertEqualString(archive_error_string(a), "Unsupported ZIP compression method (deflation)"); assert(archive_errno(a) != 0); } assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a)); }
static void test_linkify_old_cpio(void) { struct archive_entry *entry, *e2; struct archive_entry_linkresolver *resolver; /* Initialize the resolver. */ assert(NULL != (resolver = archive_entry_linkresolver_new())); archive_entry_linkresolver_set_strategy(resolver, ARCHIVE_FORMAT_CPIO_POSIX); /* Create an entry with 2 link and try to linkify it. */ assert(NULL != (entry = archive_entry_new())); archive_entry_set_pathname(entry, "test1"); archive_entry_set_ino(entry, 1); archive_entry_set_dev(entry, 2); archive_entry_set_nlink(entry, 2); archive_entry_set_size(entry, 10); archive_entry_linkify(resolver, &entry, &e2); /* Shouldn't have been changed. */ assert(e2 == NULL); assertEqualInt(10, archive_entry_size(entry)); assertEqualString("test1", archive_entry_pathname(entry)); /* Still shouldn't be matched. */ archive_entry_linkify(resolver, &entry, &e2); assert(e2 == NULL); assertEqualString("test1", archive_entry_pathname(entry)); assertEqualString(NULL, archive_entry_hardlink(entry)); assertEqualInt(10, archive_entry_size(entry)); archive_entry_free(entry); archive_entry_linkresolver_free(resolver); }
/* * Read a zip file that has a zip comment in the end of the central * directory record. */ static void verify(const char *refname) { char *p; size_t s; struct archive *a; struct archive_entry *ae; extract_reference_file(refname); p = slurpfile(&s, refname); /* Symlinks can only be extracted with the seeking reader. */ assert((a = archive_read_new()) != NULL); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a)); assertEqualIntA(a, ARCHIVE_OK, read_open_memory_seek(a, p, s, 1)); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString("file0", archive_entry_pathname(ae)); assertEqualInt(AE_IFREG | 0644, archive_entry_mode(ae)); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString("build.sh", archive_entry_pathname(ae)); assertEqualInt(AE_IFREG | 0755, archive_entry_mode(ae)); assertEqualInt(23, archive_entry_size(ae)); assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a)); }
static void test_symlink(void) { const char *refname = "test_read_format_zip_symlink.zip"; char *p; size_t s; struct archive *a; struct archive_entry *ae; extract_reference_file(refname); p = slurpfile(&s, refname); /* Symlinks can only be extracted with the seeking reader. */ assert((a = archive_read_new()) != NULL); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a)); assertEqualIntA(a, ARCHIVE_OK, read_open_memory_seek(a, p, s, 1)); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString("file", archive_entry_pathname(ae)); assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); assertEqualInt(archive_entry_is_encrypted(ae), 0); assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString("symlink", archive_entry_pathname(ae)); assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); assertEqualInt(0, archive_entry_size(ae)); assertEqualString("file", archive_entry_symlink(ae)); assertEqualInt(archive_entry_is_encrypted(ae), 0); assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0); assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a)); }
static void test(int skip_explicitely) { struct archive* a = archive_read_new(); struct archive_entry* e; assertEqualInt(ARCHIVE_OK, archive_read_support_format_raw(a)); assertEqualInt(0, archive_errno(a)); assertEqualString(NULL, archive_error_string(a)); assertEqualInt(ARCHIVE_OK, archive_read_open_memory(a, (void*) data, sizeof(data))); assertEqualString(NULL, archive_error_string(a)); assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &e)); assertEqualInt(0, archive_errno(a)); assertEqualString(NULL, archive_error_string(a)); if (skip_explicitely) assertEqualInt(ARCHIVE_OK, archive_read_data_skip(a)); assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &e)); assertEqualInt(0, archive_errno(a)); assertEqualString(NULL, archive_error_string(a)); archive_read_free(a); }
/* * Verify that we skip junk between entries. The compat_zip_2.zip file * has several bytes of junk between 'file1' and 'file2'. Such * junk is routinely introduced by some Zip writers when they manipulate * existing zip archives. */ static void test_compat_zip_2(void) { char name[] = "test_compat_zip_2.zip"; 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_zip(a)); extract_reference_file(name); assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 10240)); /* Read first entry. */ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString("file1", archive_entry_pathname(ae)); /* Read first entry. */ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString("file2", archive_entry_pathname(ae)); assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); assertEqualInt(ARCHIVE_OK, archive_read_close(a)); assertEqualInt(ARCHIVE_OK, archive_read_free(a)); }
static void test_binary(void) { const char reffile[] = "test_read_format_rar_binary_data.rar"; char file1_buff[1048576]; int file1_size = sizeof(file1_buff); const char file1_test_txt[] = "\x37\xef\xb2\xbe\x33\xf6\xcc\xcb\xee\x2a\x10" "\x9d\x2e\x01\xe9\xf6\xf9\xe5\xe6\x67\x0c\x2b" "\xd8\x6b\xa0\x26\x9a\xf7\x93\x87\x42\xf1\x08" "\x42\xdc\x9b\x76\x91\x20\xa4\x01\xbe\x67\xbd" "\x08\x74\xde\xec"; char file2_buff[32618]; int file2_size = sizeof(file2_buff); const char file2_test_txt[] = "\x00\xee\x78\x00\x00\x4d\x45\x54\x41\x2d\x49" "\x4e\x46\x2f\x6d\x61\x6e\x69\x66\x65\x73\x74" "\x2e\x78\x6d\x6c\x50\x4b\x05\x06\x00\x00\x00" "\x00\x12\x00\x12\x00\xaa\x04\x00\x00\xaa\x7a" "\x00\x00\x00\x00"; 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_file(a, reffile, 10240)); /* First header. */ assertA(0 == archive_read_next_header(a, &ae)); assertEqualString("random_data.bin", archive_entry_pathname(ae)); assertA((int)archive_entry_mtime(ae)); assertA((int)archive_entry_ctime(ae)); assertA((int)archive_entry_atime(ae)); assertEqualInt(file1_size, archive_entry_size(ae)); assertEqualInt(33188, archive_entry_mode(ae)); assertA(file1_size == archive_read_data(a, file1_buff, file1_size)); assertEqualMem(&file1_buff[file1_size - sizeof(file1_test_txt) + 1], file1_test_txt, sizeof(file1_test_txt) - 1); /* Second header. */ assertA(0 == archive_read_next_header(a, &ae)); assertEqualString("LibarchiveAddingTest.odt", archive_entry_pathname(ae)); assertA((int)archive_entry_mtime(ae)); assertA((int)archive_entry_ctime(ae)); assertA((int)archive_entry_atime(ae)); assertEqualInt(file2_size, archive_entry_size(ae)); assertEqualInt(33188, archive_entry_mode(ae)); assertA(file2_size == archive_read_data(a, file2_buff, file2_size)); assertEqualMem(&file2_buff[file2_size + 1 - sizeof(file2_test_txt)], file2_test_txt, sizeof(file2_test_txt) - 1); /* Test EOF */ assertA(1 == archive_read_next_header(a, &ae)); assertEqualInt(2, archive_file_count(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); assertEqualInt(ARCHIVE_OK, archive_read_free(a)); }
static void test_compat_tar_hardlink_1(void) { char name[] = "test_compat_tar_hardlink_1.tar"; struct archive_entry *ae; struct archive *a; assert((a = archive_read_new()) != NULL); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_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, which is a regular file. */ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString("xmcd-3.3.2/docs_d/READMf", archive_entry_pathname(ae)); assertEqualString(NULL, archive_entry_hardlink(ae)); assertEqualInt(321, archive_entry_size(ae)); assertEqualInt(1082575645, archive_entry_mtime(ae)); assertEqualInt(1851, archive_entry_uid(ae)); assertEqualInt(3, archive_entry_gid(ae)); assertEqualInt(0100444, archive_entry_mode(ae)); /* Read second entry, which is a hard link at the end of archive. */ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString("xmcd-3.3.2/README", archive_entry_pathname(ae)); assertEqualString( "xmcd-3.3.2/docs_d/READMf", archive_entry_hardlink(ae)); assertEqualInt(0, archive_entry_size(ae)); assertEqualInt(1082575645, archive_entry_mtime(ae)); assertEqualInt(1851, archive_entry_uid(ae)); assertEqualInt(3, archive_entry_gid(ae)); assertEqualInt(0100444, archive_entry_mode(ae)); /* Verify the end-of-archive. */ /* * This failed in libarchive 2.4.12 because the tar reader * tried to obey the size field for the hard link and ended * up running past the end of the file. */ assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); /* Verify that the format detection worked. */ assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_NONE); assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR); assertEqualInt(ARCHIVE_OK, archive_read_close(a)); #if ARCHIVE_VERSION_NUMBER < 2000000 archive_read_finish(a); #else assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); #endif }
static void verify5(struct archive_entry *ae) { assertEqualInt(archive_entry_filetype(ae), AE_IFDIR); assertEqualInt(archive_entry_mtime(ae), 1131430878); assertEqualInt(archive_entry_mode(ae) & 0777, 0755); assertEqualInt(archive_entry_uid(ae), 1000); assertEqualInt(archive_entry_gid(ae), 1000); assertEqualString(archive_entry_uname(ae), "tim"); assertEqualString(archive_entry_gname(ae), "tim"); }
static void test_read_format_ustar_filename_KOI8R_CP1251(const char *refname) { struct archive *a; struct archive_entry *ae; /* * Read KOI8-R filename in CP1251 with "hdrcharset=KOI8-R" option. */ if (NULL == setlocale(LC_ALL, "Russian_Russia") && NULL == setlocale(LC_ALL, "ru_RU.CP1251")) { skipping("CP1251 locale not available on this system."); return; } 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)); if (ARCHIVE_OK != archive_read_set_options(a, "hdrcharset=KOI8-R")) { skipping("This system cannot convert character-set" " from KOI8-R to CP1251."); goto cleanup; } assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 10240)); /* Verify regular file. */ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString("\xef\xf0\xe8\xe2\xe5\xf2", archive_entry_pathname(ae)); assertEqualInt(6, archive_entry_size(ae)); assertEqualInt(archive_entry_is_encrypted(ae), 0); assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED); /* Verify regular file. */ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString("\xcf\xd0\xc8\xc2\xc5\xd2", archive_entry_pathname(ae)); assertEqualInt(6, archive_entry_size(ae)); assertEqualInt(archive_entry_is_encrypted(ae), 0); assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED); /* End of archive. */ assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); /* Verify archive format. */ assertEqualIntA(a, ARCHIVE_FILTER_COMPRESS, archive_filter_code(a, 0)); assertEqualIntA(a, ARCHIVE_FORMAT_TAR_USTAR, archive_format(a)); /* Close the archive. */ assertEqualInt(ARCHIVE_OK, archive_read_close(a)); cleanup: assertEqualInt(ARCHIVE_OK, archive_read_free(a)); }
static void verify5(struct archive *a, struct archive_entry *ae) { (void)a; /* UNUSED */ assertEqualInt(archive_entry_filetype(ae), AE_IFDIR); assertEqualInt(archive_entry_mtime(ae), 86401); assertEqualInt(archive_entry_mode(ae) & 0777, 0755); assertEqualInt(archive_entry_uid(ae), UID); assertEqualInt(archive_entry_gid(ae), GID); assertEqualString(archive_entry_uname(ae), UNAME); assertEqualString(archive_entry_gname(ae), GNAME); }
/** * A file with leading garbage (similar to an SFX file). */ static void test_compat_zip_4(void) { const char *refname = "test_compat_zip_4.zip"; struct archive_entry *ae; struct archive *a; void *p; size_t s; extract_reference_file(refname); p = slurpfile(&s, refname); /* SFX files require seek support. */ 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_seek(a, p, s, 18)); /* First entry. */ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString("foo", archive_entry_pathname(ae)); assertEqualInt(4, archive_entry_size(ae)); assert(archive_entry_size_is_set(ae)); assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); assertEqualInt(0412, archive_entry_perm(ae)); /* Second entry. */ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString("bar", archive_entry_pathname(ae)); assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); assertEqualInt(4, archive_entry_size(ae)); assert(archive_entry_size_is_set(ae)); assertEqualInt(0567, archive_entry_perm(ae)); /* Third entry. */ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString("baz", archive_entry_pathname(ae)); assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); assertEqualInt(4, archive_entry_size(ae)); assert(archive_entry_size_is_set(ae)); assertEqualInt(0644, archive_entry_perm(ae)); assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a)); /* Try reading without seek support and watch it fail. */ 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_FATAL, read_open_memory(a, p, s, 3)); assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a)); free(p); }
static void test_read_format_ustar_filename_CP866_UTF8(const char *refname) { struct archive *a; struct archive_entry *ae; /* * Read CP866 filename in en_US.UTF-8 with "hdrcharset=CP866" option. */ if (NULL == setlocale(LC_ALL, "en_US.UTF-8")) { skipping("en_US.UTF-8 locale not available on this system."); return; } 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)); if (ARCHIVE_OK != archive_read_set_options(a, "hdrcharset=CP866")) { skipping("This system cannot convert character-set" " from CP866 to UTF-8."); goto cleanup; } assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 10240)); /* Verify regular file. */ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString("\xd0\x9f\xd0\xa0\xd0\x98\xd0\x92\xd0\x95\xd0\xa2", archive_entry_pathname(ae)); assertEqualInt(6, archive_entry_size(ae)); assertEqualInt(archive_entry_is_encrypted(ae), 0); assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED); /* Verify regular file. */ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString("\xd0\xbf\xd1\x80\xd0\xb8\xd0\xb2\xd0\xb5\xd1\x82", archive_entry_pathname(ae)); assertEqualInt(6, archive_entry_size(ae)); assertEqualInt(archive_entry_is_encrypted(ae), 0); assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED); /* End of archive. */ assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); /* Verify archive format. */ assertEqualIntA(a, ARCHIVE_FILTER_COMPRESS, archive_filter_code(a, 0)); assertEqualIntA(a, ARCHIVE_FORMAT_TAR_USTAR, archive_format(a)); /* Close the archive. */ assertEqualInt(ARCHIVE_OK, archive_read_close(a)); cleanup: assertEqualInt(ARCHIVE_OK, archive_read_free(a)); }
static void test_read_format_ustar_filename_eucJP_CP932(const char *refname) { struct archive *a; struct archive_entry *ae; /* * Read eucJP filename in CP932/SJIS with "hdrcharset=eucJP" option. */ if (NULL == setlocale(LC_ALL, "Japanese_Japan") && NULL == setlocale(LC_ALL, "ja_JP.SJIS")) { skipping("CP932 locale not available on this system."); return; } 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)); if (ARCHIVE_OK != archive_read_set_options(a, "hdrcharset=eucJP")) { skipping("This system cannot convert character-set" " from eucJP."); goto cleanup; } assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 10240)); /* Verify regular file. */ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString("\x8a\xbf\x8e\x9a.txt", archive_entry_pathname(ae)); assertEqualInt(8, archive_entry_size(ae)); assertEqualInt(archive_entry_is_encrypted(ae), 0); assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED); /* Verify regular file. */ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString("\x95\x5c.txt", archive_entry_pathname(ae)); assertEqualInt(4, archive_entry_size(ae)); assertEqualInt(archive_entry_is_encrypted(ae), 0); assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED); /* End of archive. */ assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); /* Verify archive format. */ assertEqualIntA(a, ARCHIVE_FILTER_COMPRESS, archive_filter_code(a, 0)); assertEqualIntA(a, ARCHIVE_FORMAT_TAR_USTAR, archive_format(a)); /* Close the archive. */ assertEqualInt(ARCHIVE_OK, archive_read_close(a)); cleanup: assertEqualInt(ARCHIVE_OK, archive_read_free(a)); }
static void test_read_format_cab_filename_CP932_eucJP(const char *refname) { struct archive *a; struct archive_entry *ae; /* * Read CAB filename in ja_JP.eucJP with "hdrcharset=CP932" option. */ if (NULL == setlocale(LC_ALL, "ja_JP.eucJP")) { skipping("ja_JP.eucJP locale not available on this system."); return; } 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)); if (ARCHIVE_OK != archive_read_set_options(a, "hdrcharset=CP932")) { skipping("This system cannot convert character-set" " from CP932 to eucJP."); goto cleanup; } assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 10240)); /* Verify regular file. */ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString( "\xc9\xbd\xa4\xc0\xa4\xe8\x2f\xb4\xc1\xbb\xfa\x2e\x74\x78\x74", archive_entry_pathname(ae)); assertEqualInt(5, archive_entry_size(ae)); /* Verify regular file. */ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString( "\xc9\xbd\xa4\xc0\xa4\xe8\x2f\xb0\xec\xcd\xf7\xc9\xbd\x2e\x74\x78\x74", archive_entry_pathname(ae)); assertEqualInt(5, archive_entry_size(ae)); /* End of archive. */ assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); /* Verify archive format. */ assertEqualIntA(a, ARCHIVE_COMPRESSION_NONE, archive_compression(a)); assertEqualIntA(a, ARCHIVE_FORMAT_CAB, archive_format(a)); /* Close the archive. */ cleanup: assertEqualInt(ARCHIVE_OK, archive_read_close(a)); assertEqualInt(ARCHIVE_OK, archive_read_free(a)); }
static void verify4(struct archive_entry *ae) { assert(S_ISBLK(archive_entry_mode(ae))); assertEqualInt(archive_entry_mode(ae) & 0777, 0755); assertEqualInt(archive_entry_uid(ae), 1000); assertEqualInt(archive_entry_gid(ae), 1000); assertEqualString(archive_entry_uname(ae), "tim"); assertEqualString(archive_entry_gname(ae), "tim"); assertEqualString(archive_entry_pathname(ae), "devblock"); assert(archive_entry_symlink(ae) == NULL); assert(archive_entry_hardlink(ae) == NULL); assertEqualInt(archive_entry_mtime(ae), 1184389185); }
static void verify6(struct archive_entry *ae) { assertEqualInt(archive_entry_filetype(ae), AE_IFIFO); assertEqualInt(archive_entry_mode(ae) & 0777, 0755); assertEqualInt(archive_entry_uid(ae), 1000); assertEqualInt(archive_entry_gid(ae), 1000); assertEqualString(archive_entry_uname(ae), "tim"); assertEqualString(archive_entry_gname(ae), "tim"); assertEqualString(archive_entry_pathname(ae), "fifo"); assert(archive_entry_symlink(ae) == NULL); assert(archive_entry_hardlink(ae) == NULL); assertEqualInt(archive_entry_mtime(ae), 1184389185); }
static void verify2(struct archive *a, struct archive_entry *ae) { (void)a; /* UNUSED */ assertEqualInt(archive_entry_filetype(ae), AE_IFLNK); assertEqualInt(archive_entry_mode(ae) & 0777, 0755); assertEqualInt(archive_entry_uid(ae), UID); assertEqualInt(archive_entry_gid(ae), GID); assertEqualString(archive_entry_uname(ae), UNAME); assertEqualString(archive_entry_gname(ae), GNAME); assertEqualString(archive_entry_pathname(ae), "symlink"); assertEqualString(archive_entry_symlink(ae), "f1"); assert(archive_entry_hardlink(ae) == NULL); }
static void verify7(struct archive *a, struct archive_entry *ae) { (void)a; /* UNUSED */ assert(archive_entry_filetype(ae) == AE_IFREG); assertEqualInt(archive_entry_mode(ae) & 0777, 0644); assertEqualInt(archive_entry_uid(ae), UID); assertEqualInt(archive_entry_gid(ae), GID); assertEqualString(archive_entry_uname(ae), UNAME); assertEqualString(archive_entry_gname(ae), GNAME); assertEqualString(archive_entry_pathname(ae), "dir1/f1"); assert(archive_entry_hardlink(ae) == NULL); assert(archive_entry_symlink(ae) == NULL); assertEqualInt(archive_entry_mtime(ae), 86401); }
/* * This test only for Windows platform because other archiver * applications on Windows translate CP1251 filenames into CP866 * filenames and store it in the ustar file and so we should read * it by default on Windows. */ static void test_read_format_ustar_filename_CP866_CP1251_win(const char *refname) { struct archive *a; struct archive_entry *ae; /* * Read CP866 filename in CP1251 without "hdrcharset=CP866" option. */ if (NULL == setlocale(LC_ALL, "Russian_Russia")) { skipping("Russian_Russia locale not available on this system."); return; } 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 regular file. */ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString("\xcf\xd0\xc8\xc2\xc5\xd2", archive_entry_pathname(ae)); assertEqualInt(6, archive_entry_size(ae)); assertEqualInt(archive_entry_is_encrypted(ae), 0); assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED); /* Verify regular file. */ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString("\xef\xf0\xe8\xe2\xe5\xf2", archive_entry_pathname(ae)); assertEqualInt(6, archive_entry_size(ae)); assertEqualInt(archive_entry_is_encrypted(ae), 0); assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED); /* End of archive. */ assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); /* Verify archive format. */ assertEqualIntA(a, ARCHIVE_FILTER_COMPRESS, archive_filter_code(a, 0)); assertEqualIntA(a, ARCHIVE_FORMAT_TAR_USTAR, archive_format(a)); /* Close the archive. */ assertEqualInt(ARCHIVE_OK, archive_read_close(a)); assertEqualInt(ARCHIVE_OK, archive_read_free(a)); }
static void test_symname() { const char *refname = "test_read_format_7zip_symbolic_name.7z"; struct archive_entry *ae; struct archive *a; char buff[128]; extract_reference_file(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, archive_read_open_filename(a, refname, 10240)); /* Verify regular file1. */ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualInt((AE_IFREG | 0644), archive_entry_mode(ae)); assertEqualString("file1", archive_entry_pathname(ae)); assertEqualInt(86401, archive_entry_mtime(ae)); assertEqualInt(32, archive_entry_size(ae)); assertEqualInt(archive_entry_is_encrypted(ae), 0); assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0); assertEqualInt(32, archive_read_data(a, buff, sizeof(buff))); assertEqualMem(buff, "hellohellohello\nhellohellohello\n", 32); /* Verify symbolic-linke symlinkfile. */ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualInt((AE_IFLNK | 0755), archive_entry_mode(ae)); assertEqualString("symlinkfile", archive_entry_pathname(ae)); assertEqualString("file1", archive_entry_symlink(ae)); assertEqualInt(86401, archive_entry_mtime(ae)); assertEqualInt(archive_entry_is_encrypted(ae), 0); assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0); assertEqualInt(2, archive_file_count(a)); /* End of archive. */ assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); /* Verify archive format. */ assertEqualIntA(a, ARCHIVE_FILTER_NONE, archive_filter_code(a, 0)); assertEqualIntA(a, ARCHIVE_FORMAT_7ZIP, archive_format(a)); /* Close the archive. */ assertEqualInt(ARCHIVE_OK, archive_read_close(a)); assertEqualInt(ARCHIVE_OK, archive_read_free(a)); }
static void test_noeof(void) { char buff[64]; const char reffile[] = "test_read_format_rar_noeof.rar"; const char test_txt[] = "test text document\r\n"; int size = sizeof(test_txt)-1; 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_file(a, reffile, 10240)); /* First header. */ assertA(0 == archive_read_next_header(a, &ae)); assertEqualString("test.txt", archive_entry_pathname(ae)); assertA((int)archive_entry_mtime(ae)); assertA((int)archive_entry_ctime(ae)); assertA((int)archive_entry_atime(ae)); assertEqualInt(20, archive_entry_size(ae)); assertEqualInt(33188, archive_entry_mode(ae)); assertA(size == archive_read_data(a, buff, size)); assertEqualMem(buff, test_txt, size); /* Test EOF */ assertA(1 == archive_read_next_header(a, &ae)); assertEqualInt(1, archive_file_count(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); assertEqualInt(ARCHIVE_OK, archive_read_free(a)); }
static void test_exclusion_and_inclusion(void) { struct archive_entry *ae; struct archive *m; const char *mp; const wchar_t *wp; if (!assert((m = archive_match_new()) != NULL)) return; if (!assert((ae = archive_entry_new()) != NULL)) { archive_match_free(m); return; } assertEqualIntA(m, 0, archive_match_exclude_pattern(m, "^aaa*")); assertEqualIntA(m, 0, archive_match_include_pattern_w(m, L"^aa*")); assertEqualIntA(m, 0, archive_match_include_pattern(m, "^a1*")); /* Test with 'aa1234', which should not be excluded. */ archive_entry_copy_pathname(ae, "aa1234"); failure("'aa1234' should not be excluded"); assertEqualInt(0, archive_match_path_excluded(m, ae)); assertEqualInt(0, archive_match_excluded(m, ae)); archive_entry_clear(ae); archive_entry_copy_pathname_w(ae, L"aa1234"); failure("'aa1234' should not be excluded"); assertEqualInt(0, archive_match_path_excluded(m, ae)); assertEqualInt(0, archive_match_excluded(m, ae)); /* Test with 'aaa1234', which should be excluded. */ archive_entry_copy_pathname(ae, "aaa1234"); failure("'aaa1234' should be excluded"); assertEqualInt(1, archive_match_path_excluded(m, ae)); assertEqualInt(1, archive_match_excluded(m, ae)); archive_entry_clear(ae); archive_entry_copy_pathname_w(ae, L"aaa1234"); failure("'aaa1234' should be excluded"); assertEqualInt(1, archive_match_path_excluded(m, ae)); assertEqualInt(1, archive_match_excluded(m, ae)); /* Verify unmatched_inclusions. */ assertEqualInt(1, archive_match_path_unmatched_inclusions(m)); /* Verify unmatched inclusion patterns. */ assertEqualIntA(m, ARCHIVE_OK, archive_match_path_unmatched_inclusions_next(m, &mp)); assertEqualString("^a1*", mp); assertEqualIntA(m, ARCHIVE_EOF, archive_match_path_unmatched_inclusions_next(m, &mp)); /* Verify unmatched inclusion patterns again in Wide-Char. */ assertEqualIntA(m, ARCHIVE_OK, archive_match_path_unmatched_inclusions_next_w(m, &wp)); assertEqualWString(L"^a1*", wp); assertEqualIntA(m, ARCHIVE_EOF, archive_match_path_unmatched_inclusions_next_w(m, &wp)); /* Clean up. */ archive_entry_free(ae); archive_match_free(m); }
/* * An archive file has one empty file. It means there is no content * in the archive file except for a header. */ static void test_empty_file() { const char *refname = "test_read_format_7zip_empty_file.7z"; struct archive_entry *ae; struct archive *a; extract_reference_file(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, archive_read_open_filename(a, refname, 10240)); /* Verify regular empty. */ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualInt((AE_IFREG | 0644), archive_entry_mode(ae)); assertEqualString("empty", archive_entry_pathname(ae)); assertEqualInt(86401, archive_entry_mtime(ae)); assertEqualInt(0, archive_entry_size(ae)); assertEqualInt(1, archive_file_count(a)); /* End of archive. */ assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); /* Verify archive format. */ assertEqualIntA(a, ARCHIVE_FILTER_NONE, archive_filter_code(a, 0)); assertEqualIntA(a, ARCHIVE_FORMAT_7ZIP, archive_format(a)); /* Close the archive. */ assertEqualInt(ARCHIVE_OK, archive_read_close(a)); assertEqualInt(ARCHIVE_OK, archive_read_free(a)); }
static void test_read_format_mtree2(void) { static char archive[] = "#mtree\n" "d type=dir content=.\n"; 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)); assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, archive, sizeof(archive))); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualInt(archive_format(a), ARCHIVE_FORMAT_MTREE); assertEqualString(archive_entry_pathname(ae), "d"); assertEqualInt(archive_entry_filetype(ae), AE_IFDIR); assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); assertEqualInt(1, archive_file_count(a)); assertEqualInt(ARCHIVE_OK, archive_read_close(a)); assertEqualInt(ARCHIVE_OK, archive_read_free(a)); }
/* * We should get a warning if the contents file doesn't exist. */ static void test_read_format_mtree5(void) { static char archive[] = "#mtree\n" "a type=file contents=nonexistent_file\n"; struct archive_entry *ae; struct archive *a; assertMakeDir("mtree5", 0777); assertChdir("mtree5"); 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_memory(a, archive, sizeof(archive))); assertEqualIntA(a, ARCHIVE_WARN, archive_read_next_header(a, &ae)); assert(strlen(archive_error_string(a)) > 0); assertEqualString(archive_entry_pathname(ae), "a"); assertEqualInt(archive_entry_filetype(ae), AE_IFREG); assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); assertEqualInt(1, archive_file_count(a)); assertEqualInt(ARCHIVE_OK, archive_read_close(a)); assertEqualInt(ARCHIVE_OK, archive_read_free(a)); assertChdir(".."); }
static void verify1(struct archive_entry *ae) { /* A hardlink is not a symlink. */ assert(archive_entry_filetype(ae) != AE_IFLNK); /* Nor is it a directory. */ assert(archive_entry_filetype(ae) != AE_IFDIR); assertEqualInt(archive_entry_mode(ae) & 0777, 0644); assertEqualInt(archive_entry_uid(ae), 1000); assertEqualInt(archive_entry_gid(ae), 1000); assertEqualString(archive_entry_uname(ae), "tim"); assertEqualString(archive_entry_gname(ae), "tim"); assertEqualString(archive_entry_pathname(ae), "hardlink"); assertEqualString(archive_entry_hardlink(ae), "file"); assert(archive_entry_symlink(ae) == NULL); assertEqualInt(archive_entry_mtime(ae), 1184388530); }
static void verify_file0_stream(struct archive *a, int size_known) { struct archive_entry *ae; assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString("-", archive_entry_pathname(ae)); assertEqualInt(AE_IFREG | 0664, archive_entry_mode(ae)); if (size_known) { // zip64b has the uncompressed size at the beginning, // plus CRC and compressed size using length-at-end. assert(archive_entry_size_is_set(ae)); assertEqualInt(6, archive_entry_size(ae)); } else { // zip64a does not have a size at the beginning at all. assert(!archive_entry_size_is_set(ae)); } #ifdef HAVE_ZLIB_H { char data[16]; assertEqualIntA(a, 6, archive_read_data(a, data, 16)); assertEqualMem(data, "file0\x0a", 6); } #endif assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a)); }
static void verify(unsigned char *buff, size_t used, enum vtype type, struct fns *fns) { struct archive *a; struct archive_entry *ae; size_t i; /* * Read ISO image. */ assert((a = archive_read_new()) != NULL); assertEqualIntA(a, 0, archive_read_support_format_all(a)); assertEqualIntA(a, 0, archive_read_support_filter_all(a)); if (type >= 1) assertA(0 == archive_read_set_option(a, NULL, "rockridge", NULL)); if (type >= 2) assertA(0 == archive_read_set_option(a, NULL, "joliet", NULL)); assertEqualIntA(a, 0, archive_read_open_memory(a, buff, used)); /* * Read Root Directory * Root Directory entry must be in ISO image. */ assertEqualIntA(a, 0, archive_read_next_header(a, &ae)); assertEqualInt(archive_entry_atime(ae), archive_entry_ctime(ae)); assertEqualInt(archive_entry_atime(ae), archive_entry_mtime(ae)); assertEqualString(".", archive_entry_pathname(ae)); switch (type) { case ROCKRIDGE: assert((S_IFDIR | 0555) == archive_entry_mode(ae)); break; case JOLIET: assert((S_IFDIR | 0700) == archive_entry_mode(ae)); break; case ISO9660: assert((S_IFDIR | 0700) == archive_entry_mode(ae)); break; } /* * Verify file status. */ memset(fns->names, 0, sizeof(char *) * fns->alloc); fns->cnt = 0; for (i = 0; i < fns->alloc; i++) verify_file(a, type, fns); for (i = 0; i < fns->alloc; i++) free(fns->names[i]); assertEqualInt((int)fns->longest_len, (int)fns->maxlen); /* * Verify the end of the archive. */ assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a)); }
/* * Issue 185: Test a regression that got in between 2.6 and 2.7 that * broke extraction of Zip entries with length-at-end. */ static void test_compat_zip_3(void) { const char *refname = "test_compat_zip_3.zip"; struct archive_entry *ae; struct archive *a; extract_reference_file(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, archive_read_open_filename(a, refname, 10240)); /* First entry. */ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString("soapui-4.0.0/", archive_entry_pathname(ae)); assertEqualInt(0, archive_entry_size(ae)); assert(archive_entry_size_is_set(ae)); assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); /* Second entry. */ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString("soapui-4.0.0/soapui-settings.xml", archive_entry_pathname(ae)); assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); assertEqualInt(1030, archive_entry_size(ae)); assert(archive_entry_size_is_set(ae)); /* Extract under a different name. */ archive_entry_set_pathname(ae, "test_3.txt"); if(libz_enabled) { char *p; size_t s; assertEqualIntA(a, ARCHIVE_OK, archive_read_extract(a, ae, 0)); /* Verify the first 12 bytes actually got written to disk correctly. */ p = slurpfile(&s, "test_3.txt"); assertEqualInt(s, 1030); assertEqualMem(p, "<?xml versio", 12); free(p); } else { skipping("Skipping ZIP compression check, no libz support"); } assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a)); }