Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 10 Sep 2021 08:29:35 GMT
From:      Martin Matuska <mm@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: aef1ff87fe88 - stable/13 - libarchive: import changes from upstream
Message-ID:  <202109100829.18A8TZxA073016@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by mm:

URL: https://cgit.FreeBSD.org/src/commit/?id=aef1ff87fe88b95e24cce0bb20b4ea87d801b070

commit aef1ff87fe88b95e24cce0bb20b4ea87d801b070
Author:     Martin Matuska <mm@FreeBSD.org>
AuthorDate: 2021-08-23 00:54:15 +0000
Commit:     Martin Matuska <mm@FreeBSD.org>
CommitDate: 2021-09-10 08:24:13 +0000

    libarchive: import changes from upstream
    
    Libarchive 3.5.2
    
    New features:
      PR #1502: Support for PWB and v7 binary cpio formats
      PR #1509: Support of deflate algorithm in symbolic link decompression
                for ZIP archives
    
    Important bugfixes:
      IS #1044: fix extraction of hardlinks to symlinks
      PR #1480: Fix truncation of size values during 7zip archive
                extraction on 32bit architectures
      PR #1504: fix rar header skiming
      PR #1514: ZIP excessive disk read - fix location of central directory
      PR #1520: fix double-free in CAB reader
      PR #1521: Fixed leak of rar before ending with error
      PR #1530: Handle short writes from archive_write_callback
      PR #1532: 7zip: Use compression settings from file also for file header
      IS #1566: do not follow symlinks when processing the fixup list
    
    Relnotes:       yes
    
    (cherry picked from commit ddce862ad8594542e1fa1af9ffae7264e12ffd27)
---
 contrib/libarchive/NEWS                            |   2 +
 contrib/libarchive/README.md                       |   3 +
 contrib/libarchive/cat/bsdcat_platform.h           |   2 +-
 contrib/libarchive/cpio/bsdcpio.1                  |   7 +
 contrib/libarchive/cpio/cmdline.c                  |   4 +-
 contrib/libarchive/cpio/cpio.c                     |  23 +-
 contrib/libarchive/cpio/cpio.h                     |   1 +
 contrib/libarchive/cpio/test/test_basic.c          |   2 +
 contrib/libarchive/libarchive/archive.h            |   8 +-
 .../libarchive/archive_disk_acl_freebsd.c          |  20 +-
 contrib/libarchive/libarchive/archive_entry.h      |   2 +-
 contrib/libarchive/libarchive/archive_pathmatch.c  |   4 +
 contrib/libarchive/libarchive/archive_private.h    |   7 +
 contrib/libarchive/libarchive/archive_random.c     |   8 +-
 .../libarchive/archive_read_disk_posix.c           |  66 ++-
 .../libarchive/libarchive/archive_read_extract2.c  |   2 +-
 .../libarchive/archive_read_set_options.3          |   9 +
 .../libarchive/archive_read_support_filter_rpm.c   |   2 +-
 .../libarchive/archive_read_support_filter_uu.c    |   2 +-
 .../libarchive/archive_read_support_format_7zip.c  |  14 +-
 .../libarchive/archive_read_support_format_cab.c   |   1 -
 .../libarchive/archive_read_support_format_cpio.c  |  18 +
 .../libarchive/archive_read_support_format_mtree.c |   8 +-
 .../libarchive/archive_read_support_format_rar.c   |  14 +-
 .../libarchive/archive_read_support_format_rar5.c  |   1 +
 .../libarchive/archive_read_support_format_tar.c   |   6 +-
 .../libarchive/archive_read_support_format_zip.c   | 154 ++----
 .../libarchive/archive_version_details.c           |   2 +-
 contrib/libarchive/libarchive/archive_write.c      |  23 +-
 .../libarchive/archive_write_disk_posix.c          |  63 ++-
 .../libarchive/libarchive/archive_write_format.3   |  18 +-
 .../libarchive/archive_write_set_format.c          |   4 +-
 .../libarchive/archive_write_set_format_7zip.c     |   7 +-
 .../libarchive/archive_write_set_format_by_name.c  |   4 +-
 .../libarchive/archive_write_set_format_cpio.c     | 494 +----------------
 .../archive_write_set_format_cpio_binary.c         | 610 +++++++++++++++++++++
 .../libarchive/archive_write_set_format_cpio_odc.c | 500 +++++++++++++++++
 .../archive_write_set_format_filter_by_ext.c       |   2 +-
 .../libarchive/archive_write_set_options.3         |  14 +-
 contrib/libarchive/libarchive/cpio.5               | 200 ++++---
 contrib/libarchive/libarchive/libarchive-formats.5 |  37 +-
 contrib/libarchive/libarchive/libarchive.3         |   2 +-
 .../libarchive/test/test_archive_pathmatch.c       |   4 +
 .../libarchive/libarchive/test/test_compat_lzma.c  |   2 +-
 .../test/test_read_disk_directory_traversals.c     |  13 +-
 .../libarchive/test/test_read_format_zip.c         |  27 +
 .../test/test_read_format_zip_7z_deflate.zip.uu    | 361 ++++++++++++
 .../libarchive/libarchive/test/test_short_writes.c | 216 ++++++++
 .../libarchive/libarchive/test/test_sparse_basic.c |   4 +-
 .../libarchive/test/test_write_disk_appledouble.c  |   8 +-
 .../libarchive/test/test_write_disk_fixup.c        |  81 +++
 .../libarchive/test/test_write_disk_hardlink.c     |  49 +-
 .../test/test_write_disk_hfs_compression.c         |   8 +-
 .../libarchive/test/test_write_disk_mac_metadata.c |   8 +-
 .../test/test_write_disk_no_hfs_compression.c      |   8 +-
 .../libarchive/test/test_write_format_cpio.c       |  16 +-
 .../libarchive/test/test_write_format_cpio_empty.c |   2 +-
 .../libarchive/test/test_write_format_cpio_odc.c   |   2 +-
 .../test/test_write_format_zip_compression_store.c |   2 +-
 .../test/test_write_format_zip_empty_zip64.c       |   2 +-
 .../libarchive/test/test_write_format_zip_file.c   |   2 +-
 .../test/test_write_format_zip_file_zip64.c        |   2 +-
 .../libarchive/test/test_write_read_format_zip.c   |   2 +-
 contrib/libarchive/libarchive/xxhash.c             |   6 +-
 .../libarchive/tar/test/test_option_safe_writes.c  |   2 +-
 contrib/libarchive/test_utils/test_main.c          |   4 +-
 lib/libarchive/Makefile                            |   2 +
 lib/libarchive/config_freebsd.h                    |   1 +
 lib/libarchive/tests/Makefile                      |   3 +
 69 files changed, 2401 insertions(+), 806 deletions(-)

diff --git a/contrib/libarchive/NEWS b/contrib/libarchive/NEWS
index 47cebdd4b9b7..096410620d6b 100644
--- a/contrib/libarchive/NEWS
+++ b/contrib/libarchive/NEWS
@@ -1,3 +1,5 @@
+Aug 22, 2021: libarchive 3.5.2 released
+
 Dec 26, 2020: libarchive 3.5.1 released
 
 Dec 01, 2020: libarchive 3.5.0 released
diff --git a/contrib/libarchive/README.md b/contrib/libarchive/README.md
index 56cd723daa47..d5ef70c2191d 100644
--- a/contrib/libarchive/README.md
+++ b/contrib/libarchive/README.md
@@ -79,6 +79,7 @@ Currently, the library automatically detects and reads the following formats:
   * POSIX octet-oriented cpio
   * SVR4 ASCII cpio
   * Binary cpio (big-endian or little-endian)
+  * PWB binary cpio
   * ISO9660 CD-ROM images (with optional Rockridge or Joliet extensions)
   * ZIP archives (with uncompressed or "deflate" compressed entries, including support for encrypted Zip archives)
   * ZIPX archives (with support for bzip2, ppmd8, lzma and xz compressed entries)
@@ -110,6 +111,8 @@ The library can create archives in any of the following formats:
   * Old V7 tar format
   * POSIX octet-oriented cpio
   * SVR4 "newc" cpio
+  * Binary cpio (little-endian)
+  * PWB binary cpio
   * shar archives
   * ZIP archives (with uncompressed or "deflate" compressed entries)
   * GNU and BSD 'ar' archives
diff --git a/contrib/libarchive/cat/bsdcat_platform.h b/contrib/libarchive/cat/bsdcat_platform.h
index ff9245e84811..10b711322c37 100644
--- a/contrib/libarchive/cat/bsdcat_platform.h
+++ b/contrib/libarchive/cat/bsdcat_platform.h
@@ -22,7 +22,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: src/usr.bin/tar/bsdtar_platform.h,v 1.26 2008/12/06 07:37:14 kientzle Exp $
  */
 
 /*
diff --git a/contrib/libarchive/cpio/bsdcpio.1 b/contrib/libarchive/cpio/bsdcpio.1
index 514c1a2c1937..01b508e122f8 100644
--- a/contrib/libarchive/cpio/bsdcpio.1
+++ b/contrib/libarchive/cpio/bsdcpio.1
@@ -82,6 +82,13 @@ all operating modes.
 .It Fl 0 , Fl Fl null
 Read filenames separated by NUL characters instead of newlines.
 This is necessary if any of the filenames being read might contain newlines.
+.It Fl 6 , Fl Fl pwb
+When reading a binary format archive, assume it's the earlier one,
+from the PWB variant of 6th Edition UNIX.
+When writing a cpio archive, use the PWB format.
+.It Fl 7 , Fl Fl binary
+(o mode only)
+When writing a cpio archive, use the (newer, non-PWB) binary format.
 .It Fl A
 (o mode only)
 Append to the specified archive.
diff --git a/contrib/libarchive/cpio/cmdline.c b/contrib/libarchive/cpio/cmdline.c
index 830caf659a07..3d5a0ecad7f7 100644
--- a/contrib/libarchive/cpio/cmdline.c
+++ b/contrib/libarchive/cpio/cmdline.c
@@ -51,7 +51,7 @@ __FBSDID("$FreeBSD$");
 /*
  * Short options for cpio.  Please keep this sorted.
  */
-static const char *short_options = "0AaBC:cdE:F:f:H:hI:iJjLlmnO:opR:rtuVvW:yZz";
+static const char *short_options = "067AaBC:cdE:F:f:H:hI:iJjLlmnO:opR:rtuVvW:yZz";
 
 /*
  * Long options for cpio.  Please keep this sorted.
@@ -62,6 +62,7 @@ static const struct option {
 	int equivalent;	/* Equivalent short option. */
 } cpio_longopts[] = {
 	{ "b64encode",			0, OPTION_B64ENCODE },
+	{ "binary",			0, '7' },
 	{ "create",			0, 'o' },
 	{ "dereference",		0, 'L' },
 	{ "dot",			0, 'V' },
@@ -86,6 +87,7 @@ static const struct option {
 	{ "pass-through",		0, 'p' },
 	{ "preserve-modification-time", 0, 'm' },
 	{ "preserve-owner",		0, OPTION_PRESERVE_OWNER },
+	{ "pwb",			0, '6' },
 	{ "quiet",			0, OPTION_QUIET },
 	{ "unconditional",		0, 'u' },
 	{ "uuencode",			0, OPTION_UUENCODE },
diff --git a/contrib/libarchive/cpio/cpio.c b/contrib/libarchive/cpio/cpio.c
index 3d5a6a837407..847c92d31449 100644
--- a/contrib/libarchive/cpio/cpio.c
+++ b/contrib/libarchive/cpio/cpio.c
@@ -192,6 +192,12 @@ main(int argc, char *argv[])
 		case '0': /* GNU convention: --null, -0 */
 			cpio->option_null = 1;
 			break;
+		case '6': /* in/out: assume/create 6th edition (PWB) format */
+			cpio->option_pwb = 1;
+			break;
+		case '7': /* out: create archive using 7th Edition binary format */
+			cpio->format = "bin";
+			break;
 		case 'A': /* NetBSD/OpenBSD */
 			cpio->option_append = 1;
 			break;
@@ -400,11 +406,12 @@ main(int argc, char *argv[])
 
 	switch (cpio->mode) {
 	case 'o':
-		/* TODO: Implement old binary format in libarchive,
-		   use that here. */
-		if (cpio->format == NULL)
-			cpio->format = "odc"; /* Default format */
-
+		if (cpio->format == NULL) {
+			if (cpio->option_pwb)
+				cpio->format = "pwb";
+			else
+				cpio->format = "cpio";
+		}
 		mode_out(cpio);
 		break;
 	case 'i':
@@ -462,7 +469,7 @@ static const char *long_help_msg =
 	"  -v Verbose filenames     -V  one dot per file\n"
 	"Create: %p -o [options]  < [list of files] > [archive]\n"
 	"  -J,-y,-z,--lzma  Compress archive with xz/bzip2/gzip/lzma\n"
-	"  --format {odc|newc|ustar}  Select archive format\n"
+	"  --format {pwb|bin|odc|newc|ustar}  Select archive format\n"
 	"List: %p -it < [archive]\n"
 	"Extract: %p -i [options] < [archive]\n";
 
@@ -970,6 +977,8 @@ mode_in(struct cpio *cpio)
 		lafe_errc(1, 0, "Couldn't allocate archive object");
 	archive_read_support_filter_all(a);
 	archive_read_support_format_all(a);
+	if (cpio->option_pwb)
+		archive_read_set_options(a, "pwb");
 	if (cpio->passphrase != NULL)
 		r = archive_read_add_passphrase(a, cpio->passphrase);
 	else
@@ -1080,6 +1089,8 @@ mode_list(struct cpio *cpio)
 		lafe_errc(1, 0, "Couldn't allocate archive object");
 	archive_read_support_filter_all(a);
 	archive_read_support_format_all(a);
+	if (cpio->option_pwb)
+		archive_read_set_options(a, "pwb");
 	if (cpio->passphrase != NULL)
 		r = archive_read_add_passphrase(a, cpio->passphrase);
 	else
diff --git a/contrib/libarchive/cpio/cpio.h b/contrib/libarchive/cpio/cpio.h
index cd789b580f8e..6ab55e474c81 100644
--- a/contrib/libarchive/cpio/cpio.h
+++ b/contrib/libarchive/cpio/cpio.h
@@ -62,6 +62,7 @@ struct cpio {
 	int		  option_list; /* -t */
 	char		  option_null; /* --null */
 	int		  option_numeric_uid_gid; /* -n */
+	int		  option_pwb; /* -6 */
 	int		  option_rename; /* -r */
 	char		 *destdir;
 	size_t		  destdir_len;
diff --git a/contrib/libarchive/cpio/test/test_basic.c b/contrib/libarchive/cpio/test/test_basic.c
index 9a23399aa7cb..3662b529e235 100644
--- a/contrib/libarchive/cpio/test/test_basic.c
+++ b/contrib/libarchive/cpio/test/test_basic.c
@@ -230,6 +230,8 @@ DEFINE_TEST(test_basic)
 	basic_cpio("copy_odc", "--format=odc", "", msg, msg);
 	basic_cpio("copy_newc", "-H newc", "", result, "2 blocks\n");
 	basic_cpio("copy_cpio", "-H odc", "", msg, msg);
+	msg = "1 block\n";
+	basic_cpio("copy_bin", "-H bin", "", msg, msg);
 	msg = canSymlink() ? "9 blocks\n" : "8 blocks\n";
 	basic_cpio("copy_ustar", "-H ustar", "", msg, msg);
 
diff --git a/contrib/libarchive/libarchive/archive.h b/contrib/libarchive/libarchive/archive.h
index 55f0fad15730..a44da908ad90 100644
--- a/contrib/libarchive/libarchive/archive.h
+++ b/contrib/libarchive/libarchive/archive.h
@@ -36,7 +36,7 @@
  * assert that ARCHIVE_VERSION_NUMBER >= 2012108.
  */
 /* Note: Compiler will complain if this does not match archive_entry.h! */
-#define	ARCHIVE_VERSION_NUMBER 3005001
+#define	ARCHIVE_VERSION_NUMBER 3005002
 
 #include <sys/stat.h>
 #include <stddef.h>  /* for wchar_t */
@@ -155,7 +155,7 @@ __LA_DECL int		archive_version_number(void);
 /*
  * Textual name/version of the library, useful for version displays.
  */
-#define	ARCHIVE_VERSION_ONLY_STRING "3.5.1"
+#define	ARCHIVE_VERSION_ONLY_STRING "3.5.2"
 #define	ARCHIVE_VERSION_STRING "libarchive " ARCHIVE_VERSION_ONLY_STRING
 __LA_DECL const char *	archive_version_string(void);
 
@@ -319,6 +319,7 @@ typedef const char *archive_passphrase_callback(struct archive *,
 #define	ARCHIVE_FORMAT_CPIO_SVR4_NOCRC		(ARCHIVE_FORMAT_CPIO | 4)
 #define	ARCHIVE_FORMAT_CPIO_SVR4_CRC		(ARCHIVE_FORMAT_CPIO | 5)
 #define	ARCHIVE_FORMAT_CPIO_AFIO_LARGE		(ARCHIVE_FORMAT_CPIO | 6)
+#define	ARCHIVE_FORMAT_CPIO_PWB			(ARCHIVE_FORMAT_CPIO | 7)
 #define	ARCHIVE_FORMAT_SHAR			0x20000
 #define	ARCHIVE_FORMAT_SHAR_BASE		(ARCHIVE_FORMAT_SHAR | 1)
 #define	ARCHIVE_FORMAT_SHAR_DUMP		(ARCHIVE_FORMAT_SHAR | 2)
@@ -800,7 +801,10 @@ __LA_DECL int archive_write_set_format_7zip(struct archive *);
 __LA_DECL int archive_write_set_format_ar_bsd(struct archive *);
 __LA_DECL int archive_write_set_format_ar_svr4(struct archive *);
 __LA_DECL int archive_write_set_format_cpio(struct archive *);
+__LA_DECL int archive_write_set_format_cpio_bin(struct archive *);
 __LA_DECL int archive_write_set_format_cpio_newc(struct archive *);
+__LA_DECL int archive_write_set_format_cpio_odc(struct archive *);
+__LA_DECL int archive_write_set_format_cpio_pwb(struct archive *);
 __LA_DECL int archive_write_set_format_gnutar(struct archive *);
 __LA_DECL int archive_write_set_format_iso9660(struct archive *);
 __LA_DECL int archive_write_set_format_mtree(struct archive *);
diff --git a/contrib/libarchive/libarchive/archive_disk_acl_freebsd.c b/contrib/libarchive/libarchive/archive_disk_acl_freebsd.c
index aba41e5dabb5..ed4e7a7896a9 100644
--- a/contrib/libarchive/libarchive/archive_disk_acl_freebsd.c
+++ b/contrib/libarchive/libarchive/archive_disk_acl_freebsd.c
@@ -319,7 +319,7 @@ translate_acl(struct archive_read_disk *a,
 
 static int
 set_acl(struct archive *a, int fd, const char *name,
-    struct archive_acl *abstract_acl,
+    struct archive_acl *abstract_acl, __LA_MODE_T mode,
     int ae_requested_type, const char *tname)
 {
 	int		 acl_type = 0;
@@ -364,6 +364,13 @@ set_acl(struct archive *a, int fd, const char *name,
 		return (ARCHIVE_FAILED);
 	}
 
+	if (acl_type == ACL_TYPE_DEFAULT && !S_ISDIR(mode)) {
+		errno = EINVAL;
+		archive_set_error(a, errno,
+		    "Cannot set default ACL on non-directory");
+		return (ARCHIVE_WARN);
+	}
+
 	acl = acl_init(entries);
 	if (acl == (acl_t)NULL) {
 		archive_set_error(a, errno,
@@ -542,7 +549,10 @@ set_acl(struct archive *a, int fd, const char *name,
 	else if (acl_set_link_np(name, acl_type, acl) != 0)
 #else
 	/* FreeBSD older than 8.0 */
-	else if (acl_set_file(name, acl_type, acl) != 0)
+	else if (S_ISLNK(mode)) {
+	    /* acl_set_file() follows symbolic links, skip */
+	    ret = ARCHIVE_OK;
+	} else if (acl_set_file(name, acl_type, acl) != 0)
 #endif
 	{
 		if (errno == EOPNOTSUPP) {
@@ -677,14 +687,14 @@ archive_write_disk_set_acls(struct archive *a, int fd, const char *name,
 	    & ARCHIVE_ENTRY_ACL_TYPE_POSIX1E) != 0) {
 		if ((archive_acl_types(abstract_acl)
 		    & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) != 0) {
-			ret = set_acl(a, fd, name, abstract_acl,
+			ret = set_acl(a, fd, name, abstract_acl, mode,
 			    ARCHIVE_ENTRY_ACL_TYPE_ACCESS, "access");
 			if (ret != ARCHIVE_OK)
 				return (ret);
 		}
 		if ((archive_acl_types(abstract_acl)
 		    & ARCHIVE_ENTRY_ACL_TYPE_DEFAULT) != 0)
-			ret = set_acl(a, fd, name, abstract_acl,
+			ret = set_acl(a, fd, name, abstract_acl, mode,
 			    ARCHIVE_ENTRY_ACL_TYPE_DEFAULT, "default");
 
 		/* Simultaneous POSIX.1e and NFSv4 is not supported */
@@ -693,7 +703,7 @@ archive_write_disk_set_acls(struct archive *a, int fd, const char *name,
 #if ARCHIVE_ACL_FREEBSD_NFS4
 	else if ((archive_acl_types(abstract_acl) &
 	    ARCHIVE_ENTRY_ACL_TYPE_NFS4) != 0) {
-		ret = set_acl(a, fd, name, abstract_acl,
+		ret = set_acl(a, fd, name, abstract_acl, mode,
 		    ARCHIVE_ENTRY_ACL_TYPE_NFS4, "nfs4");
 	}
 #endif
diff --git a/contrib/libarchive/libarchive/archive_entry.h b/contrib/libarchive/libarchive/archive_entry.h
index a1b9fe43fe22..90372b4d8f90 100644
--- a/contrib/libarchive/libarchive/archive_entry.h
+++ b/contrib/libarchive/libarchive/archive_entry.h
@@ -30,7 +30,7 @@
 #define	ARCHIVE_ENTRY_H_INCLUDED
 
 /* Note: Compiler will complain if this does not match archive.h! */
-#define	ARCHIVE_VERSION_NUMBER 3005001
+#define	ARCHIVE_VERSION_NUMBER 3005002
 
 /*
  * Note: archive_entry.h is for use outside of libarchive; the
diff --git a/contrib/libarchive/libarchive/archive_pathmatch.c b/contrib/libarchive/libarchive/archive_pathmatch.c
index 619e2b622a3c..0867a268eefe 100644
--- a/contrib/libarchive/libarchive/archive_pathmatch.c
+++ b/contrib/libarchive/libarchive/archive_pathmatch.c
@@ -384,6 +384,8 @@ __archive_pathmatch(const char *p, const char *s, int flags)
 	/* Empty pattern only matches the empty string. */
 	if (p == NULL || *p == '\0')
 		return (s == NULL || *s == '\0');
+	else if (s == NULL)
+		return (0);
 
 	/* Leading '^' anchors the start of the pattern. */
 	if (*p == '^') {
@@ -424,6 +426,8 @@ __archive_pathmatch_w(const wchar_t *p, const wchar_t *s, int flags)
 	/* Empty pattern only matches the empty string. */
 	if (p == NULL || *p == L'\0')
 		return (s == NULL || *s == L'\0');
+	else if (s == NULL)
+		return (0);
 
 	/* Leading '^' anchors the start of the pattern. */
 	if (*p == L'^') {
diff --git a/contrib/libarchive/libarchive/archive_private.h b/contrib/libarchive/libarchive/archive_private.h
index 154d1c2928b9..1b769e8452dc 100644
--- a/contrib/libarchive/libarchive/archive_private.h
+++ b/contrib/libarchive/libarchive/archive_private.h
@@ -46,6 +46,13 @@
 #define	__LA_DEAD
 #endif
 
+#if defined(__GNUC__) && (__GNUC__ > 2 || \
+			  (__GNUC__ == 2 && __GNUC_MINOR__ >= 7))
+#define	__LA_UNUSED	__attribute__((__unused__))
+#else
+#define	__LA_UNUSED
+#endif
+
 #define	ARCHIVE_WRITE_MAGIC	(0xb0c5c0deU)
 #define	ARCHIVE_READ_MAGIC	(0xdeb0c5U)
 #define	ARCHIVE_WRITE_DISK_MAGIC (0xc001b0c5U)
diff --git a/contrib/libarchive/libarchive/archive_random.c b/contrib/libarchive/libarchive/archive_random.c
index 65ea6915768d..9d1aa493f0c8 100644
--- a/contrib/libarchive/libarchive/archive_random.c
+++ b/contrib/libarchive/libarchive/archive_random.c
@@ -173,7 +173,7 @@ arc4_init(void)
 }
 
 static inline void
-arc4_addrandom(u_char *dat, int datlen)
+arc4_addrandom(uint8_t *dat, int datlen)
 {
 	int     n;
 	uint8_t si;
@@ -196,7 +196,7 @@ arc4_stir(void)
 	struct {
 		struct timeval	tv;
 		pid_t		pid;
-		u_char	 	rnd[KEYSIZE];
+		uint8_t		rnd[KEYSIZE];
 	} rdat;
 
 	if (!rs_initialized) {
@@ -216,7 +216,7 @@ arc4_stir(void)
 		/* We'll just take whatever was on the stack too... */
 	}
 
-	arc4_addrandom((u_char *)&rdat, KEYSIZE);
+	arc4_addrandom((uint8_t *)&rdat, KEYSIZE);
 
 	/*
 	 * Discard early keystream, as per recommendations in:
@@ -258,7 +258,7 @@ arc4_getbyte(void)
 static void
 arc4random_buf(void *_buf, size_t n)
 {
-	u_char *buf = (u_char *)_buf;
+	uint8_t *buf = (uint8_t *)_buf;
 	_ARC4_LOCK();
 	arc4_stir_if_needed();
 	while (n--) {
diff --git a/contrib/libarchive/libarchive/archive_read_disk_posix.c b/contrib/libarchive/libarchive/archive_read_disk_posix.c
index 2898206951d5..3ee6269ff3ce 100644
--- a/contrib/libarchive/libarchive/archive_read_disk_posix.c
+++ b/contrib/libarchive/libarchive/archive_read_disk_posix.c
@@ -1522,8 +1522,40 @@ get_xfer_size(struct tree *t, int fd, const char *path)
 }
 #endif
 
-#if defined(HAVE_STATFS) && defined(HAVE_FSTATFS) && defined(MNT_LOCAL) \
-	&& !defined(ST_LOCAL)
+#if defined(HAVE_STATVFS)
+static inline __LA_UNUSED void
+set_statvfs_transfer_size(struct filesystem *fs, const struct statvfs *sfs)
+{
+	fs->xfer_align = sfs->f_frsize > 0 ? (long)sfs->f_frsize : -1;
+	fs->max_xfer_size = -1;
+#if defined(HAVE_STRUCT_STATVFS_F_IOSIZE)
+	fs->min_xfer_size = sfs->f_iosize > 0 ? (long)sfs->f_iosize : -1;
+	fs->incr_xfer_size = sfs->f_iosize > 0 ? (long)sfs->f_iosize : -1;
+#else
+	fs->min_xfer_size = sfs->f_bsize > 0 ? (long)sfs->f_bsize : -1;
+	fs->incr_xfer_size = sfs->f_bsize > 0 ? (long)sfs->f_bsize : -1;
+#endif
+}
+#endif
+
+#if defined(HAVE_STRUCT_STATFS)
+static inline __LA_UNUSED void
+set_statfs_transfer_size(struct filesystem *fs, const struct statfs *sfs)
+{
+	fs->xfer_align = sfs->f_bsize > 0 ? (long)sfs->f_bsize : -1;
+	fs->max_xfer_size = -1;
+#if defined(HAVE_STRUCT_STATFS_F_IOSIZE)
+	fs->min_xfer_size = sfs->f_iosize > 0 ? (long)sfs->f_iosize : -1;
+	fs->incr_xfer_size = sfs->f_iosize > 0 ? (long)sfs->f_iosize : -1;
+#else
+	fs->min_xfer_size = sfs->f_bsize > 0 ? (long)sfs->f_bsize : -1;
+	fs->incr_xfer_size = sfs->f_bsize > 0 ? (long)sfs->f_bsize : -1;
+#endif
+}
+#endif
+
+#if defined(HAVE_STRUCT_STATFS) && defined(HAVE_STATFS) && \
+    defined(HAVE_FSTATFS) && defined(MNT_LOCAL) && !defined(ST_LOCAL)
 
 /*
  * Gather current filesystem properties on FreeBSD, OpenBSD and Mac OS X.
@@ -1593,10 +1625,7 @@ setup_current_filesystem(struct archive_read_disk *a)
 		return (ARCHIVE_FAILED);
 	} else if (xr == 1) {
 		/* pathconf(_PC_REX_*) operations are not supported. */
-		t->current_filesystem->xfer_align = sfs.f_bsize;
-		t->current_filesystem->max_xfer_size = -1;
-		t->current_filesystem->min_xfer_size = sfs.f_iosize;
-		t->current_filesystem->incr_xfer_size = sfs.f_iosize;
+		set_statfs_transfer_size(t->current_filesystem, &sfs);
 	}
 	if (sfs.f_flags & MNT_LOCAL)
 		t->current_filesystem->remote = 0;
@@ -1688,15 +1717,7 @@ setup_current_filesystem(struct archive_read_disk *a)
 	} else if (xr == 1) {
 		/* Usually come here unless NetBSD supports _PC_REC_XFER_ALIGN
 		 * for pathconf() function. */
-		t->current_filesystem->xfer_align = svfs.f_frsize;
-		t->current_filesystem->max_xfer_size = -1;
-#if defined(HAVE_STRUCT_STATVFS_F_IOSIZE)
-		t->current_filesystem->min_xfer_size = svfs.f_iosize;
-		t->current_filesystem->incr_xfer_size = svfs.f_iosize;
-#else
-		t->current_filesystem->min_xfer_size = svfs.f_bsize;
-		t->current_filesystem->incr_xfer_size = svfs.f_bsize;
-#endif
+		set_statvfs_transfer_size(t->current_filesystem, &svfs);
 	}
 	if (svfs.f_flag & ST_LOCAL)
 		t->current_filesystem->remote = 0;
@@ -1803,15 +1824,9 @@ setup_current_filesystem(struct archive_read_disk *a)
 	} else if (xr == 1) {
 		/* pathconf(_PC_REX_*) operations are not supported. */
 #if defined(HAVE_STATVFS)
-		t->current_filesystem->xfer_align = svfs.f_frsize;
-		t->current_filesystem->max_xfer_size = -1;
-		t->current_filesystem->min_xfer_size = svfs.f_bsize;
-		t->current_filesystem->incr_xfer_size = svfs.f_bsize;
+		set_statvfs_transfer_size(t->current_filesystem, &svfs);
 #else
-		t->current_filesystem->xfer_align = sfs.f_frsize;
-		t->current_filesystem->max_xfer_size = -1;
-		t->current_filesystem->min_xfer_size = sfs.f_bsize;
-		t->current_filesystem->incr_xfer_size = sfs.f_bsize;
+		set_statfs_transfer_size(t->current_filesystem, &sfs);
 #endif
 	}
 	switch (sfs.f_type) {
@@ -1918,10 +1933,7 @@ setup_current_filesystem(struct archive_read_disk *a)
 		return (ARCHIVE_FAILED);
 	} else if (xr == 1) {
 		/* pathconf(_PC_REX_*) operations are not supported. */
-		t->current_filesystem->xfer_align = svfs.f_frsize;
-		t->current_filesystem->max_xfer_size = -1;
-		t->current_filesystem->min_xfer_size = svfs.f_bsize;
-		t->current_filesystem->incr_xfer_size = svfs.f_bsize;
+		set_statvfs_transfer_size(t->current_filesystem, &svfs);
 	}
 
 #if defined(ST_NOATIME)
diff --git a/contrib/libarchive/libarchive/archive_read_extract2.c b/contrib/libarchive/libarchive/archive_read_extract2.c
index fbeae7eef007..4febd8ce056f 100644
--- a/contrib/libarchive/libarchive/archive_read_extract2.c
+++ b/contrib/libarchive/libarchive/archive_read_extract2.c
@@ -24,7 +24,7 @@
  */
 
 #include "archive_platform.h"
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: src/lib/libarchive/archive_read_extract.c,v 1.61 2008/05/26 17:00:22 kientzle Exp $");
 
 #ifdef HAVE_SYS_TYPES_H
 #include <sys/types.h>
diff --git a/contrib/libarchive/libarchive/archive_read_set_options.3 b/contrib/libarchive/libarchive/archive_read_set_options.3
index 78d99999cf83..b2db4cbcb893 100644
--- a/contrib/libarchive/libarchive/archive_read_set_options.3
+++ b/contrib/libarchive/libarchive/archive_read_set_options.3
@@ -188,9 +188,18 @@ used when translating file names.
 .El
 .It Format cpio
 .Bl -tag -compact -width indent
+.It Cm compat-2x
+Libarchive 2.x incorrectly encoded Unicode filenames on
+some platforms.
+This option mimics the libarchive 2.x filename handling
+so that such archives can be read correctly.
 .It Cm hdrcharset
 The value is used as a character set name that will be
 used when translating file names.
+.It Cm pwb
+When reading a binary CPIO archive, assume that it is
+in the original PWB cpio format, and handle file mode
+bits accordingly.  The default is to assume v7 format.
 .El
 .It Format iso9660
 .Bl -tag -compact -width indent
diff --git a/contrib/libarchive/libarchive/archive_read_support_filter_rpm.c b/contrib/libarchive/libarchive/archive_read_support_filter_rpm.c
index e7e58e51f3b0..ddd68392f788 100644
--- a/contrib/libarchive/libarchive/archive_read_support_filter_rpm.c
+++ b/contrib/libarchive/libarchive/archive_read_support_filter_rpm.c
@@ -216,7 +216,7 @@ rpm_filter_read(struct archive_read_filter *self, const void **buff)
 						archive_set_error(
 						    &self->archive->archive,
 						    ARCHIVE_ERRNO_FILE_FORMAT,
-						    "Unrecoginized rpm header");
+						    "Unrecognized rpm header");
 						return (ARCHIVE_FATAL);
 					}
 					rpm->state = ST_ARCHIVE;
diff --git a/contrib/libarchive/libarchive/archive_read_support_filter_uu.c b/contrib/libarchive/libarchive/archive_read_support_filter_uu.c
index 67ddffb06943..689c18ce4390 100644
--- a/contrib/libarchive/libarchive/archive_read_support_filter_uu.c
+++ b/contrib/libarchive/libarchive/archive_read_support_filter_uu.c
@@ -248,7 +248,7 @@ bid_get_line(struct archive_read_filter *filter,
 		*ravail = *avail;
 		*b += diff;
 		*avail -= diff;
-		tested = len;/* Skip some bytes we already determinated. */
+		tested = len;/* Skip some bytes we already determined. */
 		len = get_line(*b + tested, *avail - tested, nl);
 		if (len >= 0)
 			len += tested;
diff --git a/contrib/libarchive/libarchive/archive_read_support_format_7zip.c b/contrib/libarchive/libarchive/archive_read_support_format_7zip.c
index 6ce9d1a0e1bb..63cbb7df32c8 100644
--- a/contrib/libarchive/libarchive/archive_read_support_format_7zip.c
+++ b/contrib/libarchive/libarchive/archive_read_support_format_7zip.c
@@ -808,8 +808,12 @@ archive_read_format_7zip_read_data(struct archive_read *a,
 	if (zip->end_of_entry)
 		return (ARCHIVE_EOF);
 
-	bytes = read_stream(a, buff,
-		(size_t)zip->entry_bytes_remaining, 0);
+	const uint64_t max_read_size = 16 * 1024 * 1024;  // Don't try to read more than 16 MB at a time
+	size_t bytes_to_read = max_read_size;
+	if ((uint64_t)bytes_to_read > zip->entry_bytes_remaining) {
+		bytes_to_read = zip->entry_bytes_remaining;
+	}
+	bytes = read_stream(a, buff, bytes_to_read, 0);
 	if (bytes < 0)
 		return ((int)bytes);
 	if (bytes == 0) {
@@ -1493,7 +1497,7 @@ decompress(struct archive_read *a, struct _7zip *zip,
 				zip->ppmd7_stat = -1;
 				archive_set_error(&a->archive,
 				    ARCHIVE_ERRNO_MISC,
-				    "Failed to initialize PPMd range decorder");
+				    "Failed to initialize PPMd range decoder");
 				return (ARCHIVE_FAILED);
 			}
 			if (zip->ppstream.overconsumed) {
@@ -3031,10 +3035,10 @@ extract_pack_stream(struct archive_read *a, size_t minimum)
 			    "Truncated 7-Zip file body");
 			return (ARCHIVE_FATAL);
 		}
-		if (bytes_avail > (ssize_t)zip->pack_stream_inbytes_remaining)
+		if ((uint64_t)bytes_avail > zip->pack_stream_inbytes_remaining)
 			bytes_avail = (ssize_t)zip->pack_stream_inbytes_remaining;
 		zip->pack_stream_inbytes_remaining -= bytes_avail;
-		if (bytes_avail > (ssize_t)zip->folder_outbytes_remaining)
+		if ((uint64_t)bytes_avail > zip->folder_outbytes_remaining)
 			bytes_avail = (ssize_t)zip->folder_outbytes_remaining;
 		zip->folder_outbytes_remaining -= bytes_avail;
 		zip->uncompressed_buffer_bytes_remaining = bytes_avail;
diff --git a/contrib/libarchive/libarchive/archive_read_support_format_cab.c b/contrib/libarchive/libarchive/archive_read_support_format_cab.c
index 43738b53744d..950f3d254de6 100644
--- a/contrib/libarchive/libarchive/archive_read_support_format_cab.c
+++ b/contrib/libarchive/libarchive/archive_read_support_format_cab.c
@@ -2110,7 +2110,6 @@ lzx_decode_init(struct lzx_stream *strm, int w_bits)
 		ds->pos_tbl = malloc(sizeof(ds->pos_tbl[0]) * w_slot);
 		if (ds->pos_tbl == NULL)
 			return (ARCHIVE_FATAL);
-		lzx_huffman_free(&(ds->mt));
 	}
 
 	for (footer = 0; footer < 18; footer++)
diff --git a/contrib/libarchive/libarchive/archive_read_support_format_cpio.c b/contrib/libarchive/libarchive/archive_read_support_format_cpio.c
index caaac045b104..af94583c2a12 100644
--- a/contrib/libarchive/libarchive/archive_read_support_format_cpio.c
+++ b/contrib/libarchive/libarchive/archive_read_support_format_cpio.c
@@ -185,6 +185,8 @@ struct cpio {
 	struct archive_string_conv *opt_sconv;
 	struct archive_string_conv *sconv_default;
 	int			  init_default_conversion;
+
+	int			  option_pwb;
 };
 
 static int64_t	atol16(const char *, unsigned);
@@ -343,6 +345,10 @@ archive_read_format_cpio_options(struct archive_read *a,
 				ret = ARCHIVE_FATAL;
 		}
 		return (ret);
+	} else if (strcmp(key, "pwb")  == 0) {
+		if (val != NULL && val[0] != 0)
+			cpio->option_pwb = 1;
+		return (ARCHIVE_OK);
 	}
 
 	/* Note: The "warn" return is just to inform the options
@@ -891,6 +897,12 @@ header_bin_le(struct archive_read *a, struct cpio *cpio,
 	archive_entry_set_dev(entry, header[bin_dev_offset] + header[bin_dev_offset + 1] * 256);
 	archive_entry_set_ino(entry, header[bin_ino_offset] + header[bin_ino_offset + 1] * 256);
 	archive_entry_set_mode(entry, header[bin_mode_offset] + header[bin_mode_offset + 1] * 256);
+	if (cpio->option_pwb) {
+		/* turn off random bits left over from V6 inode */
+		archive_entry_set_mode(entry, archive_entry_mode(entry) & 067777);
+		if ((archive_entry_mode(entry) & AE_IFMT) == 0)
+			archive_entry_set_mode(entry, archive_entry_mode(entry) | AE_IFREG);
+	}
 	archive_entry_set_uid(entry, header[bin_uid_offset] + header[bin_uid_offset + 1] * 256);
 	archive_entry_set_gid(entry, header[bin_gid_offset] + header[bin_gid_offset + 1] * 256);
 	archive_entry_set_nlink(entry, header[bin_nlink_offset] + header[bin_nlink_offset + 1] * 256);
@@ -930,6 +942,12 @@ header_bin_be(struct archive_read *a, struct cpio *cpio,
 	archive_entry_set_dev(entry, header[bin_dev_offset] * 256 + header[bin_dev_offset + 1]);
 	archive_entry_set_ino(entry, header[bin_ino_offset] * 256 + header[bin_ino_offset + 1]);
 	archive_entry_set_mode(entry, header[bin_mode_offset] * 256 + header[bin_mode_offset + 1]);
+	if (cpio->option_pwb) {
+		/* turn off random bits left over from V6 inode */
+		archive_entry_set_mode(entry, archive_entry_mode(entry) & 067777);
+		if ((archive_entry_mode(entry) & AE_IFMT) == 0)
+			archive_entry_set_mode(entry, archive_entry_mode(entry) | AE_IFREG);
+	}
 	archive_entry_set_uid(entry, header[bin_uid_offset] * 256 + header[bin_uid_offset + 1]);
 	archive_entry_set_gid(entry, header[bin_gid_offset] * 256 + header[bin_gid_offset + 1]);
 	archive_entry_set_nlink(entry, header[bin_nlink_offset] * 256 + header[bin_nlink_offset + 1]);
diff --git a/contrib/libarchive/libarchive/archive_read_support_format_mtree.c b/contrib/libarchive/libarchive/archive_read_support_format_mtree.c
index 669eff55fbfe..f03290ad0c8f 100644
--- a/contrib/libarchive/libarchive/archive_read_support_format_mtree.c
+++ b/contrib/libarchive/libarchive/archive_read_support_format_mtree.c
@@ -408,7 +408,7 @@ next_line(struct archive_read *a,
 		*ravail = *avail;
 		*b += diff;
 		*avail -= diff;
-		tested = len;/* Skip some bytes we already determinated. */
+		tested = len;/* Skip some bytes we already determined. */
 		len = get_line_size(*b + len, *avail - len, nl);
 		if (len >= 0)
 			len += tested;
@@ -1074,7 +1074,7 @@ read_mtree(struct archive_read *a, struct mtree *mtree)
 			continue;
 		/* Non-printable characters are not allowed */
 		for (s = p;s < p + len - 1; s++) {
-			if (!isprint(*s)) {
+			if (!isprint((unsigned char)*s)) {
 				r = ARCHIVE_FATAL;
 				break;
 			}
@@ -2035,13 +2035,13 @@ mtree_atol(char **p, int base)
 
 	if (**p == '-') {
 		limit = INT64_MIN / base;
-		last_digit_limit = INT64_MIN % base;
+		last_digit_limit = -(INT64_MIN % base);
 		++(*p);
 
 		l = 0;
 		digit = parsedigit(**p);
 		while (digit >= 0 && digit < base) {
-			if (l < limit || (l == limit && digit > last_digit_limit))
+			if (l < limit || (l == limit && digit >= last_digit_limit))
 				return INT64_MIN;
 			l = (l * base) - digit;
 			digit = parsedigit(*++(*p));
diff --git a/contrib/libarchive/libarchive/archive_read_support_format_rar.c b/contrib/libarchive/libarchive/archive_read_support_format_rar.c
index 283a9604447b..c2666b2f4612 100644
--- a/contrib/libarchive/libarchive/archive_read_support_format_rar.c
+++ b/contrib/libarchive/libarchive/archive_read_support_format_rar.c
@@ -958,17 +958,17 @@ archive_read_format_rar_read_header(struct archive_read *a,
       crc32_val = 0;
       while (skip > 0) {
 	      size_t to_read = skip;
-	      ssize_t did_read;
-	      if (to_read > 32 * 1024) {
+	      if (to_read > 32 * 1024)
 		      to_read = 32 * 1024;
-	      }
-	      if ((h = __archive_read_ahead(a, to_read, &did_read)) == NULL) {
+	      if ((h = __archive_read_ahead(a, to_read, NULL)) == NULL) {
+		      archive_set_error(&a->archive,  ARCHIVE_ERRNO_FILE_FORMAT,
+			  "Bad RAR file");
 		      return (ARCHIVE_FATAL);
 	      }
 	      p = h;
-	      crc32_val = crc32(crc32_val, (const unsigned char *)p, (unsigned)did_read);
-	      __archive_read_consume(a, did_read);
-	      skip -= did_read;
+	      crc32_val = crc32(crc32_val, (const unsigned char *)p, to_read);
+	      __archive_read_consume(a, to_read);
+	      skip -= to_read;
       }
       if ((crc32_val & 0xffff) != crc32_expected) {
 	      archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
diff --git a/contrib/libarchive/libarchive/archive_read_support_format_rar5.c b/contrib/libarchive/libarchive/archive_read_support_format_rar5.c
index 58a61d1bcb29..5d62d16ee00f 100644
--- a/contrib/libarchive/libarchive/archive_read_support_format_rar5.c
+++ b/contrib/libarchive/libarchive/archive_read_support_format_rar5.c
@@ -4076,6 +4076,7 @@ int archive_read_support_format_rar5(struct archive *_a) {
 	if(ARCHIVE_OK != rar5_init(rar)) {
 		archive_set_error(&ar->archive, ENOMEM,
 		    "Can't allocate rar5 filter buffer");
+		free(rar);
 		return ARCHIVE_FATAL;
 	}
 
diff --git a/contrib/libarchive/libarchive/archive_read_support_format_tar.c b/contrib/libarchive/libarchive/archive_read_support_format_tar.c
index ce2e4095f6d9..2613a6d83f0e 100644
--- a/contrib/libarchive/libarchive/archive_read_support_format_tar.c
+++ b/contrib/libarchive/libarchive/archive_read_support_format_tar.c
@@ -1908,7 +1908,7 @@ pax_attribute(struct archive_read *a, struct tar *tar,
 		}
 		if (strcmp(key, "GNU.sparse.numbytes") == 0) {
 			tar->sparse_numbytes = tar_atol10(value, strlen(value));
-			if (tar->sparse_numbytes != -1) {
+			if (tar->sparse_offset != -1) {
 				if (gnu_add_sparse_entry(a, tar,
 				    tar->sparse_offset, tar->sparse_numbytes)
 				    != ARCHIVE_OK)
@@ -2645,14 +2645,14 @@ tar_atol_base_n(const char *p, size_t char_cnt, int base)
 
 		maxval = INT64_MIN;
 		limit = -(INT64_MIN / base);
-		last_digit_limit = INT64_MIN % base;
+		last_digit_limit = -(INT64_MIN % base);
 	}
 
 	l = 0;
 	if (char_cnt != 0) {
 		digit = *p - '0';
 		while (digit >= 0 && digit < base  && char_cnt != 0) {
-			if (l>limit || (l == limit && digit > last_digit_limit)) {
+			if (l>limit || (l == limit && digit >= last_digit_limit)) {
 				return maxval; /* Truncate on overflow. */
 			}
 			l = (l * base) + digit;
diff --git a/contrib/libarchive/libarchive/archive_read_support_format_zip.c b/contrib/libarchive/libarchive/archive_read_support_format_zip.c
index e046a9fd150e..210a87886aef 100644
--- a/contrib/libarchive/libarchive/archive_read_support_format_zip.c
+++ b/contrib/libarchive/libarchive/archive_read_support_format_zip.c
@@ -142,6 +142,7 @@ struct zip {
 	/* Structural information about the archive. */
 	struct archive_string	format_name;
 	int64_t			central_directory_offset;
+	int64_t			central_directory_offset_adjusted;
 	size_t			central_directory_entries_total;
 	size_t			central_directory_entries_on_this_disk;
 	int			has_encrypted_entries;
@@ -246,6 +247,17 @@ struct zip {
 /* Many systems define min or MIN, but not all. */
 #define	zipmin(a,b) ((a) < (b) ? (a) : (b))
 
+#ifdef HAVE_ZLIB_H
+static int
+zip_read_data_deflate(struct archive_read *a, const void **buff,
+	size_t *size, int64_t *offset);
+#endif
+#if HAVE_LZMA_H && HAVE_LIBLZMA
+static int
+zip_read_data_zipx_lzma_alone(struct archive_read *a, const void **buff,
+	size_t *size, int64_t *offset);
+#endif
+
 /* This function is used by Ppmd8_DecodeSymbol during decompression of Ppmd8
  * streams inside ZIP files. It has 2 purposes: one is to fetch the next
  * compressed byte from the stream, second one is to increase the counter how
@@ -899,81 +911,6 @@ process_extra(struct archive_read *a, struct archive_entry *entry,
 	return ARCHIVE_OK;
 }
 
-#if HAVE_LZMA_H && HAVE_LIBLZMA
-/*
- * Auxiliary function to uncompress data chunk from zipx archive
- * (zip with lzma compression).
- */
-static int
-zipx_lzma_uncompress_buffer(const char *compressed_buffer,
-	size_t compressed_buffer_size,
-	char *uncompressed_buffer,
-	size_t uncompressed_buffer_size)
-{
-	int status = ARCHIVE_FATAL;
-	// length of 'lzma properties data' in lzma compressed
-	// data segment (stream) inside zip archive
-	const size_t lzma_params_length = 5;
-	// offset of 'lzma properties data' from the beginning of lzma stream
-	const size_t lzma_params_offset = 4;
-	// end position of 'lzma properties data' in lzma stream
-	const size_t lzma_params_end = lzma_params_offset + lzma_params_length;
-	if (compressed_buffer == NULL ||
-			compressed_buffer_size < lzma_params_end ||
-			uncompressed_buffer == NULL)
-		return status;
-
-	// prepare header for lzma_alone_decoder to replace zipx header
-	// (see comments in 'zipx_lzma_alone_init' for justification)
-#pragma pack(push)
-#pragma pack(1)
-	struct _alone_header
-	{
-		uint8_t bytes[5]; // lzma_params_length
-		uint64_t uncompressed_size;
-	} alone_header;
-#pragma pack(pop)
-	// copy 'lzma properties data' blob
-	memcpy(&alone_header.bytes[0], compressed_buffer + lzma_params_offset,
-		lzma_params_length);
-	alone_header.uncompressed_size = UINT64_MAX;
-
-	// prepare new compressed buffer, see 'zipx_lzma_alone_init' for details
-	const size_t lzma_alone_buffer_size =
-		compressed_buffer_size - lzma_params_end + sizeof(alone_header);
-	unsigned char *lzma_alone_compressed_buffer =
-		(unsigned char*) malloc(lzma_alone_buffer_size);
-	if (lzma_alone_compressed_buffer == NULL)
-		return status;
-	// copy lzma_alone header into new buffer
-	memcpy(lzma_alone_compressed_buffer, (void*) &alone_header,
-		sizeof(alone_header));
-	// copy compressed data into new buffer
-	memcpy(lzma_alone_compressed_buffer + sizeof(alone_header),
-		compressed_buffer + lzma_params_end,
-		compressed_buffer_size - lzma_params_end);
-
-	// create and fill in lzma_alone_decoder stream
-	lzma_stream stream = LZMA_STREAM_INIT;
-	lzma_ret ret = lzma_alone_decoder(&stream, UINT64_MAX);
-	if (ret == LZMA_OK)
-	{
-		stream.next_in = lzma_alone_compressed_buffer;
-		stream.avail_in = lzma_alone_buffer_size;
-		stream.total_in = 0;
-		stream.next_out = (unsigned char*)uncompressed_buffer;
-		stream.avail_out = uncompressed_buffer_size;
-		stream.total_out = 0;
-		ret = lzma_code(&stream, LZMA_RUN);
-		if (ret == LZMA_OK || ret == LZMA_STREAM_END)
-			status = ARCHIVE_OK;
-	}
-	lzma_end(&stream);
-	free(lzma_alone_compressed_buffer);
-	return status;
-}
-#endif
-
 /*
  * Assumes file pointer is at beginning of local file header.
  */
@@ -1242,36 +1179,30 @@ zip_read_local_file_header(struct archive_read *a, struct archive_entry *entry,
 		linkname_length = (size_t)zip_entry->compressed_size;
 
 		archive_entry_set_size(entry, 0);
-		p = __archive_read_ahead(a, linkname_length, NULL);
-		if (p == NULL) {
-			archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
-			    "Truncated Zip file");
-			return ARCHIVE_FATAL;
-		}
+
 		// take into account link compression if any
*** 3749 LINES SKIPPED ***



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202109100829.18A8TZxA073016>