From 6b9cd724cf135db9f06f27b94e164f647a4a0df1 Mon Sep 17 00:00:00 2001 From: mm Date: Thu, 21 Mar 2013 21:51:46 +0000 Subject: Delete files accidentially left over in r248590 (libarchive 3.1.2) --- libarchive/filter_fork.c | 161 ---------------- libarchive/test/test_acl_freebsd.c | 260 -------------------------- libarchive/test/test_read_compress_program.c | 84 --------- libarchive/test/test_read_uu.c | 175 ----------------- libarchive/test/test_write_compress.c | 97 ---------- libarchive/test/test_write_compress_bzip2.c | 228 ---------------------- libarchive/test/test_write_compress_gzip.c | 256 ------------------------- libarchive/test/test_write_compress_lzip.c | 247 ------------------------ libarchive/test/test_write_compress_lzma.c | 251 ------------------------- libarchive/test/test_write_compress_program.c | 123 ------------ libarchive/test/test_write_compress_xz.c | 257 ------------------------- 11 files changed, 2139 deletions(-) delete mode 100644 libarchive/filter_fork.c delete mode 100644 libarchive/test/test_acl_freebsd.c delete mode 100644 libarchive/test/test_read_compress_program.c delete mode 100644 libarchive/test/test_read_uu.c delete mode 100644 libarchive/test/test_write_compress.c delete mode 100644 libarchive/test/test_write_compress_bzip2.c delete mode 100644 libarchive/test/test_write_compress_gzip.c delete mode 100644 libarchive/test/test_write_compress_lzip.c delete mode 100644 libarchive/test/test_write_compress_lzma.c delete mode 100644 libarchive/test/test_write_compress_program.c delete mode 100644 libarchive/test/test_write_compress_xz.c diff --git a/libarchive/filter_fork.c b/libarchive/filter_fork.c deleted file mode 100644 index d160524..0000000 --- a/libarchive/filter_fork.c +++ /dev/null @@ -1,161 +0,0 @@ -/*- - * Copyright (c) 2007 Joerg Sonnenberger - * 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 "archive_platform.h" - -/* This capability is only available on POSIX systems. */ -#if defined(HAVE_PIPE) && defined(HAVE_FCNTL) && \ - (defined(HAVE_FORK) || defined(HAVE_VFORK)) - -__FBSDID("$FreeBSD: head/lib/libarchive/filter_fork.c 182958 2008-09-12 05:33:00Z kientzle $"); - -#if defined(HAVE_POLL) && (defined(HAVE_POLL_H) || defined(HAVE_SYS_POLL_H)) -# if defined(HAVE_POLL_H) -# include -# elif defined(HAVE_SYS_POLL_H) -# include -# endif -#elif defined(HAVE_SELECT) -# if defined(HAVE_SYS_SELECT_H) -# include -# elif defined(HAVE_UNISTD_H) -# include -# endif -#endif -#ifdef HAVE_FCNTL_H -# include -#endif -#ifdef HAVE_UNISTD_H -# include -#endif - -#include "filter_fork.h" - -pid_t -__archive_create_child(const char *path, int *child_stdin, int *child_stdout) -{ - pid_t child; - int stdin_pipe[2], stdout_pipe[2], tmp; - - if (pipe(stdin_pipe) == -1) - goto state_allocated; - if (stdin_pipe[0] == 1 /* stdout */) { - if ((tmp = dup(stdin_pipe[0])) == -1) - goto stdin_opened; - close(stdin_pipe[0]); - stdin_pipe[0] = tmp; - } - if (pipe(stdout_pipe) == -1) - goto stdin_opened; - if (stdout_pipe[1] == 0 /* stdin */) { - if ((tmp = dup(stdout_pipe[1])) == -1) - goto stdout_opened; - close(stdout_pipe[1]); - stdout_pipe[1] = tmp; - } - -#if HAVE_VFORK - switch ((child = vfork())) { -#else - switch ((child = fork())) { -#endif - case -1: - goto stdout_opened; - case 0: - close(stdin_pipe[1]); - close(stdout_pipe[0]); - if (dup2(stdin_pipe[0], 0 /* stdin */) == -1) - _exit(254); - if (stdin_pipe[0] != 0 /* stdin */) - close(stdin_pipe[0]); - if (dup2(stdout_pipe[1], 1 /* stdout */) == -1) - _exit(254); - if (stdout_pipe[1] != 1 /* stdout */) - close(stdout_pipe[1]); - execlp(path, path, (char *)NULL); - _exit(254); - default: - close(stdin_pipe[0]); - close(stdout_pipe[1]); - - *child_stdin = stdin_pipe[1]; - fcntl(*child_stdin, F_SETFL, O_NONBLOCK); - *child_stdout = stdout_pipe[0]; - fcntl(*child_stdout, F_SETFL, O_NONBLOCK); - } - - return child; - -stdout_opened: - close(stdout_pipe[0]); - close(stdout_pipe[1]); -stdin_opened: - close(stdin_pipe[0]); - close(stdin_pipe[1]); -state_allocated: - return -1; -} - -void -__archive_check_child(int in, int out) -{ -#if defined(HAVE_POLL) && (defined(HAVE_POLL_H) || defined(HAVE_SYS_POLL_H)) - struct pollfd fds[2]; - int idx; - - idx = 0; - if (in != -1) { - fds[idx].fd = in; - fds[idx].events = POLLOUT; - ++idx; - } - if (out != -1) { - fds[idx].fd = out; - fds[idx].events = POLLIN; - ++idx; - } - - poll(fds, idx, -1); /* -1 == INFTIM, wait forever */ -#elif defined(HAVE_SELECT) - fd_set fds_in, fds_out, fds_error; - - FD_ZERO(&fds_in); - FD_ZERO(&fds_out); - FD_ZERO(&fds_error); - if (out != -1) { - FD_SET(out, &fds_in); - FD_SET(out, &fds_error); - } - if (in != -1) { - FD_SET(in, &fds_out); - FD_SET(in, &fds_error); - } - select(in < out ? out + 1 : in + 1, &fds_in, &fds_out, &fds_error, NULL); -#else - sleep(1); -#endif -} - -#endif /* defined(HAVE_PIPE) && defined(HAVE_VFORK) && defined(HAVE_FCNTL) */ diff --git a/libarchive/test/test_acl_freebsd.c b/libarchive/test/test_acl_freebsd.c deleted file mode 100644 index 1680f9f..0000000 --- a/libarchive/test/test_acl_freebsd.c +++ /dev/null @@ -1,260 +0,0 @@ -/*- - * Copyright (c) 2003-2008 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" -__FBSDID("$FreeBSD: head/lib/libarchive/test/test_acl_freebsd.c 189427 2009-03-06 04:21:23Z kientzle $"); - -#if defined(__FreeBSD__) && __FreeBSD__ > 4 -#include - -struct myacl_t { - int type; /* Type of ACL: "access" or "default" */ - int permset; /* Permissions for this class of users. */ - int tag; /* Owner, User, Owning group, group, other, etc. */ - int qual; /* GID or UID of user/group, depending on tag. */ - const char *name; /* Name of user/group, depending on tag. */ -}; - -static struct myacl_t acls2[] = { - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_EXECUTE | ARCHIVE_ENTRY_ACL_READ, - ARCHIVE_ENTRY_ACL_USER_OBJ, -1, "" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_READ, - ARCHIVE_ENTRY_ACL_USER, 77, "user77" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, 0, - ARCHIVE_ENTRY_ACL_USER, 78, "user78" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_READ, - ARCHIVE_ENTRY_ACL_GROUP_OBJ, -1, "" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, 0007, - ARCHIVE_ENTRY_ACL_GROUP, 78, "group78" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, - ARCHIVE_ENTRY_ACL_WRITE | ARCHIVE_ENTRY_ACL_EXECUTE, - ARCHIVE_ENTRY_ACL_OTHER, -1, "" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, - ARCHIVE_ENTRY_ACL_WRITE | ARCHIVE_ENTRY_ACL_READ | ARCHIVE_ENTRY_ACL_EXECUTE, - ARCHIVE_ENTRY_ACL_MASK, -1, "" }, - { 0, 0, 0, 0, NULL } -}; - -static void -set_acls(struct archive_entry *ae, struct myacl_t *acls) -{ - int i; - - archive_entry_acl_clear(ae); - for (i = 0; acls[i].name != NULL; i++) { - archive_entry_acl_add_entry(ae, - acls[i].type, acls[i].permset, acls[i].tag, acls[i].qual, - acls[i].name); - } -} - -static int -acl_match(acl_entry_t aclent, struct myacl_t *myacl) -{ - gid_t g, *gp; - uid_t u, *up; - acl_tag_t tag_type; - acl_permset_t opaque_ps; - int permset = 0; - - acl_get_tag_type(aclent, &tag_type); - - /* translate the silly opaque permset to a bitmap */ - acl_get_permset(aclent, &opaque_ps); - if (acl_get_perm_np(opaque_ps, ACL_EXECUTE)) - permset |= ARCHIVE_ENTRY_ACL_EXECUTE; - if (acl_get_perm_np(opaque_ps, ACL_WRITE)) - permset |= ARCHIVE_ENTRY_ACL_WRITE; - if (acl_get_perm_np(opaque_ps, ACL_READ)) - permset |= ARCHIVE_ENTRY_ACL_READ; - - if (permset != myacl->permset) - return (0); - - switch (tag_type) { - case ACL_USER_OBJ: - if (myacl->tag != ARCHIVE_ENTRY_ACL_USER_OBJ) return (0); - break; - case ACL_USER: - if (myacl->tag != ARCHIVE_ENTRY_ACL_USER) - return (0); - up = acl_get_qualifier(aclent); - u = *up; - acl_free(up); - if ((uid_t)myacl->qual != u) - return (0); - break; - case ACL_GROUP_OBJ: - if (myacl->tag != ARCHIVE_ENTRY_ACL_GROUP_OBJ) return (0); - break; - case ACL_GROUP: - if (myacl->tag != ARCHIVE_ENTRY_ACL_GROUP) - return (0); - gp = acl_get_qualifier(aclent); - g = *gp; - acl_free(gp); - if ((gid_t)myacl->qual != g) - return (0); - break; - case ACL_MASK: - if (myacl->tag != ARCHIVE_ENTRY_ACL_MASK) return (0); - break; - case ACL_OTHER: - if (myacl->tag != ARCHIVE_ENTRY_ACL_OTHER) return (0); - break; - } - return (1); -} - -static void -compare_acls(acl_t acl, struct myacl_t *myacls) -{ - int *marker; - int entry_id = ACL_FIRST_ENTRY; - int matched; - int i, n; - acl_entry_t acl_entry; - - /* Count ACL entries in myacls array and allocate an indirect array. */ - for (n = 0; myacls[n].name != NULL; ++n) - continue; - marker = malloc(sizeof(marker[0]) * n); - for (i = 0; i < n; i++) - marker[i] = i; - - /* - * Iterate over acls in system acl object, try to match each - * one with an item in the myacls array. - */ - while (1 == acl_get_entry(acl, entry_id, &acl_entry)) { - /* After the first time... */ - entry_id = ACL_NEXT_ENTRY; - - /* Search for a matching entry (tag and qualifier) */ - for (i = 0, matched = 0; i < n && !matched; i++) { - if (acl_match(acl_entry, &myacls[marker[i]])) { - /* We found a match; remove it. */ - marker[i] = marker[n - 1]; - n--; - matched = 1; - } - } - - /* TODO: Print out more details in this case. */ - failure("ACL entry on file that shouldn't be there"); - assert(matched == 1); - } - - /* Dump entries in the myacls array that weren't in the system acl. */ - for (i = 0; i < n; ++i) { - failure(" ACL entry missing from file: " - "type=%d,permset=%d,tag=%d,qual=%d,name=``%s''\n", - myacls[marker[i]].type, myacls[marker[i]].permset, - myacls[marker[i]].tag, myacls[marker[i]].qual, - myacls[marker[i]].name); - assert(0); /* Record this as a failure. */ - } - free(marker); -} - -#endif - - -/* - * Verify ACL restore-to-disk. This test is FreeBSD-specific. - */ - -DEFINE_TEST(test_acl_freebsd) -{ -#if !defined(__FreeBSD__) - skipping("FreeBSD-specific ACL restore test"); -#elif __FreeBSD__ < 5 - skipping("ACL restore supported only on FreeBSD 5.0 and later"); -#else - struct stat st; - struct archive *a; - struct archive_entry *ae; - int n, fd; - acl_t acl; - - /* - * First, do a quick manual set/read of ACL data to - * verify that the local filesystem does support ACLs. - * If it doesn't, we'll simply skip the remaining tests. - */ - acl = acl_from_text("u::rwx,u:1:rw,g::rwx,g:15:rx,o::rwx,m::rwx"); - assert((void *)acl != NULL); - /* Create a test file and try to set an ACL on it. */ - fd = open("pretest", O_WRONLY | O_CREAT | O_EXCL, 0777); - failure("Could not create test file?!"); - if (!assert(fd >= 0)) { - acl_free(acl); - return; - } - - n = acl_set_fd(fd, acl); - acl_free(acl); - if (n != 0 && errno == EOPNOTSUPP) { - close(fd); - skipping("ACL tests require that ACL support be enabled on the filesystem"); - return; - } - if (n != 0 && errno == EINVAL) { - close(fd); - skipping("This filesystem does not support POSIX.1e ACLs"); - return; - } - failure("acl_set_fd(): errno = %d (%s)", - errno, strerror(errno)); - assertEqualInt(0, n); - close(fd); - - /* Create a write-to-disk object. */ - assert(NULL != (a = archive_write_disk_new())); - archive_write_disk_set_options(a, - ARCHIVE_EXTRACT_TIME | ARCHIVE_EXTRACT_PERM | ARCHIVE_EXTRACT_ACL); - - /* Populate an archive entry with some metadata, including ACL info */ - ae = archive_entry_new(); - assert(ae != NULL); - archive_entry_set_pathname(ae, "test0"); - archive_entry_set_mtime(ae, 123456, 7890); - archive_entry_set_size(ae, 0); - set_acls(ae, acls2); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - archive_entry_free(ae); - - /* Close the archive. */ - assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - - /* Verify the data on disk. */ - assertEqualInt(0, stat("test0", &st)); - assertEqualInt(st.st_mtime, 123456); - acl = acl_get_file("test0", ACL_TYPE_ACCESS); - assert(acl != (acl_t)NULL); - compare_acls(acl, acls2); - acl_free(acl); -#endif -} diff --git a/libarchive/test/test_read_compress_program.c b/libarchive/test/test_read_compress_program.c deleted file mode 100644 index 751abd5..0000000 --- a/libarchive/test/test_read_compress_program.c +++ /dev/null @@ -1,84 +0,0 @@ -/*- - * Copyright (c) 2003-2007 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" -__FBSDID("$FreeBSD: head/lib/libarchive/test/test_read_compress_program.c 201247 2009-12-30 05:59:21Z kientzle $"); - -static unsigned char archive[] = { -31,139,8,0,222,'C','p','C',0,3,211,'c',160,'=','0','0','0','0','7','5','U', -0,210,134,230,166,6,200,'4',28,'(',24,26,24,27,155,24,152,24,154,27,155,')', -24,24,26,152,154,25,'2','(',152,210,193,'m',12,165,197,'%',137,'E','@',167, -148,'d',230,226,'U','G','H',30,234,15,'8','=',10,'F',193,'(',24,5,131,28, -0,0,29,172,5,240,0,6,0,0}; - -DEFINE_TEST(test_read_compress_program) -{ - int r; - struct archive_entry *ae; - struct archive *a; - - /* - * First, test handling when a non-existent compression - * program is requested. - */ - assert((a = archive_read_new()) != NULL); - r = archive_read_support_filter_program(a, "nonexistent"); - if (r == ARCHIVE_FATAL) { - skipping("archive_read_support_filter_program() " - "unsupported on this platform"); - return; - } - assertEqualIntA(a, ARCHIVE_OK, r); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_FATAL, - archive_read_open_memory(a, archive, sizeof(archive))); - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_free(a)); - - /* - * If we have "gzip -d", try using that. - */ - if (!canGunzip()) { - skipping("Can't run gunzip program on this platform"); - return; - } - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_filter_none(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_filter_program(a, "gunzip")); - 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_compression(a), ARCHIVE_COMPRESSION_PROGRAM); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR); - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_free(a)); -} - - diff --git a/libarchive/test/test_read_uu.c b/libarchive/test/test_read_uu.c deleted file mode 100644 index 648dbf0..0000000 --- a/libarchive/test/test_read_uu.c +++ /dev/null @@ -1,175 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * Copyright (c) 2009-2011 Michihiro NAKAJIMA - * 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: head/lib/libarchive/test/test_read_uu.c 201248 2009-12-30 06:12:03Z kientzle $"); - -static const char archive[] = { -"begin 644 test_read_uu.Z\n" -"M'YV0+@`('$BPH,&#\"!,J7,BP(4(8$&_4J`$\"`,08$F%4O)AQ(\\2/(#7&@#%C\n" -"M!@T8-##.L`$\"QL@:-F(``%'#H/1A2\n" -"IHU\"0%9=*G4JUJM6K6+-JWO8,.*'4NVK-FS:-.J7\n" -"Received: from libarchive (localhost [127.0.0.1])\n" -" by libarchive (8.14.2/8.14.2) with ESMTP id m5233UT1006448\n" -" for ; Mon, 2 Jun 2008 03:03:31 GMT\n" -" (envelope-from uudecode@libarchive)\n" -"Received: (from uudecode@localhost)\n" -" by libarchive (8.14.2/8.14.2/Submit) id m5233U3e006406\n" -" for uudecode; Mon, 2 Jun 2008 03:03:30 GMT\n" -" (envelope-from root)\n" -"Date: Mon, 2 Jun 2008 03:03:30 GMT\n" -"From: Libarchive Test \n" -"Message-Id: <200806020303.m5233U3e006406@libarchive>\n" -"To: uudecode@libarchive\n" -"Subject: Libarchive uudecode test\n" -"\n" -"* Redistribution and use in source and binary forms, with or without\n" -"* modification, are permitted provided that the following conditions\n" -"* are met:\n" -"\n" -"01234567890abcdeghijklmnopqrstuvwxyz\n" -"01234567890ABCEFGHIJKLMNOPQRSTUVWXYZ\n" -"\n" -}; - -static void -test_read_uu_sub(const char *uudata, size_t uusize, int no_nl) -{ - struct archive_entry *ae; - struct archive *a; - char *buff; - char extradata_no_nl[sizeof(extradata)]; - const char *extradata_ptr; - int extra; - size_t size; - - if (no_nl) { - /* Remove '\n' from extra data to make a very long line. */ - char *p; - memcpy(extradata_no_nl, extradata, sizeof(extradata)); - extradata_ptr = extradata_no_nl; - for (p = extradata_no_nl; - *p && (p = strchr(p, '\n')) != NULL; p++) - *p = ' ';/* Replace '\n' with ' ' a space character. */ - } else - extradata_ptr = extradata; - - assert(NULL != (buff = malloc(uusize + 1024 * 1024))); - if (buff == NULL) - return; - for (extra = 0; extra <= 64; extra = extra==0?1:extra*2) { - char *p = buff; - - size = extra * 1024; - /* Add extra text size of which is from 1K bytes to - * 64Kbytes before uuencoded data. */ - while (size) { - if (size > sizeof(extradata)-1) { - memcpy(p, extradata_ptr, sizeof(extradata)-1); - p += sizeof(extradata)-1; - size -= sizeof(extradata)-1; - } else { - memcpy(p, extradata_ptr, size-1); - p += size-1; - *p++ = '\n';/* the last of extra text must have - * '\n' character. */ - break; - } - } - memcpy(p, uudata, uusize); - size = extra * 1024 + uusize; - - 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, buff, size, 2)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_next_header(a, &ae)); - failure("archive_compression_name(a)=\"%s\"" - "extra %d, NL %d", - archive_compression_name(a), extra, !no_nl); - assertEqualInt(archive_compression(a), - ARCHIVE_COMPRESSION_COMPRESS); - failure("archive_format_name(a)=\"%s\"" - "extra %d, NL %d", - archive_format_name(a), extra, !no_nl); - assertEqualInt(archive_format(a), - ARCHIVE_FORMAT_TAR_USTAR); - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_free(a)); - } - - /* UUdecode bidder shouldn't scan too much data; make sure it - * fails if we put 512k of data before the start. */ - size = 512 * 1024; - for (extra = 0; (size_t)extra < size; ++extra) - buff[extra + 1024] = buff[extra]; - buff[size - 1] = '\n'; - memcpy(buff + size, uudata, uusize); - size += uusize; - 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, buff, size, 2)); - assertEqualInt(ARCHIVE_OK, archive_read_free(a)); - - free(buff); -} - -DEFINE_TEST(test_read_uu) -{ - /* Read the traditional uuencoded data. */ - test_read_uu_sub(archive, sizeof(archive)-1, 0); - /* Read the Base64 uuencoded data. */ - test_read_uu_sub(archive64, sizeof(archive64)-1, 0); - /* Read the traditional uuencoded data with very long line extra - * data in front of it. */ - test_read_uu_sub(archive, sizeof(archive)-1, 1); - /* Read the Base64 uuencoded data with very long line extra data - * in front of it. */ - test_read_uu_sub(archive64, sizeof(archive64)-1, 1); -} - diff --git a/libarchive/test/test_write_compress.c b/libarchive/test/test_write_compress.c deleted file mode 100644 index bb81c4f..0000000 --- a/libarchive/test/test_write_compress.c +++ /dev/null @@ -1,97 +0,0 @@ -/*- - * Copyright (c) 2007 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 - * in this position and unchanged. - * 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: head/lib/libarchive/test/test_write_compress.c 189308 2009-03-03 17:02:51Z kientzle $"); - -/* - * A basic exercise of compress reading and writing. - * - * TODO: Add a reference file and make sure we can decompress that. - */ - -DEFINE_TEST(test_write_compress) -{ - struct archive_entry *ae; - struct archive* a; - char *buff, *data; - size_t buffsize, datasize; - char path[16]; - size_t used; - int i; - - buffsize = 1000000; - assert(NULL != (buff = (char *)malloc(buffsize))); - - datasize = 10000; - assert(NULL != (data = (char *)malloc(datasize))); - memset(data, 0, datasize); - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_compression_compress(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_open_memory(a, buff, buffsize, &used)); - - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, path); - archive_entry_set_size(ae, datasize); - archive_entry_set_filetype(ae, AE_IFREG); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - assertEqualInt(datasize, - archive_write_data(a, data, datasize)); - archive_entry_free(ae); - } - - assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - - /* - * Now, read the data back. - */ - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used)); - - - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - if (!assertEqualInt(0, archive_read_next_header(a, &ae))) - break; - assertEqualString(path, archive_entry_pathname(ae)); - assertEqualInt((int)datasize, archive_entry_size(ae)); - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_free(a)); - - free(data); - free(buff); -} diff --git a/libarchive/test/test_write_compress_bzip2.c b/libarchive/test/test_write_compress_bzip2.c deleted file mode 100644 index b9e9236..0000000 --- a/libarchive/test/test_write_compress_bzip2.c +++ /dev/null @@ -1,228 +0,0 @@ -/*- - * Copyright (c) 2007 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 - * in this position and unchanged. - * 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: head/lib/libarchive/test/test_write_compress_bzip2.c 191183 2009-04-17 01:06:31Z kientzle $"); - -/* - * A basic exercise of bzip2 reading and writing. - * - * TODO: Add a reference file and make sure we can decompress that. - */ - -DEFINE_TEST(test_write_compress_bzip2) -{ - struct archive_entry *ae; - struct archive* a; - char *buff, *data; - size_t buffsize, datasize; - char path[16]; - size_t used1, used2; - int i, r; - - buffsize = 2000000; - assert(NULL != (buff = (char *)malloc(buffsize))); - - datasize = 10000; - assert(NULL != (data = (char *)malloc(datasize))); - memset(data, 0, datasize); - - /* - * Write a 100 files and read them all back. - */ - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - r = archive_write_set_compression_bzip2(a); - if (r == ARCHIVE_FATAL) { - skipping("bzip2 writing not supported on this platform"); - assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - return; - } - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_bytes_per_block(a, 10)); - assertEqualInt(ARCHIVE_COMPRESSION_BZIP2, archive_compression(a)); - assertEqualString("bzip2", archive_compression_name(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used1)); - assertEqualInt(ARCHIVE_COMPRESSION_BZIP2, archive_compression(a)); - assertEqualString("bzip2", archive_compression_name(a)); - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_filetype(ae, AE_IFREG); - archive_entry_set_size(ae, datasize); - for (i = 0; i < 999; i++) { - sprintf(path, "file%03d", i); - archive_entry_copy_pathname(ae, path); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - assertA(datasize - == (size_t)archive_write_data(a, data, datasize)); - } - archive_entry_free(ae); - assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used1)); - for (i = 0; i < 999; i++) { - sprintf(path, "file%03d", i); - if (!assertEqualInt(0, archive_read_next_header(a, &ae))) - break; - assertEqualString(path, archive_entry_pathname(ae)); - assertEqualInt((int)datasize, archive_entry_size(ae)); - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_free(a)); - - /* - * Repeat the cycle again, this time setting some compression - * options. - */ - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_bytes_per_block(a, 10)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_bzip2(a)); - assertEqualIntA(a, ARCHIVE_FAILED, - archive_write_set_filter_option(a, NULL, "nonexistent-option", "0")); - assertEqualIntA(a, ARCHIVE_FAILED, - archive_write_set_filter_option(a, NULL, "compression-level", "abc")); - assertEqualIntA(a, ARCHIVE_FAILED, - archive_write_set_filter_option(a, NULL, "compression-level", "99")); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_filter_option(a, NULL, "compression-level", "9")); - assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2)); - for (i = 0; i < 999; i++) { - sprintf(path, "file%03d", i); - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, path); - archive_entry_set_size(ae, datasize); - archive_entry_set_filetype(ae, AE_IFREG); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - assertA(datasize == (size_t)archive_write_data(a, data, datasize)); - archive_entry_free(ae); - } - assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - - /* Curiously, this test fails; the test data above compresses - * better at default compression than at level 9. */ - /* - failure("compression-level=9 wrote %d bytes, default wrote %d bytes", - (int)used2, (int)used1); - assert(used2 < used1); - */ - - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used2)); - for (i = 0; i < 999; i++) { - sprintf(path, "file%03d", i); - if (!assertEqualInt(0, archive_read_next_header(a, &ae))) - break; - assertEqualString(path, archive_entry_pathname(ae)); - assertEqualInt((int)datasize, archive_entry_size(ae)); - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_free(a)); - - /* - * Repeat again, with much lower compression. - */ - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_bytes_per_block(a, 10)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_bzip2(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_filter_option(a, NULL, "compression-level", "1")); - assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2)); - for (i = 0; i < 999; i++) { - sprintf(path, "file%03d", i); - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, path); - archive_entry_set_size(ae, datasize); - archive_entry_set_filetype(ae, AE_IFREG); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - failure("Writing file %s", path); - assertEqualIntA(a, datasize, - (size_t)archive_write_data(a, data, datasize)); - archive_entry_free(ae); - } - assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - - /* Level 0 really does result in larger data. */ - failure("Compression-level=0 wrote %d bytes; default wrote %d bytes", - (int)used2, (int)used1); - assert(used2 > used1); - - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used2)); - for (i = 0; i < 999; i++) { - sprintf(path, "file%03d", i); - if (!assertEqualInt(0, archive_read_next_header(a, &ae))) - break; - assertEqualString(path, archive_entry_pathname(ae)); - assertEqualInt((int)datasize, archive_entry_size(ae)); - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_free(a)); - - /* - * Test various premature shutdown scenarios to make sure we - * don't crash or leak memory. - */ - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_bzip2(a)); - assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_bzip2(a)); - assertEqualInt(ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_bzip2(a)); - assertEqualInt(ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_bzip2(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2)); - assertEqualInt(ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - - /* - * Clean up. - */ - free(data); - free(buff); -} diff --git a/libarchive/test/test_write_compress_gzip.c b/libarchive/test/test_write_compress_gzip.c deleted file mode 100644 index c8281e7..0000000 --- a/libarchive/test/test_write_compress_gzip.c +++ /dev/null @@ -1,256 +0,0 @@ -/*- - * Copyright (c) 2007 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 - * in this position and unchanged. - * 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: head/lib/libarchive/test/test_write_compress_gzip.c 191183 2009-04-17 01:06:31Z kientzle $"); - -/* - * A basic exercise of gzip reading and writing. - * - * TODO: Add a reference file and make sure we can decompress that. - */ - -DEFINE_TEST(test_write_compress_gzip) -{ - struct archive_entry *ae; - struct archive* a; - char *buff, *data; - size_t buffsize, datasize; - char path[16]; - size_t used1, used2; - int i, r; - - buffsize = 2000000; - assert(NULL != (buff = (char *)malloc(buffsize))); - - datasize = 10000; - assert(NULL != (data = (char *)malloc(datasize))); - memset(data, 0, datasize); - - /* - * Write a 100 files and read them all back. - */ - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_compression_compress(a)); - r = archive_write_set_compression_gzip(a); - if (r == ARCHIVE_FATAL) { - skipping("gzip writing not supported on this platform"); - assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - return; - } - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_bytes_per_block(a, 10)); - assertEqualInt(ARCHIVE_COMPRESSION_GZIP, archive_compression(a)); - assertEqualString("gzip", archive_compression_name(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used1)); - assertEqualInt(ARCHIVE_COMPRESSION_GZIP, archive_compression(a)); - assertEqualString("gzip", archive_compression_name(a)); - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_filetype(ae, AE_IFREG); - archive_entry_set_size(ae, datasize); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - archive_entry_copy_pathname(ae, path); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - assertA(datasize - == (size_t)archive_write_data(a, data, datasize)); - } - archive_entry_free(ae); - assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - r = archive_read_support_filter_gzip(a); - if (r == ARCHIVE_WARN) { - skipping("Can't verify gzip writing by reading back;" - " gzip reading not fully supported on this platform"); - } else { - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, buff, used1)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - if (!assertEqualInt(ARCHIVE_OK, - archive_read_next_header(a, &ae))) - break; - assertEqualString(path, archive_entry_pathname(ae)); - assertEqualInt((int)datasize, archive_entry_size(ae)); - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - } - assertEqualInt(ARCHIVE_OK, archive_read_free(a)); - - /* - * Repeat the cycle again, this time setting some compression - * options. - */ - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_bytes_per_block(a, 10)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_gzip(a)); - assertEqualIntA(a, ARCHIVE_FAILED, - archive_write_set_options(a, "gzip:nonexistent-option=0")); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_options(a, "gzip:compression-level=0")); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_filter_option(a, NULL, "compression-level", "9")); - assertEqualIntA(a, ARCHIVE_FAILED, - archive_write_set_filter_option(a, NULL, "compression-level", "abc")); - assertEqualIntA(a, ARCHIVE_FAILED, - archive_write_set_filter_option(a, NULL, "compression-level", "99")); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_options(a, "gzip:compression-level=9")); - assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, path); - archive_entry_set_size(ae, datasize); - archive_entry_set_filetype(ae, AE_IFREG); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - assertA(datasize == (size_t)archive_write_data(a, data, datasize)); - archive_entry_free(ae); - } - assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - - /* Curiously, this test fails; the test data above compresses - * better at default compression than at level 9. */ - /* - failure("compression-level=9 wrote %d bytes, default wrote %d bytes", - (int)used2, (int)used1); - assert(used2 < used1); - */ - - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - r = archive_read_support_filter_gzip(a); - if (r == ARCHIVE_WARN) { - skipping("gzip reading not fully supported on this platform"); - } else { - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_filter_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, buff, used2)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - if (!assertEqualInt(ARCHIVE_OK, - archive_read_next_header(a, &ae))) - break; - assertEqualString(path, archive_entry_pathname(ae)); - assertEqualInt((int)datasize, archive_entry_size(ae)); - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - } - assertEqualInt(ARCHIVE_OK, archive_read_free(a)); - - /* - * Repeat again, with much lower compression. - */ - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_bytes_per_block(a, 10)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_gzip(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_filter_option(a, NULL, "compression-level", "0")); - assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, path); - archive_entry_set_size(ae, datasize); - archive_entry_set_filetype(ae, AE_IFREG); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - failure("Writing file %s", path); - assertEqualIntA(a, datasize, - (size_t)archive_write_data(a, data, datasize)); - archive_entry_free(ae); - } - assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - - /* Level 0 really does result in larger data. */ - failure("Compression-level=0 wrote %d bytes; default wrote %d bytes", - (int)used2, (int)used1); - assert(used2 > used1); - - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); - r = archive_read_support_filter_gzip(a); - if (r == ARCHIVE_WARN) { - skipping("gzip reading not fully supported on this platform"); - } else { - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, buff, used2)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - if (!assertEqualInt(ARCHIVE_OK, - archive_read_next_header(a, &ae))) - break; - assertEqualString(path, archive_entry_pathname(ae)); - assertEqualInt((int)datasize, archive_entry_size(ae)); - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - } - assertEqualInt(ARCHIVE_OK, archive_read_free(a)); - - /* - * Test various premature shutdown scenarios to make sure we - * don't crash or leak memory. - */ - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_gzip(a)); - assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_gzip(a)); - assertEqualInt(ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_gzip(a)); - assertEqualInt(ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_gzip(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2)); - assertEqualInt(ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - - /* - * Clean up. - */ - free(data); - free(buff); -} diff --git a/libarchive/test/test_write_compress_lzip.c b/libarchive/test/test_write_compress_lzip.c deleted file mode 100644 index 7dd8bcf..0000000 --- a/libarchive/test/test_write_compress_lzip.c +++ /dev/null @@ -1,247 +0,0 @@ -/*- - * Copyright (c) 2010 Michihiro NAKAJIMA - * Copyright (c) 2007-2009 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 - * in this position and unchanged. - * 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$"); - -/* - * A basic exercise of lzip reading and writing. - * - */ - -DEFINE_TEST(test_write_compress_lzip) -{ - struct archive_entry *ae; - struct archive* a; - char *buff, *data; - size_t buffsize, datasize; - char path[16]; - size_t used1, used2; - int i, r; - - buffsize = 2000000; - assert(NULL != (buff = (char *)malloc(buffsize))); - - datasize = 10000; - assert(NULL != (data = (char *)malloc(datasize))); - memset(data, 0, datasize); - - /* - * Write a 100 files and read them all back. - */ - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - r = archive_write_set_compression_lzip(a); - if (r == ARCHIVE_FATAL) { - skipping("lzip writing not supported on this platform"); - assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - return; - } - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_bytes_per_block(a, 10)); - assertEqualInt(ARCHIVE_COMPRESSION_LZIP, archive_compression(a)); - assertEqualString("lzip", archive_compression_name(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_open_memory(a, buff, buffsize, &used1)); - assertEqualInt(ARCHIVE_COMPRESSION_LZIP, archive_compression(a)); - assertEqualString("lzip", archive_compression_name(a)); - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_filetype(ae, AE_IFREG); - archive_entry_set_size(ae, datasize); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - archive_entry_copy_pathname(ae, path); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - assertA(datasize - == (size_t)archive_write_data(a, data, datasize)); - } - archive_entry_free(ae); - assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - r = archive_read_support_filter_lzip(a); - if (r == ARCHIVE_WARN) { - skipping("Can't verify lzip writing by reading back;" - " lzip reading not fully supported on this platform"); - } else { - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_filter_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, buff, used1)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - if (!assertEqualInt(ARCHIVE_OK, - archive_read_next_header(a, &ae))) - break; - assertEqualString(path, archive_entry_pathname(ae)); - assertEqualInt((int)datasize, archive_entry_size(ae)); - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - } - assertEqualInt(ARCHIVE_OK, archive_read_free(a)); - - /* - * Repeat the cycle again, this time setting some compression - * options. - */ - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_bytes_per_block(a, 10)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_lzip(a)); - assertEqualIntA(a, ARCHIVE_FAILED, - archive_write_set_filter_option(a, NULL, "nonexistent-option", "0")); - assertEqualIntA(a, ARCHIVE_FAILED, - archive_write_set_filter_option(a, NULL, "compression-level", "abc")); - assertEqualIntA(a, ARCHIVE_FAILED, - archive_write_set_filter_option(a, NULL, "compression-level", "99")); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_filter_option(a, NULL, "compression-level", "9")); - assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, path); - archive_entry_set_size(ae, datasize); - archive_entry_set_filetype(ae, AE_IFREG); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - assertA(datasize == (size_t)archive_write_data(a, data, datasize)); - archive_entry_free(ae); - } - assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - - - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - r = archive_read_support_filter_lzip(a); - if (r == ARCHIVE_WARN) { - skipping("lzip reading not fully supported on this platform"); - } else { - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_filter_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, buff, used2)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - failure("Trying to read %s", path); - if (!assertEqualIntA(a, ARCHIVE_OK, - archive_read_next_header(a, &ae))) - break; - assertEqualString(path, archive_entry_pathname(ae)); - assertEqualInt((int)datasize, archive_entry_size(ae)); - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - } - assertEqualInt(ARCHIVE_OK, archive_read_free(a)); - - /* - * Repeat again, with much lower compression. - */ - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_bytes_per_block(a, 10)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_lzip(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_filter_option(a, NULL, "compression-level", "0")); - assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, path); - archive_entry_set_size(ae, datasize); - archive_entry_set_filetype(ae, AE_IFREG); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - failure("Writing file %s", path); - assertEqualIntA(a, datasize, - (size_t)archive_write_data(a, data, datasize)); - archive_entry_free(ae); - } - assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - - /* Level 0 really does result in larger data. */ - failure("Compression-level=0 wrote %d bytes; default wrote %d bytes", - (int)used2, (int)used1); - assert(used2 > used1); - - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); - r = archive_read_support_filter_lzip(a); - if (r == ARCHIVE_WARN) { - skipping("lzip reading not fully supported on this platform"); - } else { - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, buff, used2)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - if (!assertEqualInt(ARCHIVE_OK, - archive_read_next_header(a, &ae))) - break; - assertEqualString(path, archive_entry_pathname(ae)); - assertEqualInt((int)datasize, archive_entry_size(ae)); - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - } - assertEqualInt(ARCHIVE_OK, archive_read_free(a)); - - /* - * Test various premature shutdown scenarios to make sure we - * don't crash or leak memory. - */ - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_lzip(a)); - assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_lzip(a)); - assertEqualInt(ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_lzip(a)); - assertEqualInt(ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_lzip(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2)); - assertEqualInt(ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - - /* - * Clean up. - */ - free(data); - free(buff); -} diff --git a/libarchive/test/test_write_compress_lzma.c b/libarchive/test/test_write_compress_lzma.c deleted file mode 100644 index f3b9de3..0000000 --- a/libarchive/test/test_write_compress_lzma.c +++ /dev/null @@ -1,251 +0,0 @@ -/*- - * Copyright (c) 2007-2009 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 - * in this position and unchanged. - * 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: head/lib/libarchive/test/test_write_compress_lzma.c 191183 2009-04-17 01:06:31Z kientzle $"); - -/* - * A basic exercise of lzma reading and writing. - * - */ - -DEFINE_TEST(test_write_compress_lzma) -{ - struct archive_entry *ae; - struct archive* a; - char *buff, *data; - size_t buffsize, datasize; - char path[16]; - size_t used1, used2; - int i, r; - - buffsize = 2000000; - assert(NULL != (buff = (char *)malloc(buffsize))); - - datasize = 10000; - assert(NULL != (data = (char *)malloc(datasize))); - memset(data, 0, datasize); - - /* - * Write a 100 files and read them all back. - */ - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - r = archive_write_set_compression_lzma(a); - if (r == ARCHIVE_FATAL) { - skipping("lzma writing not supported on this platform"); - assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - return; - } - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_bytes_per_block(a, 10)); - assertEqualInt(ARCHIVE_COMPRESSION_LZMA, archive_compression(a)); - assertEqualString("lzma", archive_compression_name(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_open_memory(a, buff, buffsize, &used1)); - assertEqualInt(ARCHIVE_COMPRESSION_LZMA, archive_compression(a)); - assertEqualString("lzma", archive_compression_name(a)); - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_filetype(ae, AE_IFREG); - archive_entry_set_size(ae, datasize); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - archive_entry_copy_pathname(ae, path); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - assertA(datasize - == (size_t)archive_write_data(a, data, datasize)); - } - archive_entry_free(ae); - assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - r = archive_read_support_filter_lzma(a); - if (r == ARCHIVE_WARN) { - skipping("Can't verify lzma writing by reading back;" - " lzma reading not fully supported on this platform"); - } else { - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_filter_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, buff, used1)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - if (!assertEqualInt(ARCHIVE_OK, - archive_read_next_header(a, &ae))) - break; - assertEqualString(path, archive_entry_pathname(ae)); - assertEqualInt((int)datasize, archive_entry_size(ae)); - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - } - assertEqualInt(ARCHIVE_OK, archive_read_free(a)); - - /* - * Repeat the cycle again, this time setting some compression - * options. - */ - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_bytes_per_block(a, 10)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_lzma(a)); - assertEqualIntA(a, ARCHIVE_FAILED, - archive_write_set_filter_option(a, NULL, "nonexistent-option", "0")); - assertEqualIntA(a, ARCHIVE_FAILED, - archive_write_set_filter_option(a, NULL, "compression-level", "abc")); - assertEqualIntA(a, ARCHIVE_FAILED, - archive_write_set_filter_option(a, NULL, "compression-level", "99")); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_filter_option(a, NULL, "compression-level", "9")); - assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, path); - archive_entry_set_size(ae, datasize); - archive_entry_set_filetype(ae, AE_IFREG); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - assertA(datasize == (size_t)archive_write_data(a, data, datasize)); - archive_entry_free(ae); - } - assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - - - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - r = archive_read_support_filter_lzma(a); - if (r == ARCHIVE_WARN) { - skipping("lzma reading not fully supported on this platform"); - } else { - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_filter_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, buff, used2)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - failure("Trying to read %s", path); - if (!assertEqualIntA(a, ARCHIVE_OK, - archive_read_next_header(a, &ae))) - break; - assertEqualString(path, archive_entry_pathname(ae)); - assertEqualInt((int)datasize, archive_entry_size(ae)); - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - } - assertEqualInt(ARCHIVE_OK, archive_read_free(a)); - - /* - * Repeat again, with much lower compression. - */ - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_bytes_per_block(a, 10)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_lzma(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_filter_option(a, NULL, "compression-level", "0")); - assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, path); - archive_entry_set_size(ae, datasize); - archive_entry_set_filetype(ae, AE_IFREG); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - failure("Writing file %s", path); - assertEqualIntA(a, datasize, - (size_t)archive_write_data(a, data, datasize)); - archive_entry_free(ae); - } - assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - - /* It would be nice to assert that compression-level=0 produced - * consistently larger/smaller results than the default compression, - * but the results here vary a lot depending on the version of liblzma - * being used. */ - /* - failure("Compression-level=0 wrote %d bytes; default wrote %d bytes", - (int)used2, (int)used1); - assert(used2 > used1); - */ - - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); - r = archive_read_support_filter_lzma(a); - if (r == ARCHIVE_WARN) { - skipping("lzma reading not fully supported on this platform"); - } else { - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, buff, used2)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - if (!assertEqualInt(ARCHIVE_OK, - archive_read_next_header(a, &ae))) - break; - assertEqualString(path, archive_entry_pathname(ae)); - assertEqualInt((int)datasize, archive_entry_size(ae)); - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - } - assertEqualInt(ARCHIVE_OK, archive_read_free(a)); - - /* - * Test various premature shutdown scenarios to make sure we - * don't crash or leak memory. - */ - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_lzma(a)); - assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_lzma(a)); - assertEqualInt(ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_lzma(a)); - assertEqualInt(ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_lzma(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2)); - assertEqualInt(ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - - /* - * Clean up. - */ - free(data); - free(buff); -} diff --git a/libarchive/test/test_write_compress_program.c b/libarchive/test/test_write_compress_program.c deleted file mode 100644 index 4956e1a..0000000 --- a/libarchive/test/test_write_compress_program.c +++ /dev/null @@ -1,123 +0,0 @@ -/*- - * Copyright (c) 2003-2007 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" -__FBSDID("$FreeBSD: head/lib/libarchive/test/test_write_compress_program.c 201247 2009-12-30 05:59:21Z kientzle $"); - -char buff[1000000]; -char buff2[64]; - -DEFINE_TEST(test_write_compress_program) -{ - struct archive_entry *ae; - struct archive *a; - size_t used; - int blocksize = 1024; - int r; - - if (!canGzip()) { - skipping("Cannot run 'gzip'"); - return; - } - /* NOTE: Setting blocksize=1024 will cause gunzip failure because - * it add extra bytes that gunzip ignores with its warning and - * exit code 1. So we should set blocksize=1 in order not to - * yield the extra bytes when using gunzip. */ - assert((a = archive_read_new()) != NULL); - r = archive_read_support_filter_gzip(a); - if (r != ARCHIVE_OK && canGunzip()) - blocksize = 1; - assertEqualInt(ARCHIVE_OK, archive_read_free(a)); - - /* Create a new archive in memory. */ - /* Write it through an external "gzip" program. */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - r = archive_write_set_compression_program(a, "gzip"); - if (r == ARCHIVE_FATAL) { - skipping("Write compression via external " - "program unsupported on this platform"); - archive_write_free(a); - return; - } - assertA(0 == archive_write_set_bytes_per_block(a, blocksize)); - assertA(0 == archive_write_set_bytes_in_last_block(a, blocksize)); - assertA(blocksize == archive_write_get_bytes_in_last_block(a)); - assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); - assertA(blocksize == archive_write_get_bytes_in_last_block(a)); - - /* - * Write a file to it. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_mtime(ae, 1, 10); - archive_entry_copy_pathname(ae, "file"); - archive_entry_set_mode(ae, S_IFREG | 0755); - archive_entry_set_size(ae, 8); - - assertA(0 == archive_write_header(a, ae)); - archive_entry_free(ae); - assertA(8 == archive_write_data(a, "12345678", 9)); - - /* Close out the archive. */ - assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - - /* - * Now, read the data back through the built-in gzip support. - */ - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); - r = archive_read_support_filter_gzip(a); - /* The compression_gzip() handler will fall back to gunzip - * automatically, but if we know gunzip isn't available, then - * skip the rest. */ - if (r != ARCHIVE_OK && !canGunzip()) { - skipping("No libz and no gunzip program, " - "unable to verify gzip compression"); - assertEqualInt(ARCHIVE_OK, archive_read_free(a)); - return; - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used)); - - if (!assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae))) { - archive_read_free(a); - return; - } - - assertEqualInt(1, archive_entry_mtime(ae)); - assertEqualInt(0, archive_entry_atime(ae)); - assertEqualInt(0, archive_entry_ctime(ae)); - assertEqualString("file", archive_entry_pathname(ae)); - assertEqualInt((S_IFREG | 0755), archive_entry_mode(ae)); - assertEqualInt(8, archive_entry_size(ae)); - assertEqualIntA(a, 8, archive_read_data(a, buff2, 10)); - assertEqualMem(buff2, "12345678", 8); - - /* Verify the end of the archive. */ - 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_write_compress_xz.c b/libarchive/test/test_write_compress_xz.c deleted file mode 100644 index 281dbcf..0000000 --- a/libarchive/test/test_write_compress_xz.c +++ /dev/null @@ -1,257 +0,0 @@ -/*- - * Copyright (c) 2007 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 - * in this position and unchanged. - * 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: head/lib/libarchive/test/test_write_compress_xz.c 191183 2009-04-17 01:06:31Z kientzle $"); - -/* - * A basic exercise of xz reading and writing. - * - * TODO: Add a reference file and make sure we can decompress that. - */ - -DEFINE_TEST(test_write_compress_xz) -{ - struct archive_entry *ae; - struct archive* a; - char *buff, *data; - size_t buffsize, datasize; - char path[16]; - size_t used1, used2; - int i, r; - - buffsize = 2000000; - assert(NULL != (buff = (char *)malloc(buffsize))); - - datasize = 10000; - assert(NULL != (data = (char *)malloc(datasize))); - memset(data, 0, datasize); - - /* - * Write a 100 files and read them all back. - */ - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - r = archive_write_set_compression_xz(a); - if (r == ARCHIVE_FATAL) { - skipping("xz writing not supported on this platform"); - assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - return; - } - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_bytes_per_block(a, 10)); - assertEqualInt(ARCHIVE_COMPRESSION_XZ, archive_compression(a)); - assertEqualString("xz", archive_compression_name(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used1)); - assertEqualInt(ARCHIVE_COMPRESSION_XZ, archive_compression(a)); - assertEqualString("xz", archive_compression_name(a)); - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_filetype(ae, AE_IFREG); - archive_entry_set_size(ae, datasize); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - archive_entry_copy_pathname(ae, path); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - assertA(datasize - == (size_t)archive_write_data(a, data, datasize)); - } - archive_entry_free(ae); - assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - r = archive_read_support_filter_xz(a); - if (r == ARCHIVE_WARN) { - skipping("Can't verify xz writing by reading back;" - " xz reading not fully supported on this platform"); - } else { - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_filter_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, buff, used1)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - if (!assertEqualInt(ARCHIVE_OK, - archive_read_next_header(a, &ae))) - break; - assertEqualString(path, archive_entry_pathname(ae)); - assertEqualInt((int)datasize, archive_entry_size(ae)); - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - } - assertEqualInt(ARCHIVE_OK, archive_read_free(a)); - - /* - * Repeat the cycle again, this time setting some compression - * options. - */ - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_bytes_per_block(a, 10)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_xz(a)); - assertEqualIntA(a, ARCHIVE_FAILED, - archive_write_set_filter_option(a, NULL, "nonexistent-option", "0")); - assertEqualIntA(a, ARCHIVE_FAILED, - archive_write_set_filter_option(a, NULL, "compression-level", "abc")); - assertEqualIntA(a, ARCHIVE_FAILED, - archive_write_set_filter_option(a, NULL, "compression-level", "99")); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_filter_option(a, NULL, "compression-level", "9")); - assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, path); - archive_entry_set_size(ae, datasize); - archive_entry_set_filetype(ae, AE_IFREG); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - assertA(datasize == (size_t)archive_write_data(a, data, datasize)); - archive_entry_free(ae); - } - assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - - /* Curiously, this test fails; the test data above compresses - * better at default compression than at level 9. */ - /* - failure("compression-level=9 wrote %d bytes, default wrote %d bytes", - (int)used2, (int)used1); - assert(used2 < used1); - */ - - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - r = archive_read_support_filter_xz(a); - if (r == ARCHIVE_WARN) { - skipping("xz reading not fully supported on this platform"); - } else { - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_filter_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, buff, used2)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - failure("Trying to read %s", path); - if (!assertEqualIntA(a, ARCHIVE_OK, - archive_read_next_header(a, &ae))) - break; - assertEqualString(path, archive_entry_pathname(ae)); - assertEqualInt((int)datasize, archive_entry_size(ae)); - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - } - assertEqualInt(ARCHIVE_OK, archive_read_free(a)); - - /* - * Repeat again, with much lower compression. - */ - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_bytes_per_block(a, 10)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_xz(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_filter_option(a, NULL, "compression-level", "0")); - assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, path); - archive_entry_set_size(ae, datasize); - archive_entry_set_filetype(ae, AE_IFREG); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - failure("Writing file %s", path); - assertEqualIntA(a, datasize, - (size_t)archive_write_data(a, data, datasize)); - archive_entry_free(ae); - } - assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - - /* I would like to assert that compression-level=0 results in - * larger data than the default compression, but that's not true - * for all versions of liblzma. */ - /* - failure("Compression-level=0 wrote %d bytes; default wrote %d bytes", - (int)used2, (int)used1); - assert(used2 > used1); - */ - - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); - r = archive_read_support_filter_xz(a); - if (r == ARCHIVE_WARN) { - skipping("xz reading not fully supported on this platform"); - } else { - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, buff, used2)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - if (!assertEqualInt(ARCHIVE_OK, - archive_read_next_header(a, &ae))) - break; - assertEqualString(path, archive_entry_pathname(ae)); - assertEqualInt((int)datasize, archive_entry_size(ae)); - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - } - assertEqualInt(ARCHIVE_OK, archive_read_free(a)); - - /* - * Test various premature shutdown scenarios to make sure we - * don't crash or leak memory. - */ - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_xz(a)); - assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_xz(a)); - assertEqualInt(ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_xz(a)); - assertEqualInt(ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_xz(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2)); - assertEqualInt(ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - - /* - * Clean up. - */ - free(data); - free(buff); -} -- cgit v1.1 From df46367f24c4916dcd2838c094088b4f3f89ff2b Mon Sep 17 00:00:00 2001 From: delphij Date: Thu, 14 May 2015 21:33:33 +0000 Subject: Apply upstream changeset 3865cf2: Issue 394: Segfault when reading malformed old-style cpio archives Root cause here was an implicit cast that resulted in reading very large file sizes as negative numbers. --- libarchive/archive_read_support_format_cpio.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libarchive/archive_read_support_format_cpio.c b/libarchive/archive_read_support_format_cpio.c index 819f4a4..4a0452d 100644 --- a/libarchive/archive_read_support_format_cpio.c +++ b/libarchive/archive_read_support_format_cpio.c @@ -198,7 +198,7 @@ static int archive_read_format_cpio_read_data(struct archive_read *, static int archive_read_format_cpio_read_header(struct archive_read *, struct archive_entry *); static int archive_read_format_cpio_skip(struct archive_read *); -static int be4(const unsigned char *); +static int64_t be4(const unsigned char *); static int find_odc_header(struct archive_read *); static int find_newc_header(struct archive_read *); static int header_bin_be(struct archive_read *, struct cpio *, @@ -213,7 +213,7 @@ static int header_afiol(struct archive_read *, struct cpio *, struct archive_entry *, size_t *, size_t *); static int is_octal(const char *, size_t); static int is_hex(const char *, size_t); -static int le4(const unsigned char *); +static int64_t le4(const unsigned char *); static int record_hardlink(struct archive_read *a, struct cpio *cpio, struct archive_entry *entry); @@ -944,17 +944,17 @@ archive_read_format_cpio_cleanup(struct archive_read *a) return (ARCHIVE_OK); } -static int +static int64_t le4(const unsigned char *p) { - return ((p[0]<<16) + (p[1]<<24) + (p[2]<<0) + (p[3]<<8)); + return ((p[0] << 16) + (((int64_t)p[1]) << 24) + (p[2] << 0) + (p[3] << 8)); } -static int +static int64_t be4(const unsigned char *p) { - return ((p[0]<<24) + (p[1]<<16) + (p[2]<<8) + (p[3])); + return ((((int64_t)p[0]) << 24) + (p[1] << 16) + (p[2] << 8) + (p[3])); } /* -- cgit v1.1 From 46925f0dc8a5f586b97ca7d31b409d369b8dcf2d Mon Sep 17 00:00:00 2001 From: delphij Date: Thu, 14 May 2015 21:34:20 +0000 Subject: Apply upstream changeset e6c9668: Add a check to archive_read_filter_consume to reject any attempts to move the file pointer by a negative amount. Note: Either this or commit 3865cf2 provides a fix for Issue 394. --- libarchive/archive_read.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libarchive/archive_read.c b/libarchive/archive_read.c index 048c316..7f3edc1 100644 --- a/libarchive/archive_read.c +++ b/libarchive/archive_read.c @@ -1394,6 +1394,8 @@ __archive_read_filter_consume(struct archive_read_filter * filter, { int64_t skipped; + if (request < 0) + return ARCHIVE_FATAL; if (request == 0) return 0; -- cgit v1.1 From 0830fa02bc6016f13679f49681e2e311aa22f2a1 Mon Sep 17 00:00:00 2001 From: delphij Date: Thu, 14 May 2015 21:39:03 +0000 Subject: Apply upstream changeset 24f5de6: Set a proper error message if we hit end-of-file when trying to read a cpio header. Suggested by Issue #395, although the actual problem there seems to have been the same as Issue #394. --- libarchive/archive_read_support_format_cpio.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libarchive/archive_read_support_format_cpio.c b/libarchive/archive_read_support_format_cpio.c index 4a0452d..1dabc47 100644 --- a/libarchive/archive_read_support_format_cpio.c +++ b/libarchive/archive_read_support_format_cpio.c @@ -864,8 +864,11 @@ header_bin_le(struct archive_read *a, struct cpio *cpio, /* Read fixed-size portion of header. */ h = __archive_read_ahead(a, bin_header_size, NULL); - if (h == NULL) + if (h == NULL) { + archive_set_error(&a->archive, 0, + "End of file trying to read next cpio header"); return (ARCHIVE_FATAL); + } /* Parse out binary fields. */ header = (const unsigned char *)h; @@ -900,8 +903,11 @@ header_bin_be(struct archive_read *a, struct cpio *cpio, /* Read fixed-size portion of header. */ h = __archive_read_ahead(a, bin_header_size, NULL); - if (h == NULL) + if (h == NULL) { + archive_set_error(&a->archive, 0, + "End of file trying to read next cpio header"); return (ARCHIVE_FATAL); + } /* Parse out binary fields. */ header = (const unsigned char *)h; -- cgit v1.1 From 8aa4f29361bd9cd8e289f7a6d2a812e9e102d932 Mon Sep 17 00:00:00 2001 From: bdrewery Date: Tue, 28 Jul 2015 17:20:35 +0000 Subject: Apply upstream changeset fa9e61: Fix --one-file-system to include the directory encountered rather than excluding it. --- libarchive/archive_read_disk_posix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libarchive/archive_read_disk_posix.c b/libarchive/archive_read_disk_posix.c index a13dbbf..1787d86 100644 --- a/libarchive/archive_read_disk_posix.c +++ b/libarchive/archive_read_disk_posix.c @@ -974,7 +974,7 @@ next_entry(struct archive_read_disk *a, struct tree *t, t->initial_filesystem_id = t->current_filesystem_id; if (!a->traverse_mount_points) { if (t->initial_filesystem_id != t->current_filesystem_id) - return (ARCHIVE_RETRY); + descend = 0; } t->descend = descend; -- cgit v1.1 From 286a87565ae815374f0cc56973d9f0393b2bd12b Mon Sep 17 00:00:00 2001 From: bdrewery Date: Tue, 28 Jul 2015 17:48:34 +0000 Subject: Apply upstream changeset bf4f6ec64e: Fix issue 356: properly skip a sparse file entry in a tar file. --- Makefile.am | 2 + libarchive/archive_read_support_format_tar.c | 16 ++- libarchive/test/CMakeLists.txt | 1 + .../test/test_read_format_gtar_sparse_skip_entry.c | 119 +++++++++++++++++++++ ...est_read_format_gtar_sparse_skip_entry.tar.Z.uu | 15 +++ 5 files changed, 150 insertions(+), 3 deletions(-) create mode 100644 libarchive/test/test_read_format_gtar_sparse_skip_entry.c create mode 100644 libarchive/test/test_read_format_gtar_sparse_skip_entry.tar.Z.uu diff --git a/Makefile.am b/Makefile.am index 3fa2d22..9e22a9b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -395,6 +395,7 @@ libarchive_test_SOURCES= \ libarchive/test/test_read_format_gtar_gz.c \ libarchive/test/test_read_format_gtar_lzma.c \ libarchive/test/test_read_format_gtar_sparse.c \ + libarchive/test/test_read_format_gtar_sparse_skip_entry.c \ libarchive/test/test_read_format_iso_Z.c \ libarchive/test/test_read_format_iso_multi_extent.c \ libarchive/test/test_read_format_iso_xorriso.c \ @@ -622,6 +623,7 @@ libarchive_test_EXTRA_DIST=\ libarchive/test/test_read_format_gtar_sparse_1_17_posix01.tar.uu \ libarchive/test/test_read_format_gtar_sparse_1_17_posix10.tar.uu \ libarchive/test/test_read_format_gtar_sparse_1_17_posix10_modified.tar.uu \ + libarchive/test/test_read_format_gtar_sparse_skip_entry.tar.Z.uu \ libarchive/test/test_read_format_iso.iso.Z.uu \ libarchive/test/test_read_format_iso_2.iso.Z.uu \ libarchive/test/test_read_format_iso_joliet.iso.Z.uu \ diff --git a/libarchive/archive_read_support_format_tar.c b/libarchive/archive_read_support_format_tar.c index e9523cb..c6f405d 100644 --- a/libarchive/archive_read_support_format_tar.c +++ b/libarchive/archive_read_support_format_tar.c @@ -585,13 +585,23 @@ static int archive_read_format_tar_skip(struct archive_read *a) { int64_t bytes_skipped; + int64_t request; + struct sparse_block *p; struct tar* tar; tar = (struct tar *)(a->format->data); - bytes_skipped = __archive_read_consume(a, - tar->entry_bytes_remaining + tar->entry_padding + - tar->entry_bytes_unconsumed); + /* Do not consume the hole of a sparse file. */ + request = 0; + for (p = tar->sparse_list; p != NULL; p = p->next) { + if (!p->hole) + request += p->remaining; + } + if (request > tar->entry_bytes_remaining) + request = tar->entry_bytes_remaining; + request += tar->entry_padding + tar->entry_bytes_unconsumed; + + bytes_skipped = __archive_read_consume(a, request); if (bytes_skipped < 0) return (ARCHIVE_FATAL); diff --git a/libarchive/test/CMakeLists.txt b/libarchive/test/CMakeLists.txt index d2eb2c2..ff73c77 100644 --- a/libarchive/test/CMakeLists.txt +++ b/libarchive/test/CMakeLists.txt @@ -110,6 +110,7 @@ IF(ENABLE_TEST) test_read_format_gtar_gz.c test_read_format_gtar_lzma.c test_read_format_gtar_sparse.c + test_read_format_gtar_sparse_skip_entry.c test_read_format_iso_Z.c test_read_format_iso_multi_extent.c test_read_format_iso_xorriso.c diff --git a/libarchive/test/test_read_format_gtar_sparse_skip_entry.c b/libarchive/test/test_read_format_gtar_sparse_skip_entry.c new file mode 100644 index 0000000..813315b --- /dev/null +++ b/libarchive/test/test_read_format_gtar_sparse_skip_entry.c @@ -0,0 +1,119 @@ +/*- + * Copyright (c) 2014 Michihiro NAKAJIMA + * 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"); + +/* + * To test skip a sparse file entry, this test does not read file data. + */ +DEFINE_TEST(test_read_format_gtar_sparse_skip_entry) +{ + const char *refname = "test_read_format_gtar_sparse_skip_entry.tar.Z.uu"; + struct archive *a; + struct archive_entry *ae; + const void *p; + size_t s; + int64_t o; + + copy_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 first file. */ + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualString("a", archive_entry_pathname(ae)); + assertEqualInt(10737418244, 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 second file. */ + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualString("b", 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_PAX_INTERCHANGE, + archive_format(a)); + + /* Close the archive. */ + assertEqualInt(ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_free(a)); + + + /* + * Read just one block of a sparse file and skip it. + */ + 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 first file. */ + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualString("a", archive_entry_pathname(ae)); + assertEqualInt(10737418244, archive_entry_size(ae)); + assertEqualInt(archive_entry_is_encrypted(ae), 0); + assertEqualIntA(a, archive_read_has_encrypted_entries(a), + ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED); + assertEqualInt(0, archive_read_data_block(a, &p, &s, &o)); + assertEqualInt(4096, s); + assertEqualInt(0, o); + + + /* Verify regular second file. */ + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualString("b", 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_PAX_INTERCHANGE, + archive_format(a)); + + /* Close the archive. */ + assertEqualInt(ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_free(a)); +} + diff --git a/libarchive/test/test_read_format_gtar_sparse_skip_entry.tar.Z.uu b/libarchive/test/test_read_format_gtar_sparse_skip_entry.tar.Z.uu new file mode 100644 index 0000000..dc0daae --- /dev/null +++ b/libarchive/test/test_read_format_gtar_sparse_skip_entry.tar.Z.uu @@ -0,0 +1,15 @@ +begin 644 - +M'YV04,+@05(F#)DRBD:;,V!@T8-6)NE&'#10T<-#;>R(%CAEV28_3R9?LW\(P8-F[`<#%C +M)@T<->#6>`PBC.2^E07;J#'#Q>J-F5DJ<`GBB),J+N;`<3JGC(LV8=2\D<-V +M]DO;N'7S]MTFC9OA/6#,CE'[=N[=$V +M9]RY=212"9YD1EOO*&`DE!&*>645%9IY9589JGE +MEEQVZ>678(8IYIADEFGFF6BFJ>::;+;IYIMPQBGGG'36:>>=>.:IYYY\]NGG +MGX`&*NB@A!9JJ)YB](D@1PZ>U&B#*468484RT11###7<8!8(&-)4PX=^DN@4 +B5%*E6.J*746JTHN'2LFDDZW&*NNLM-9JZZVXYJKKKKR&!0`` +` +end -- cgit v1.1