Module Name:    src
Committed By:   christos
Date:           Thu Oct 17 16:42:09 UTC 2024

Modified Files:
        src/external/bsd/libarchive/dist/cat/test: test_0.c
        src/external/bsd/libarchive/dist/cpio/test: test_basic.c
            test_format_newc.c
        src/external/bsd/libarchive/dist/libarchive: archive.h
            archive_openssl_evp_private.h archive_openssl_hmac_private.h
            archive_private.h archive_read.c
            archive_read_disk_entry_from_file.c archive_read_disk_posix.c
            archive_read_open_filename.c archive_read_support_format_iso9660.c
            archive_read_support_format_mtree.c
            archive_read_support_format_xar.c archive_util.c
            archive_write_disk_posix.c archive_write_set_format_ar.c
            archive_write_set_format_shar.c archive_write_set_format_ustar.c
        src/external/bsd/libarchive/dist/libarchive/test:
            test_read_format_7zip.c test_read_format_zip_nested.c
            test_read_truncated_filter.c test_sparse_basic.c
        src/external/bsd/libarchive/dist/tar: bsdtar.c write.c
        src/external/bsd/libarchive/dist/tar/test: test_basic.c test_copy.c
            test_option_C_upper.c test_option_U_upper.c test_option_s.c
            test_symlink_dir.c
        src/external/bsd/libarchive/dist/test_utils: test_common.h test_main.c
        src/external/bsd/libarchive/include: config_netbsd.h

Log Message:
merge conflicts (4 tests still fail)


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/external/bsd/libarchive/dist/cat/test/test_0.c
cvs rdiff -u -r1.3 -r1.4 \
    src/external/bsd/libarchive/dist/cpio/test/test_basic.c
cvs rdiff -u -r1.4 -r1.5 \
    src/external/bsd/libarchive/dist/cpio/test/test_format_newc.c
cvs rdiff -u -r1.6 -r1.7 \
    src/external/bsd/libarchive/dist/libarchive/archive.h
cvs rdiff -u -r1.4 -r1.5 \
    src/external/bsd/libarchive/dist/libarchive/archive_openssl_evp_private.h \
    src/external/bsd/libarchive/dist/libarchive/archive_read_disk_posix.c
cvs rdiff -u -r1.5 -r1.6 \
    src/external/bsd/libarchive/dist/libarchive/archive_openssl_hmac_private.h \
    
src/external/bsd/libarchive/dist/libarchive/archive_read_support_format_iso9660.c
 \
    src/external/bsd/libarchive/dist/libarchive/archive_write_set_format_ar.c \
    src/external/bsd/libarchive/dist/libarchive/archive_write_set_format_shar.c 
\
    src/external/bsd/libarchive/dist/libarchive/archive_write_set_format_ustar.c
cvs rdiff -u -r1.3 -r1.4 \
    src/external/bsd/libarchive/dist/libarchive/archive_private.h \
    src/external/bsd/libarchive/dist/libarchive/archive_read.c \
    src/external/bsd/libarchive/dist/libarchive/archive_read_open_filename.c \
    
src/external/bsd/libarchive/dist/libarchive/archive_read_support_format_mtree.c 
\
    
src/external/bsd/libarchive/dist/libarchive/archive_read_support_format_xar.c \
    src/external/bsd/libarchive/dist/libarchive/archive_util.c
cvs rdiff -u -r1.7 -r1.8 \
    
src/external/bsd/libarchive/dist/libarchive/archive_read_disk_entry_from_file.c 
\
    src/external/bsd/libarchive/dist/libarchive/archive_write_disk_posix.c
cvs rdiff -u -r1.3 -r1.4 \
    src/external/bsd/libarchive/dist/libarchive/test/test_read_format_7zip.c \
    
src/external/bsd/libarchive/dist/libarchive/test/test_read_format_zip_nested.c \
    
src/external/bsd/libarchive/dist/libarchive/test/test_read_truncated_filter.c
cvs rdiff -u -r1.4 -r1.5 \
    src/external/bsd/libarchive/dist/libarchive/test/test_sparse_basic.c
cvs rdiff -u -r1.3 -r1.4 src/external/bsd/libarchive/dist/tar/bsdtar.c
cvs rdiff -u -r1.4 -r1.5 src/external/bsd/libarchive/dist/tar/write.c
cvs rdiff -u -r1.3 -r1.4 \
    src/external/bsd/libarchive/dist/tar/test/test_basic.c \
    src/external/bsd/libarchive/dist/tar/test/test_option_C_upper.c \
    src/external/bsd/libarchive/dist/tar/test/test_option_U_upper.c \
    src/external/bsd/libarchive/dist/tar/test/test_option_s.c \
    src/external/bsd/libarchive/dist/tar/test/test_symlink_dir.c
cvs rdiff -u -r1.4 -r1.5 \
    src/external/bsd/libarchive/dist/tar/test/test_copy.c
cvs rdiff -u -r1.3 -r1.4 \
    src/external/bsd/libarchive/dist/test_utils/test_common.h \
    src/external/bsd/libarchive/dist/test_utils/test_main.c
cvs rdiff -u -r1.13 -r1.14 \
    src/external/bsd/libarchive/include/config_netbsd.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/bsd/libarchive/dist/cat/test/test_0.c
diff -u src/external/bsd/libarchive/dist/cat/test/test_0.c:1.2 src/external/bsd/libarchive/dist/cat/test/test_0.c:1.3
--- src/external/bsd/libarchive/dist/cat/test/test_0.c:1.2	Tue Jan 21 13:33:47 2020
+++ src/external/bsd/libarchive/dist/cat/test/test_0.c	Thu Oct 17 12:42:07 2024
@@ -1,26 +1,8 @@
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
  * 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"
 

Index: src/external/bsd/libarchive/dist/cpio/test/test_basic.c
diff -u src/external/bsd/libarchive/dist/cpio/test/test_basic.c:1.3 src/external/bsd/libarchive/dist/cpio/test/test_basic.c:1.4
--- src/external/bsd/libarchive/dist/cpio/test/test_basic.c:1.3	Sun Jun  9 15:47:55 2024
+++ src/external/bsd/libarchive/dist/cpio/test/test_basic.c	Thu Oct 17 12:42:07 2024
@@ -1,26 +1,8 @@
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
  * 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"
 

Index: src/external/bsd/libarchive/dist/cpio/test/test_format_newc.c
diff -u src/external/bsd/libarchive/dist/cpio/test/test_format_newc.c:1.4 src/external/bsd/libarchive/dist/cpio/test/test_format_newc.c:1.5
--- src/external/bsd/libarchive/dist/cpio/test/test_format_newc.c:1.4	Sun Jun  9 15:47:55 2024
+++ src/external/bsd/libarchive/dist/cpio/test/test_format_newc.c	Thu Oct 17 12:42:07 2024
@@ -1,26 +1,8 @@
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
  * 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"
 
@@ -194,11 +176,11 @@ DEFINE_TEST(test_format_newc)
 	assertEqualMem(e + 0, "070701", 6); /* Magic */
 	ino = from_hex(e + 6, 8); /* ino */
 #if defined(_WIN32) && !defined(__CYGWIN__)
-	/* Group members bits and others bits do not work. */ 
+	/* Group members bits and others bits do not work. */
 	assertEqualInt(0x8180, from_hex(e + 14, 8) & 0xffc0); /* Mode */
 #else
 	assertEqualInt(0x81a4, from_hex(e + 14, 8)); /* Mode */
-#endif	
+#endif
 #if defined(_WIN32)
 	uid = from_hex(e + 22, 8);
 #else
@@ -308,7 +290,7 @@ DEFINE_TEST(test_format_newc)
 	failure("If these aren't the same, then the hardlink detection failed to match them.");
 	assertEqualInt(ino, from_hex(e + 6, 8)); /* ino */
 #if defined(_WIN32) && !defined(__CYGWIN__)
-	/* Group members bits and others bits do not work. */ 
+	/* Group members bits and others bits do not work. */
 	assertEqualInt(0x8180, from_hex(e + 14, 8) & 0xffc0); /* Mode */
 #else
 	assertEqualInt(0x81a4, from_hex(e + 14, 8)); /* Mode */

Index: src/external/bsd/libarchive/dist/libarchive/archive.h
diff -u src/external/bsd/libarchive/dist/libarchive/archive.h:1.6 src/external/bsd/libarchive/dist/libarchive/archive.h:1.7
--- src/external/bsd/libarchive/dist/libarchive/archive.h:1.6	Sun Jun  9 15:47:55 2024
+++ src/external/bsd/libarchive/dist/libarchive/archive.h	Thu Oct 17 12:42:07 2024
@@ -34,7 +34,7 @@
  * assert that ARCHIVE_VERSION_NUMBER >= 2012108.
  */
 /* Note: Compiler will complain if this does not match archive_entry.h! */
-#define	ARCHIVE_VERSION_NUMBER 3007004
+#define	ARCHIVE_VERSION_NUMBER 3007007
 
 #include <sys/stat.h>
 #include <stddef.h>  /* for wchar_t */
@@ -155,7 +155,7 @@ __LA_DECL int		archive_version_number(vo
 /*
  * Textual name/version of the library, useful for version displays.
  */
-#define	ARCHIVE_VERSION_ONLY_STRING "3.7.4"
+#define	ARCHIVE_VERSION_ONLY_STRING "3.7.7"
 #define	ARCHIVE_VERSION_STRING "libarchive " ARCHIVE_VERSION_ONLY_STRING
 __LA_DECL const char *	archive_version_string(void);
 

Index: src/external/bsd/libarchive/dist/libarchive/archive_openssl_evp_private.h
diff -u src/external/bsd/libarchive/dist/libarchive/archive_openssl_evp_private.h:1.4 src/external/bsd/libarchive/dist/libarchive/archive_openssl_evp_private.h:1.5
--- src/external/bsd/libarchive/dist/libarchive/archive_openssl_evp_private.h:1.4	Sun Jun  9 15:47:55 2024
+++ src/external/bsd/libarchive/dist/libarchive/archive_openssl_evp_private.h	Thu Oct 17 12:42:08 2024
@@ -39,7 +39,7 @@
 #include <string.h> /* memset */
 static inline EVP_MD_CTX *EVP_MD_CTX_new(void)
 {
-	EVP_MD_CTX *ctx = (EVP_MD_CTX *)calloc(1, sizeof(EVP_MD_CTX));
+	EVP_MD_CTX *ctx = calloc(1, sizeof(EVP_MD_CTX));
 	return ctx;
 }
 
Index: src/external/bsd/libarchive/dist/libarchive/archive_read_disk_posix.c
diff -u src/external/bsd/libarchive/dist/libarchive/archive_read_disk_posix.c:1.4 src/external/bsd/libarchive/dist/libarchive/archive_read_disk_posix.c:1.5
--- src/external/bsd/libarchive/dist/libarchive/archive_read_disk_posix.c:1.4	Sun Jun  9 15:47:55 2024
+++ src/external/bsd/libarchive/dist/libarchive/archive_read_disk_posix.c	Thu Oct 17 12:42:08 2024
@@ -451,7 +451,7 @@ archive_read_disk_new(void)
 {
 	struct archive_read_disk *a;
 
-	a = (struct archive_read_disk *)calloc(1, sizeof(*a));
+	a = calloc(1, sizeof(*a));
 	if (a == NULL)
 		return (NULL);
 	a->archive.magic = ARCHIVE_READ_DISK_MAGIC;

Index: src/external/bsd/libarchive/dist/libarchive/archive_openssl_hmac_private.h
diff -u src/external/bsd/libarchive/dist/libarchive/archive_openssl_hmac_private.h:1.5 src/external/bsd/libarchive/dist/libarchive/archive_openssl_hmac_private.h:1.6
--- src/external/bsd/libarchive/dist/libarchive/archive_openssl_hmac_private.h:1.5	Sun Jun  9 15:47:55 2024
+++ src/external/bsd/libarchive/dist/libarchive/archive_openssl_hmac_private.h	Thu Oct 17 12:42:08 2024
@@ -39,7 +39,7 @@
 #include <string.h> /* memset */
 static inline HMAC_CTX *HMAC_CTX_new(void)
 {
-	HMAC_CTX *ctx = (HMAC_CTX *)calloc(1, sizeof(HMAC_CTX));
+	HMAC_CTX *ctx = calloc(1, sizeof(HMAC_CTX));
 	return ctx;
 }
 
Index: src/external/bsd/libarchive/dist/libarchive/archive_read_support_format_iso9660.c
diff -u src/external/bsd/libarchive/dist/libarchive/archive_read_support_format_iso9660.c:1.5 src/external/bsd/libarchive/dist/libarchive/archive_read_support_format_iso9660.c:1.6
--- src/external/bsd/libarchive/dist/libarchive/archive_read_support_format_iso9660.c:1.5	Sun Jun  9 15:47:55 2024
+++ src/external/bsd/libarchive/dist/libarchive/archive_read_support_format_iso9660.c	Thu Oct 17 12:42:08 2024
@@ -273,7 +273,7 @@ struct file_info {
 	char		 re;		/* Having RRIP "RE" extension.	*/
 	char		 re_descendant;
 	uint64_t	 cl_offset;	/* Having RRIP "CL" extension.	*/
-	int		 birthtime_is_set;
+	int		 time_is_set;	/* Bitmask indicating which times are known */
 	time_t		 birthtime;	/* File created time.		*/
 	time_t		 mtime;		/* File last modified time.	*/
 	time_t		 atime;		/* File last accessed time.	*/
@@ -306,6 +306,11 @@ struct file_info {
 	} rede_files;
 };
 
+#define BIRTHTIME_IS_SET 1
+#define MTIME_IS_SET 2
+#define ATIME_IS_SET 4
+#define CTIME_IS_SET 8
+
 struct heap_queue {
 	struct file_info **files;
 	int		 allocated;
@@ -394,7 +399,9 @@ static void	dump_isodirrec(FILE *, const
 #endif
 static time_t	time_from_tm(struct tm *);
 static time_t	isodate17(const unsigned char *);
+static int	isodate17_valid(const unsigned char *);
 static time_t	isodate7(const unsigned char *);
+static int	isodate7_valid(const unsigned char *);
 static int	isBootRecord(struct iso9660 *, const unsigned char *);
 static int	isVolumePartition(struct iso9660 *, const unsigned char *);
 static int	isVDSetTerminator(struct iso9660 *, const unsigned char *);
@@ -402,6 +409,9 @@ static int	isJolietSVD(struct iso9660 *,
 static int	isSVD(struct iso9660 *, const unsigned char *);
 static int	isEVD(struct iso9660 *, const unsigned char *);
 static int	isPVD(struct iso9660 *, const unsigned char *);
+static int	isRootDirectoryRecord(const unsigned char *);
+static int	isValid723Integer(const unsigned char *);
+static int	isValid733Integer(const unsigned char *);
 static int	next_cache_entry(struct archive_read *, struct iso9660 *,
 		    struct file_info **);
 static int	next_entry_seek(struct archive_read *, struct iso9660 *,
@@ -453,7 +463,7 @@ archive_read_support_format_iso9660(stru
 	archive_check_magic(_a, ARCHIVE_READ_MAGIC,
 	    ARCHIVE_STATE_NEW, "archive_read_support_format_iso9660");
 
-	iso9660 = (struct iso9660 *)calloc(1, sizeof(*iso9660));
+	iso9660 = calloc(1, sizeof(*iso9660));
 	if (iso9660 == NULL) {
 		archive_set_error(&a->archive, ENOMEM,
 		    "Can't allocate iso9660 data");
@@ -773,8 +783,9 @@ isSVD(struct iso9660 *iso9660, const uns
 
 	/* Read Root Directory Record in Volume Descriptor. */
 	p = h + SVD_root_directory_record_offset;
-	if (p[DR_length_offset] != 34)
+	if (!isRootDirectoryRecord(p)) {
 		return (0);
+	}
 
 	return (48);
 }
@@ -851,8 +862,9 @@ isEVD(struct iso9660 *iso9660, const uns
 
 	/* Read Root Directory Record in Volume Descriptor. */
 	p = h + PVD_root_directory_record_offset;
-	if (p[DR_length_offset] != 34)
+	if (!isRootDirectoryRecord(p)) {
 		return (0);
+	}
 
 	return (48);
 }
@@ -882,21 +894,43 @@ isPVD(struct iso9660 *iso9660, const uns
 	if (!isNull(iso9660, h, PVD_reserved2_offset, PVD_reserved2_size))
 		return (0);
 
+	/* Volume space size must be encoded according to 7.3.3 */
+	if (!isValid733Integer(h + PVD_volume_space_size_offset)) {
+		return (0);
+	}
+	volume_block = archive_le32dec(h + PVD_volume_space_size_offset);
+	if (volume_block <= SYSTEM_AREA_BLOCK+4)
+		return (0);
+
 	/* Reserved field must be 0. */
 	if (!isNull(iso9660, h, PVD_reserved3_offset, PVD_reserved3_size))
 		return (0);
 
+	/* Volume set size must be encoded according to 7.2.3 */
+	if (!isValid723Integer(h + PVD_volume_set_size_offset)) {
+		return (0);
+	}
+
+	/* Volume sequence number must be encoded according to 7.2.3 */
+	if (!isValid723Integer(h + PVD_volume_sequence_number_offset)) {
+		return (0);
+	}
+
 	/* Logical block size must be > 0. */
 	/* I've looked at Ecma 119 and can't find any stronger
 	 * restriction on this field. */
+	if (!isValid723Integer(h + PVD_logical_block_size_offset)) {
+		return (0);
+	}
 	logical_block_size =
 	    archive_le16dec(h + PVD_logical_block_size_offset);
 	if (logical_block_size <= 0)
 		return (0);
 
-	volume_block = archive_le32dec(h + PVD_volume_space_size_offset);
-	if (volume_block <= SYSTEM_AREA_BLOCK+4)
+	/* Path Table size must be encoded according to 7.3.3 */
+	if (!isValid733Integer(h + PVD_path_table_size_offset)) {
 		return (0);
+	}
 
 	/* File structure version must be 1 for ISO9660/ECMA119. */
 	if (h[PVD_file_structure_version_offset] != 1)
@@ -935,8 +969,9 @@ isPVD(struct iso9660 *iso9660, const uns
 
 	/* Read Root Directory Record in Volume Descriptor. */
 	p = h + PVD_root_directory_record_offset;
-	if (p[DR_length_offset] != 34)
+	if (!isRootDirectoryRecord(p)) {
 		return (0);
+	}
 
 	if (!iso9660->primary.location) {
 		iso9660->logical_block_size = logical_block_size;
@@ -952,6 +987,51 @@ isPVD(struct iso9660 *iso9660, const uns
 }
 
 static int
+isRootDirectoryRecord(const unsigned char *p) {
+	int flags;
+
+	/* ECMA119/ISO9660 requires that the root directory record be _exactly_ 34 bytes.
+	 * However, we've seen images that have root directory records up to 68 bytes. */
+	if (p[DR_length_offset] < 34 || p[DR_length_offset] > 68) {
+		return (0);
+	}
+
+	/* The root directory location must be a 7.3.3 32-bit integer. */
+	if (!isValid733Integer(p + DR_extent_offset)) {
+		return (0);
+	}
+
+	/* The root directory size must be a 7.3.3 integer. */
+	if (!isValid733Integer(p + DR_size_offset)) {
+		return (0);
+	}
+
+	/* According to the standard, certain bits must be one or zero:
+	 * Bit 1: must be 1 (this is a directory)
+	 * Bit 2: must be 0 (not an associated file)
+	 * Bit 3: must be 0 (doesn't use extended attribute record)
+	 * Bit 7: must be 0 (final directory record for this file)
+	 */
+	flags = p[DR_flags_offset];
+	if ((flags & 0x8E) != 0x02) {
+		return (0);
+	}
+
+	/* Volume sequence number must be a 7.2.3 integer. */
+	if (!isValid723Integer(p + DR_volume_sequence_number_offset)) {
+		return (0);
+	}
+
+	/* Root directory name is a single zero byte... */
+	if (p[DR_name_len_offset] != 1 || p[DR_name_offset] != 0) {
+		return (0);
+	}
+
+	/* Nothing looked wrong, so let's accept it. */
+	return (1);
+}
+
+static int
 read_children(struct archive_read *a, struct file_info *parent)
 {
 	struct iso9660 *iso9660;
@@ -1212,7 +1292,7 @@ archive_read_format_iso9660_read_header(
 			}
 		}
 		if (iso9660->utf16be_previous_path == NULL) {
-			iso9660->utf16be_previous_path = malloc(UTF16_NAME_MAX);
+			iso9660->utf16be_previous_path = calloc(1, UTF16_NAME_MAX);
 			if (iso9660->utf16be_previous_path == NULL) {
 				archive_set_error(&a->archive, ENOMEM,
 				    "No memory");
@@ -1278,13 +1358,22 @@ archive_read_format_iso9660_read_header(
 	archive_entry_set_uid(entry, file->uid);
 	archive_entry_set_gid(entry, file->gid);
 	archive_entry_set_nlink(entry, file->nlinks);
-	if (file->birthtime_is_set)
+	if ((file->time_is_set & BIRTHTIME_IS_SET))
 		archive_entry_set_birthtime(entry, file->birthtime, 0);
 	else
 		archive_entry_unset_birthtime(entry);
-	archive_entry_set_mtime(entry, file->mtime, 0);
-	archive_entry_set_ctime(entry, file->ctime, 0);
-	archive_entry_set_atime(entry, file->atime, 0);
+	if ((file->time_is_set & MTIME_IS_SET))
+		archive_entry_set_mtime(entry, file->mtime, 0);
+	else
+		archive_entry_unset_mtime(entry);
+	if ((file->time_is_set & CTIME_IS_SET))
+		archive_entry_set_ctime(entry, file->ctime, 0);
+	else
+		archive_entry_unset_ctime(entry);
+	if ((file->time_is_set & ATIME_IS_SET))
+		archive_entry_set_atime(entry, file->atime, 0);
+	else
+		archive_entry_unset_atime(entry);
 	/* N.B.: Rock Ridge supports 64-bit device numbers. */
 	archive_entry_set_rdev(entry, (dev_t)file->rdev);
 	archive_entry_set_size(entry, iso9660->entry_bytes_remaining);
@@ -1816,7 +1905,7 @@ parse_file_info(struct archive_read *a, 
 	}
 
 	/* Create a new file entry and copy data from the ISO dir record. */
-	file = (struct file_info *)calloc(1, sizeof(*file));
+	file = calloc(1, sizeof(*file));
 	if (file == NULL) {
 		archive_set_error(&a->archive, ENOMEM,
 		    "No memory for file entry");
@@ -1825,8 +1914,11 @@ parse_file_info(struct archive_read *a, 
 	file->parent = parent;
 	file->offset = offset;
 	file->size = fsize;
-	file->mtime = isodate7(isodirrec + DR_date_offset);
-	file->ctime = file->atime = file->mtime;
+	if (isodate7_valid(isodirrec + DR_date_offset)) {
+		file->time_is_set |= MTIME_IS_SET | ATIME_IS_SET | CTIME_IS_SET;
+		file->mtime = isodate7(isodirrec + DR_date_offset);
+		file->ctime = file->atime = file->mtime;
+	}
 	file->rede_files.first = NULL;
 	file->rede_files.last = &(file->rede_files.first);
 
@@ -2500,51 +2592,73 @@ parse_rockridge_TF1(struct file_info *fi
 		/* Use 17-byte time format. */
 		if ((flag & 1) && data_length >= 17) {
 			/* Create time. */
-			file->birthtime_is_set = 1;
-			file->birthtime = isodate17(data);
+			if (isodate17_valid(data)) {
+				file->time_is_set |= BIRTHTIME_IS_SET;
+				file->birthtime = isodate17(data);
+			}
 			data += 17;
 			data_length -= 17;
 		}
 		if ((flag & 2) && data_length >= 17) {
 			/* Modify time. */
-			file->mtime = isodate17(data);
+			if (isodate17_valid(data)) {
+				file->time_is_set |= MTIME_IS_SET;
+				file->mtime = isodate17(data);
+			}
 			data += 17;
 			data_length -= 17;
 		}
 		if ((flag & 4) && data_length >= 17) {
 			/* Access time. */
-			file->atime = isodate17(data);
+			if (isodate17_valid(data)) {
+				file->time_is_set |= ATIME_IS_SET;
+				file->atime = isodate17(data);
+			}
 			data += 17;
 			data_length -= 17;
 		}
 		if ((flag & 8) && data_length >= 17) {
 			/* Attribute change time. */
-			file->ctime = isodate17(data);
+			if (isodate17_valid(data)) {
+				file->time_is_set |= CTIME_IS_SET;
+				file->ctime = isodate17(data);
+			}
 		}
 	} else {
 		/* Use 7-byte time format. */
 		if ((flag & 1) && data_length >= 7) {
 			/* Create time. */
-			file->birthtime_is_set = 1;
-			file->birthtime = isodate7(data);
+			if (isodate7_valid(data)) {
+				file->time_is_set |= BIRTHTIME_IS_SET;
+				file->birthtime = isodate7(data);
+			}
 			data += 7;
 			data_length -= 7;
 		}
 		if ((flag & 2) && data_length >= 7) {
 			/* Modify time. */
-			file->mtime = isodate7(data);
+			if (isodate7_valid(data)) {
+				file->time_is_set |= MTIME_IS_SET;
+				file->mtime = isodate7(data);
+			}
 			data += 7;
 			data_length -= 7;
 		}
 		if ((flag & 4) && data_length >= 7) {
 			/* Access time. */
-			file->atime = isodate7(data);
+			if (isodate7_valid(data)) {
+				file->time_is_set |= ATIME_IS_SET;
+				file->atime = isodate7(data);
+			}
 			data += 7;
 			data_length -= 7;
 		}
 		if ((flag & 8) && data_length >= 7) {
 			/* Attribute change time. */
-			file->ctime = isodate7(data);
+			if (isodate7_valid(data)) {
+				file->time_is_set |= CTIME_IS_SET;
+				file->ctime = isodate7(data);
+			}
 		}
 	}
 }
@@ -3033,7 +3147,7 @@ heap_add_entry(struct archive_read *a, s
 			return (ARCHIVE_FATAL);
 		}
 		new_pending_files = (struct file_info **)
-		    malloc(new_size * sizeof(new_pending_files[0]));
+		    calloc(new_size, sizeof(new_pending_files[0]));
 		if (new_pending_files == NULL) {
 			archive_set_error(&a->archive,
 			    ENOMEM, "Out of memory");
@@ -3127,6 +3241,82 @@ toi(const void *p, int n)
 	return (0);
 }
 
+/*
+ * ECMA119/ISO9660 stores multi-byte integers in one of
+ * three different formats:
+ *  * Little-endian (specified in section 7.2.1 and 7.3.1)
+ *  * Big-endian (specified in section 7.2.2 and 7.3.2)
+ *  * Both (specified in section 7.2.3 and 7.3.3)
+ *
+ * For values that follow section 7.2.3 (16-bit) or 7.3.3 (32-bit), we
+ * can check that the little-endian and big-endian forms agree with
+ * each other.  This helps us avoid trying to decode files that are
+ * not really ISO images.
+ */
+static int
+isValid723Integer(const unsigned char *p) {
+	return (p[0] == p[3] && p[1] == p[2]);
+}
+
+static int
+isValid733Integer(const unsigned char *p)
+{
+	return (p[0] == p[7]
+		&& p[1] == p[6]
+		&& p[2] == p[5]
+		&& p[3] == p[4]);
+}
+
+static int
+isodate7_valid(const unsigned char *v)
+{
+	int year = v[0];
+	int month = v[1];
+	int day = v[2];
+	int hour = v[3];
+	int minute = v[4];
+	int second = v[5];
+	int gmt_off = (signed char)v[6];
+
+	/* ECMA-119 9.1.5 "If all seven values are zero, it shall mean
+	 * that the date is unspecified" */
+	if (year == 0
+	    && month == 0
+	    && day == 0
+	    && hour == 0
+	    && minute == 0
+	    && second == 0
+	    && gmt_off == 0)
+		return 0;
+	/*
+	 * Sanity-test each individual field
+	 */
+	/* Year can have any value */
+	/* Month must be 1-12 */
+	if (month < 1 || month > 12)
+		return 0;
+	/* Day must be 1-31 */
+	if (day < 1 || day > 31)
+		return 0;
+	/* Hour must be 0-23 */
+	if (hour > 23)
+		return 0;
+	/* Minute must be 0-59 */
+	if (minute > 59)
+		return 0;
+	/* second must be 0-59 according to ECMA-119 9.1.5 */
+	/* BUT: we should probably allow for the time being in UTC, which
+	   allows up to 61 seconds in a minute in certain cases */
+	if (second > 61)
+		return 0;
+	/* Offset from GMT must be -48 to +52 */
+	if (gmt_off < -48 || gmt_off > +52)
+		return 0;
+
+	/* All tests pass, this is OK */
+	return 1;
+}
+
 static time_t
 isodate7(const unsigned char *v)
 {
@@ -3153,6 +3343,67 @@ isodate7(const unsigned char *v)
 	return (t);
 }
 
+static int
+isodate17_valid(const unsigned char *v)
+{
+	/* First 16 bytes are all ASCII digits */
+	for (int i = 0; i < 16; i++) {
+		if (v[i] < '0' || v[i] > '9')
+			return 0;
+	}
+
+	int year = (v[0] - '0') * 1000 + (v[1] - '0') * 100
+		+ (v[2] - '0') * 10 + (v[3] - '0');
+	int month = (v[4] - '0') * 10 + (v[5] - '0');
+	int day = (v[6] - '0') * 10 + (v[7] - '0');
+	int hour = (v[8] - '0') * 10 + (v[9] - '0');
+	int minute = (v[10] - '0') * 10 + (v[11] - '0');
+	int second = (v[12] - '0') * 10 + (v[13] - '0');
+	int hundredths = (v[14] - '0') * 10 + (v[15] - '0');
+	int gmt_off = (signed char)v[16];
+
+	if (year == 0 && month == 0 && day == 0
+	    && hour == 0 && minute == 0 && second == 0
+	    && hundredths == 0 && gmt_off == 0)
+		return 0;
+	/*
+	 * Sanity-test each individual field
+	 */
+
+	/* Year must be 1900-2300 */
+	/* (Not specified in ECMA-119, but these seem
+	   like reasonable limits. */
+	if (year < 1900 || year > 2300)
+		return 0;
+	/* Month must be 1-12 */
+	if (month < 1 || month > 12)
+		return 0;
+	/* Day must be 1-31 */
+	if (day < 1 || day > 31)
+		return 0;
+	/* Hour must be 0-23 */
+	if (hour > 23)
+		return 0;
+	/* Minute must be 0-59 */
+	if (minute > 59)
+		return 0;
+	/* second must be 0-59 according to ECMA-119 9.1.5 */
+	/* BUT: we should probably allow for the time being in UTC, which
+	   allows up to 61 seconds in a minute in certain cases */
+	if (second > 61)
+		return 0;
+	/* Hundredths must be 0-99 */
+	if (hundredths > 99)
+		return 0;
+	/* Offset from GMT must be -48 to +52 */
+	if (gmt_off < -48 || gmt_off > +52)
+		return 0;
+
+	/* All tests pass, this is OK */
+	return 1;
+
+}
+
 static time_t
 isodate17(const unsigned char *v)
 {
@@ -3164,7 +3415,7 @@ isodate17(const unsigned char *v)
 	tm.tm_year = (v[0] - '0') * 1000 + (v[1] - '0') * 100
 	    + (v[2] - '0') * 10 + (v[3] - '0')
 	    - 1900;
-	tm.tm_mon = (v[4] - '0') * 10 + (v[5] - '0');
+	tm.tm_mon = (v[4] - '0') * 10 + (v[5] - '0') - 1;
 	tm.tm_mday = (v[6] - '0') * 10 + (v[7] - '0');
 	tm.tm_hour = (v[8] - '0') * 10 + (v[9] - '0');
 	tm.tm_min = (v[10] - '0') * 10 + (v[11] - '0');
Index: src/external/bsd/libarchive/dist/libarchive/archive_write_set_format_ar.c
diff -u src/external/bsd/libarchive/dist/libarchive/archive_write_set_format_ar.c:1.5 src/external/bsd/libarchive/dist/libarchive/archive_write_set_format_ar.c:1.6
--- src/external/bsd/libarchive/dist/libarchive/archive_write_set_format_ar.c:1.5	Sun Jun  9 15:47:55 2024
+++ src/external/bsd/libarchive/dist/libarchive/archive_write_set_format_ar.c	Thu Oct 17 12:42:08 2024
@@ -126,7 +126,7 @@ archive_write_set_format_ar(struct archi
 	if (a->format_free != NULL)
 		(a->format_free)(a);
 
-	ar = (struct ar_w *)calloc(1, sizeof(*ar));
+	ar = calloc(1, sizeof(*ar));
 	if (ar == NULL) {
 		archive_set_error(&a->archive, ENOMEM, "Can't allocate ar data");
 		return (ARCHIVE_FATAL);
@@ -246,7 +246,7 @@ archive_write_ar_header(struct archive_w
 				return (ARCHIVE_WARN);
 			}
 
-			se = (char *)malloc(strlen(filename) + 3);
+			se = malloc(strlen(filename) + 3);
 			if (se == NULL) {
 				archive_set_error(&a->archive, ENOMEM,
 				    "Can't allocate filename buffer");
@@ -379,7 +379,7 @@ archive_write_ar_data(struct archive_wri
 			return (ARCHIVE_WARN);
 		}
 
-		ar->strtab = (char *)malloc(s + 1);
+		ar->strtab = malloc(s + 1);
 		if (ar->strtab == NULL) {
 			archive_set_error(&a->archive, ENOMEM,
 			    "Can't allocate strtab buffer");
Index: src/external/bsd/libarchive/dist/libarchive/archive_write_set_format_shar.c
diff -u src/external/bsd/libarchive/dist/libarchive/archive_write_set_format_shar.c:1.5 src/external/bsd/libarchive/dist/libarchive/archive_write_set_format_shar.c:1.6
--- src/external/bsd/libarchive/dist/libarchive/archive_write_set_format_shar.c:1.5	Sun Jun  9 15:47:55 2024
+++ src/external/bsd/libarchive/dist/libarchive/archive_write_set_format_shar.c	Thu Oct 17 12:42:08 2024
@@ -113,7 +113,7 @@ archive_write_set_format_shar(struct arc
 	if (a->format_free != NULL)
 		(a->format_free)(a);
 
-	shar = (struct shar *)calloc(1, sizeof(*shar));
+	shar = calloc(1, sizeof(*shar));
 	if (shar == NULL) {
 		archive_set_error(&a->archive, ENOMEM, "Can't allocate shar data");
 		return (ARCHIVE_FATAL);
@@ -209,6 +209,10 @@ archive_write_shar_header(struct archive
 	if (archive_entry_filetype(entry) != AE_IFDIR) {
 		/* Try to create the dir. */
 		p = strdup(name);
+		if (p == NULL) {
+			archive_set_error(&a->archive, ENOMEM, "Out of memory");
+			return (ARCHIVE_FATAL);
+		}
 		pp = strrchr(p, '/');
 		/* If there is a / character, try to create the dir. */
 		if (pp != NULL) {
@@ -291,6 +295,10 @@ archive_write_shar_header(struct archive
 			free(shar->last_dir);
 
 			shar->last_dir = strdup(name);
+			if (shar->last_dir == NULL) {
+				archive_set_error(&a->archive, ENOMEM, "Out of memory");
+				return (ARCHIVE_FATAL);
+			}
 			/* Trim a trailing '/'. */
 			pp = strrchr(shar->last_dir, '/');
 			if (pp != NULL && pp[1] == '\0')
Index: src/external/bsd/libarchive/dist/libarchive/archive_write_set_format_ustar.c
diff -u src/external/bsd/libarchive/dist/libarchive/archive_write_set_format_ustar.c:1.5 src/external/bsd/libarchive/dist/libarchive/archive_write_set_format_ustar.c:1.6
--- src/external/bsd/libarchive/dist/libarchive/archive_write_set_format_ustar.c:1.5	Sun Jun  9 15:47:55 2024
+++ src/external/bsd/libarchive/dist/libarchive/archive_write_set_format_ustar.c	Thu Oct 17 12:42:08 2024
@@ -183,7 +183,7 @@ archive_write_set_format_ustar(struct ar
 		return (ARCHIVE_FATAL);
 	}
 
-	ustar = (struct ustar *)calloc(1, sizeof(*ustar));
+	ustar = calloc(1, sizeof(*ustar));
 	if (ustar == NULL) {
 		archive_set_error(&a->archive, ENOMEM,
 		    "Can't allocate ustar data");
@@ -254,7 +254,11 @@ archive_write_ustar_header(struct archiv
 		sconv = ustar->opt_sconv;
 
 	/* Sanity check. */
+#if defined(_WIN32) && !defined(__CYGWIN__)
+	if (archive_entry_pathname_w(entry) == NULL) {
+#else
 	if (archive_entry_pathname(entry) == NULL) {
+#endif
 		archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
 		    "Can't record entry in tar file without pathname");
 		return (ARCHIVE_FAILED);
@@ -263,7 +267,7 @@ archive_write_ustar_header(struct archiv
 	/* Only regular files (not hardlinks) have data. */
 	if (archive_entry_hardlink(entry) != NULL ||
 	    archive_entry_symlink(entry) != NULL ||
-	    !(archive_entry_filetype(entry) == AE_IFREG))
+	    archive_entry_filetype(entry) != AE_IFREG)
 		archive_entry_set_size(entry, 0);
 
 	if (AE_IFDIR == archive_entry_filetype(entry)) {

Index: src/external/bsd/libarchive/dist/libarchive/archive_private.h
diff -u src/external/bsd/libarchive/dist/libarchive/archive_private.h:1.3 src/external/bsd/libarchive/dist/libarchive/archive_private.h:1.4
--- src/external/bsd/libarchive/dist/libarchive/archive_private.h:1.3	Sun Jun  9 15:47:55 2024
+++ src/external/bsd/libarchive/dist/libarchive/archive_private.h	Thu Oct 17 12:42:08 2024
@@ -27,8 +27,10 @@
 #define ARCHIVE_PRIVATE_H_INCLUDED
 
 #ifndef __LIBARCHIVE_BUILD
+#ifndef __LIBARCHIVE_TEST
 #error This header is only to be used internally to libarchive.
 #endif
+#endif
 
 #if HAVE_ICONV_H
 #include <iconv.h>
@@ -158,9 +160,9 @@ __LA_NORETURN void	__archive_errx(int re
 void	__archive_ensure_cloexec_flag(int fd);
 int	__archive_mktemp(const char *tmpdir);
 #if defined(_WIN32) && !defined(__CYGWIN__)
-int	__archive_mkstemp(wchar_t *template);
+int	__archive_mkstemp(wchar_t *templates);
 #else
-int	__archive_mkstemp(char *template);
+int	__archive_mkstemp(char *templates);
 #endif
 
 int	__archive_clean(struct archive *);
Index: src/external/bsd/libarchive/dist/libarchive/archive_read.c
diff -u src/external/bsd/libarchive/dist/libarchive/archive_read.c:1.3 src/external/bsd/libarchive/dist/libarchive/archive_read.c:1.4
--- src/external/bsd/libarchive/dist/libarchive/archive_read.c:1.3	Sun Jun  9 15:47:55 2024
+++ src/external/bsd/libarchive/dist/libarchive/archive_read.c	Thu Oct 17 12:42:08 2024
@@ -92,7 +92,7 @@ archive_read_new(void)
 {
 	struct archive_read *a;
 
-	a = (struct archive_read *)calloc(1, sizeof(*a));
+	a = calloc(1, sizeof(*a));
 	if (a == NULL)
 		return (NULL);
 	a->archive.magic = ARCHIVE_READ_MAGIC;
@@ -582,7 +582,7 @@ choose_filters(struct archive_read *a)
 		}
 
 		filter
-		    = (struct archive_read_filter *)calloc(1, sizeof(*filter));
+		    = calloc(1, sizeof(*filter));
 		if (filter == NULL)
 			return (ARCHIVE_FATAL);
 		filter->bidder = best_bidder;
@@ -1382,7 +1382,7 @@ __archive_read_filter_ahead(struct archi
 		if (filter->client_avail <= 0) {
 			if (filter->end_of_file) {
 				if (avail != NULL)
-					*avail = 0;
+					*avail = filter->avail;
 				return (NULL);
 			}
 			bytes_read = (filter->vtable->read)(filter,
@@ -1451,7 +1451,7 @@ __archive_read_filter_ahead(struct archi
 					s = t;
 				}
 				/* Now s >= min, so allocate a new buffer. */
-				p = (char *)malloc(s);
+				p = malloc(s);
 				if (p == NULL) {
 					archive_set_error(
 						&filter->archive->archive,
Index: src/external/bsd/libarchive/dist/libarchive/archive_read_open_filename.c
diff -u src/external/bsd/libarchive/dist/libarchive/archive_read_open_filename.c:1.3 src/external/bsd/libarchive/dist/libarchive/archive_read_open_filename.c:1.4
--- src/external/bsd/libarchive/dist/libarchive/archive_read_open_filename.c:1.3	Sun Jun  9 15:47:55 2024
+++ src/external/bsd/libarchive/dist/libarchive/archive_read_open_filename.c	Thu Oct 17 12:42:08 2024
@@ -122,7 +122,7 @@ archive_read_open_filenames(struct archi
 	{
 		if (filename == NULL)
 			filename = "";
-		mine = (struct read_file_data *)calloc(1,
+		mine = calloc(1,
 			sizeof(*mine) + strlen(filename));
 		if (mine == NULL)
 			goto no_memory;
@@ -175,7 +175,7 @@ archive_read_open_filenames_w(struct arc
 	{
 		if (wfilename == NULL)
 			wfilename = L"";
-		mine = (struct read_file_data *)calloc(1,
+		mine = calloc(1,
 			sizeof(*mine) + wcslen(wfilename) * sizeof(wchar_t));
 		if (mine == NULL)
 			goto no_memory;
Index: src/external/bsd/libarchive/dist/libarchive/archive_read_support_format_mtree.c
diff -u src/external/bsd/libarchive/dist/libarchive/archive_read_support_format_mtree.c:1.3 src/external/bsd/libarchive/dist/libarchive/archive_read_support_format_mtree.c:1.4
--- src/external/bsd/libarchive/dist/libarchive/archive_read_support_format_mtree.c:1.3	Sun Jun  9 15:47:55 2024
+++ src/external/bsd/libarchive/dist/libarchive/archive_read_support_format_mtree.c	Thu Oct 17 12:42:08 2024
@@ -273,7 +273,7 @@ archive_read_support_format_mtree(struct
 	archive_check_magic(_a, ARCHIVE_READ_MAGIC,
 	    ARCHIVE_STATE_NEW, "archive_read_support_format_mtree");
 
-	mtree = (struct mtree *)calloc(1, sizeof(*mtree));
+	mtree = calloc(1, sizeof(*mtree));
 	if (mtree == NULL) {
 		archive_set_error(&a->archive, ENOMEM,
 		    "Can't allocate mtree data");
Index: src/external/bsd/libarchive/dist/libarchive/archive_read_support_format_xar.c
diff -u src/external/bsd/libarchive/dist/libarchive/archive_read_support_format_xar.c:1.3 src/external/bsd/libarchive/dist/libarchive/archive_read_support_format_xar.c:1.4
--- src/external/bsd/libarchive/dist/libarchive/archive_read_support_format_xar.c:1.3	Sun Jun  9 15:47:55 2024
+++ src/external/bsd/libarchive/dist/libarchive/archive_read_support_format_xar.c	Thu Oct 17 12:42:08 2024
@@ -416,7 +416,7 @@ static void	unknowntag_end(struct xar *,
 static int	xml_start(struct archive_read *,
     const char *, struct xmlattr_list *);
 static void	xml_end(void *, const char *);
-static void	xml_data(void *, const char *, int);
+static void	xml_data(void *, const char *, size_t);
 static int	xml_parse_file_flags(struct xar *, const char *);
 static int	xml_parse_file_ext2(struct xar *, const char *);
 #if defined(HAVE_LIBXML_XMLREADER_H)
@@ -450,7 +450,7 @@ archive_read_support_format_xar(struct a
 	archive_check_magic(_a, ARCHIVE_READ_MAGIC,
 	    ARCHIVE_STATE_NEW, "archive_read_support_format_xar");
 
-	xar = (struct xar *)calloc(1, sizeof(*xar));
+	xar = calloc(1, sizeof(*xar));
 	if (xar == NULL) {
 		archive_set_error(&a->archive, ENOMEM,
 		    "Can't allocate xar data");
@@ -1242,7 +1242,7 @@ heap_add_entry(struct archive_read *a,
 			return (ARCHIVE_FATAL);
 		}
 		new_pending_files = (struct xar_file **)
-		    malloc(new_size * sizeof(new_pending_files[0]));
+		    calloc(new_size, sizeof(new_pending_files[0]));
 		if (new_pending_files == NULL) {
 			archive_set_error(&a->archive,
 			    ENOMEM, "Out of memory");
@@ -1616,9 +1616,9 @@ decompress(struct archive_read *a, const
 	switch (xar->rd_encoding) {
 	case GZIP:
 		xar->stream.next_in = (Bytef *)(uintptr_t)b;
-		xar->stream.avail_in = avail_in;
+		xar->stream.avail_in = (uInt)avail_in;
 		xar->stream.next_out = (unsigned char *)outbuff;
-		xar->stream.avail_out = avail_out;
+		xar->stream.avail_out = (uInt)avail_out;
 		r = inflate(&(xar->stream), 0);
 		switch (r) {
 		case Z_OK: /* Decompressor made some progress.*/
@@ -1635,9 +1635,9 @@ decompress(struct archive_read *a, const
 #if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR)
 	case BZIP2:
 		xar->bzstream.next_in = (char *)(uintptr_t)b;
-		xar->bzstream.avail_in = avail_in;
+		xar->bzstream.avail_in = (unsigned int)avail_in;
 		xar->bzstream.next_out = (char *)outbuff;
-		xar->bzstream.avail_out = avail_out;
+		xar->bzstream.avail_out = (unsigned int)avail_out;
 		r = BZ2_bzDecompress(&(xar->bzstream));
 		switch (r) {
 		case BZ_STREAM_END: /* Found end of stream. */
@@ -2055,9 +2055,10 @@ xml_start(struct archive_read *a, const 
 			    attr = attr->next) {
 				if (strcmp(attr->name, "link") != 0)
 					continue;
-				if (xar->file->hdnext != NULL || xar->file->link != 0) {
+				if (xar->file->hdnext != NULL || xar->file->link != 0 ||
+				    xar->file == xar->hdlink_orgs) {
 					archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
-					    "File with multiple link targets");
+					    "File with multiple link attributes");
 					return (ARCHIVE_FATAL);
 				}
 				if (strcmp(attr->value, "original") == 0) {
@@ -2673,7 +2674,7 @@ is_string(const char *known, const char 
 }
 
 static void
-xml_data(void *userData, const char *s, int len)
+xml_data(void *userData, const char *s, size_t len)
 {
 	struct archive_read *a;
 	struct xar *xar;
@@ -2706,6 +2707,9 @@ xml_data(void *userData, const char *s, 
 
 	switch (xar->xmlsts) {
 	case FILE_NAME:
+		if (xar->file->has & HAS_PATHNAME)
+			break;
+
 		if (xar->file->parent != NULL) {
 			archive_string_concat(&(xar->file->pathname),
 			    &(xar->file->parent->pathname));
@@ -3189,8 +3193,11 @@ xml2_read_toc(struct archive_read *a)
 			if (r == ARCHIVE_OK)
 				r = xml_start(a, name, &list);
 			xmlattr_cleanup(&list);
-			if (r != ARCHIVE_OK)
+			if (r != ARCHIVE_OK) {
+				xmlFreeTextReader(reader);
+				xmlCleanupParser();
 				return (r);
+			}
 			if (empty)
 				xml_end(a, name);
 			break;
@@ -3256,6 +3263,9 @@ expat_start_cb(void *userData, const XML
 	struct xmlattr_list list;
 	int r;
 
+	if (ud->state != ARCHIVE_OK)
+		return;
+
 	r = expat_xmlattr_setup(a, &list, atts);
 	if (r == ARCHIVE_OK)
 		r = xml_start(a, (const char *)name, &list);
@@ -3276,7 +3286,7 @@ expat_data_cb(void *userData, const XML_
 {
 	struct expat_userData *ud = (struct expat_userData *)userData;
 
-	xml_data(ud->archive, s, len);
+	xml_data(ud->archive, s, (size_t)len);
 }
 
 static int
@@ -3312,14 +3322,16 @@ expat_read_toc(struct archive_read *a)
 
 		d = NULL;
 		r = rd_contents(a, &d, &outbytes, &used, xar->toc_remaining);
-		if (r != ARCHIVE_OK)
+		if (r != ARCHIVE_OK) {
+			XML_ParserFree(parser);
 			return (r);
+		}
 		xar->toc_remaining -= used;
 		xar->offset += used;
 		xar->toc_total += outbytes;
 		PRINT_TOC(d, outbytes);
 
-		xr = XML_Parse(parser, d, outbytes, xar->toc_remaining == 0);
+		xr = XML_Parse(parser, d, (int)outbytes, xar->toc_remaining == 0);
 		__archive_read_consume(a, used);
 		if (xr == XML_STATUS_ERROR) {
 			XML_ParserFree(parser);
Index: src/external/bsd/libarchive/dist/libarchive/archive_util.c
diff -u src/external/bsd/libarchive/dist/libarchive/archive_util.c:1.3 src/external/bsd/libarchive/dist/libarchive/archive_util.c:1.4
--- src/external/bsd/libarchive/dist/libarchive/archive_util.c:1.3	Sun Jun  9 15:47:55 2024
+++ src/external/bsd/libarchive/dist/libarchive/archive_util.c	Thu Oct 17 12:42:08 2024
@@ -280,7 +280,8 @@ __archive_mktempx(const char *tmpdir, wc
 			if (archive_wstring_append_from_mbs(&temp_name, tmpdir,
 			    strlen(tmpdir)) < 0)
 				goto exit_tmpfile;
-			if (temp_name.s[temp_name.length-1] != L'/')
+			if (temp_name.length == 0 ||
+			    temp_name.s[temp_name.length-1] != L'/')
 				archive_wstrappend_wchar(&temp_name, L'/');
 		}
 
@@ -454,7 +455,7 @@ get_tempdir(struct archive_string *tempp
                 tmp = "/tmp";
 #endif
 	archive_strcpy(temppath, tmp);
-	if (temppath->s[temppath->length-1] != '/')
+	if (temppath->length == 0 || temppath->s[temppath->length-1] != '/')
 		archive_strappend_char(temppath, '/');
 	return (ARCHIVE_OK);
 }
@@ -477,7 +478,8 @@ __archive_mktemp(const char *tmpdir)
 			goto exit_tmpfile;
 	} else {
 		archive_strcpy(&temp_name, tmpdir);
-		if (temp_name.s[temp_name.length-1] != '/')
+		if (temp_name.length == 0 ||
+		    temp_name.s[temp_name.length-1] != '/')
 			archive_strappend_char(&temp_name, '/');
 	}
 #ifdef O_TMPFILE
@@ -538,7 +540,7 @@ __archive_mktempx(const char *tmpdir, ch
 				goto exit_tmpfile;
 		} else
 			archive_strcpy(&temp_name, tmpdir);
-		if (temp_name.s[temp_name.length-1] == '/') {
+		if (temp_name.length > 0 && temp_name.s[temp_name.length-1] == '/') {
 			temp_name.s[temp_name.length-1] = '\0';
 			temp_name.length --;
 		}
@@ -649,8 +651,7 @@ archive_utility_string_sort_helper(char 
 		if (strcmp(strings[i], pivot) < 0)
 		{
 			lesser_count++;
-			tmp = (char **)realloc(lesser,
-				lesser_count * sizeof(char *));
+			tmp = realloc(lesser, lesser_count * sizeof(*tmp));
 			if (!tmp) {
 				free(greater);
 				free(lesser);
@@ -662,8 +663,7 @@ archive_utility_string_sort_helper(char 
 		else
 		{
 			greater_count++;
-			tmp = (char **)realloc(greater,
-				greater_count * sizeof(char *));
+			tmp = realloc(greater, greater_count * sizeof(*tmp));
 			if (!tmp) {
 				free(greater);
 				free(lesser);

Index: src/external/bsd/libarchive/dist/libarchive/archive_read_disk_entry_from_file.c
diff -u src/external/bsd/libarchive/dist/libarchive/archive_read_disk_entry_from_file.c:1.7 src/external/bsd/libarchive/dist/libarchive/archive_read_disk_entry_from_file.c:1.8
--- src/external/bsd/libarchive/dist/libarchive/archive_read_disk_entry_from_file.c:1.7	Sun Jun  9 15:47:55 2024
+++ src/external/bsd/libarchive/dist/libarchive/archive_read_disk_entry_from_file.c	Thu Oct 17 12:42:08 2024
@@ -520,6 +520,7 @@ setup_xattr(struct archive_read_disk *a,
 	if (size == -1) {
 		archive_set_error(&a->archive, errno,
 		    "Couldn't read extended attribute");
+		free(value);
 		return (ARCHIVE_WARN);
 	}
 
Index: src/external/bsd/libarchive/dist/libarchive/archive_write_disk_posix.c
diff -u src/external/bsd/libarchive/dist/libarchive/archive_write_disk_posix.c:1.7 src/external/bsd/libarchive/dist/libarchive/archive_write_disk_posix.c:1.8
--- src/external/bsd/libarchive/dist/libarchive/archive_write_disk_posix.c:1.7	Sun Jun  9 15:47:55 2024
+++ src/external/bsd/libarchive/dist/libarchive/archive_write_disk_posix.c	Thu Oct 17 12:42:08 2024
@@ -2031,7 +2031,7 @@ archive_write_disk_new(void)
 {
 	struct archive_write_disk *a;
 
-	a = (struct archive_write_disk *)calloc(1, sizeof(*a));
+	a = calloc(1, sizeof(*a));
 	if (a == NULL)
 		return (NULL);
 	a->archive.magic = ARCHIVE_WRITE_DISK_MAGIC;
@@ -2811,7 +2811,7 @@ new_fixup(struct archive_write_disk *a, 
 {
 	struct fixup_entry *fe;
 
-	fe = (struct fixup_entry *)calloc(1, sizeof(struct fixup_entry));
+	fe = calloc(1, sizeof(struct fixup_entry));
 	if (fe == NULL) {
 		archive_set_error(&a->archive, ENOMEM,
 		    "Can't allocate memory for a fixup");
@@ -4260,7 +4260,7 @@ copy_xattrs(struct archive_write_disk *a
 	}
 	for (xattr_i = 0; xattr_i < xattr_size;
 	    xattr_i += strlen(xattr_names + xattr_i) + 1) {
-		char *xattr_val_saved;
+		char *p;
 		ssize_t s;
 		int f;
 
@@ -4271,15 +4271,14 @@ copy_xattrs(struct archive_write_disk *a
 			ret = ARCHIVE_WARN;
 			goto exit_xattr;
 		}
-		xattr_val_saved = xattr_val;
-		xattr_val = realloc(xattr_val, s);
-		if (xattr_val == NULL) {
+		p = realloc(xattr_val, s);
+		if (p == NULL) {
 			archive_set_error(&a->archive, ENOMEM,
 			    "Failed to get metadata(xattr)");
 			ret = ARCHIVE_WARN;
-			free(xattr_val_saved);
 			goto exit_xattr;
 		}
+		xattr_val = p;
 		s = fgetxattr(tmpfd, xattr_names + xattr_i, xattr_val, s, 0, 0);
 		if (s == -1) {
 			archive_set_error(&a->archive, errno,
@@ -4425,8 +4424,7 @@ set_mac_metadata(struct archive_write_di
 	 * silly dance of writing the data to disk just so that
 	 * copyfile() can read it back in again. */
 	archive_string_init(&tmp);
-	archive_strcpy(&tmp, pathname);
-	archive_strcat(&tmp, ".XXXXXX");
+	archive_strcpy(&tmp, "tar.mmd.XXXXXX");
 	fd = mkstemp(tmp.s);
 
 	if (fd < 0) {

Index: src/external/bsd/libarchive/dist/libarchive/test/test_read_format_7zip.c
diff -u src/external/bsd/libarchive/dist/libarchive/test/test_read_format_7zip.c:1.3 src/external/bsd/libarchive/dist/libarchive/test/test_read_format_7zip.c:1.4
--- src/external/bsd/libarchive/dist/libarchive/test/test_read_format_7zip.c:1.3	Sun Jun  9 15:47:56 2024
+++ src/external/bsd/libarchive/dist/libarchive/test/test_read_format_7zip.c	Thu Oct 17 12:42:08 2024
@@ -1050,6 +1050,7 @@ test_arm_filter(const char *refname)
 
 	extract_reference_file(refname);
 
+	assertEqualInt(ARCHIVE_OK, archive_read_free(a));
 	assert((a = archive_read_new()) != NULL);
 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
@@ -1123,6 +1124,7 @@ test_arm64_filter(const char *refname)
 
 	extract_reference_file(refname);
 
+	assertEqualInt(ARCHIVE_OK, archive_read_free(a));
 	assert((a = archive_read_new()) != NULL);
 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
@@ -1257,3 +1259,45 @@ DEFINE_TEST(test_read_format_7zip_win_at
 
 	assertEqualInt(ARCHIVE_OK, archive_read_free(a));
 }
+
+DEFINE_TEST(test_read_format_7zip_extract_second)
+{
+	struct archive *a;
+	char buffer[256];
+
+	assert((a = archive_read_new()) != NULL);
+
+	if (ARCHIVE_OK != archive_read_support_filter_lzma(a)) {
+		skipping(
+		    "7zip:lzma decoding is not supported on this platform");
+		assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+		return;
+	}
+
+	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
+
+	/*
+	 * The test archive has two files: first.txt which is a 65,536 file (the
+	 * size of the uncompressed buffer), and second.txt which has contents
+	 * we will validate. This test ensures we can skip first.txt and still
+	 * be able to read the contents of second.txt
+	 */
+	const char *refname = "test_read_format_7zip_extract_second.7z";
+	extract_reference_file(refname);
+
+	assertEqualIntA(a, ARCHIVE_OK,
+		archive_read_open_filename(a, refname, 10240));
+
+	struct archive_entry *ae;
+
+	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
+	assertEqualString("first.txt", archive_entry_pathname(ae));
+
+	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
+	assertEqualString("second.txt", archive_entry_pathname(ae));
+
+	assertEqualInt(23, archive_read_data(a, buffer, sizeof(buffer)));
+	assertEqualMem("This is from second.txt", buffer, 23);
+
+	assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+}
Index: src/external/bsd/libarchive/dist/libarchive/test/test_read_format_zip_nested.c
diff -u src/external/bsd/libarchive/dist/libarchive/test/test_read_format_zip_nested.c:1.3 src/external/bsd/libarchive/dist/libarchive/test/test_read_format_zip_nested.c:1.4
--- src/external/bsd/libarchive/dist/libarchive/test/test_read_format_zip_nested.c:1.3	Sun Jun  9 15:47:56 2024
+++ src/external/bsd/libarchive/dist/libarchive/test/test_read_format_zip_nested.c	Thu Oct 17 12:42:08 2024
@@ -49,7 +49,7 @@ DEFINE_TEST(test_read_format_zip_nested)
 
 	/* Save contents of inner Zip. */
 	innerLength = (size_t)archive_entry_size(ae);
-	inner = calloc(innerLength, sizeof(char));
+	inner = calloc(innerLength, sizeof(*inner));
 	assertEqualInt(innerLength, archive_read_data(a, inner, innerLength));
 
 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
Index: src/external/bsd/libarchive/dist/libarchive/test/test_read_truncated_filter.c
diff -u src/external/bsd/libarchive/dist/libarchive/test/test_read_truncated_filter.c:1.3 src/external/bsd/libarchive/dist/libarchive/test/test_read_truncated_filter.c:1.4
--- src/external/bsd/libarchive/dist/libarchive/test/test_read_truncated_filter.c:1.3	Sun Jun  9 15:47:56 2024
+++ src/external/bsd/libarchive/dist/libarchive/test/test_read_truncated_filter.c	Thu Oct 17 12:42:08 2024
@@ -43,12 +43,12 @@ test_truncation(const char *compression,
 	int i, r, use_prog;
 
 	buffsize = 2000000;
-	assert(NULL != (buff = (char *)malloc(buffsize)));
+	assert(NULL != (buff = malloc(buffsize)));
 	if (buff == NULL)
 		return;
 
 	datasize = 10000;
-	assert(NULL != (data = (char *)malloc(datasize)));
+	assert(NULL != (data = malloc(datasize)));
 	if (data == NULL) {
 		free(buff);
 		return;

Index: src/external/bsd/libarchive/dist/libarchive/test/test_sparse_basic.c
diff -u src/external/bsd/libarchive/dist/libarchive/test/test_sparse_basic.c:1.4 src/external/bsd/libarchive/dist/libarchive/test/test_sparse_basic.c:1.5
--- src/external/bsd/libarchive/dist/libarchive/test/test_sparse_basic.c:1.4	Sun Jun  9 15:47:56 2024
+++ src/external/bsd/libarchive/dist/libarchive/test/test_sparse_basic.c	Thu Oct 17 12:42:08 2024
@@ -67,13 +67,16 @@ struct sparse {
 
 static void create_sparse_file(const char *, const struct sparse *);
 
-#if defined(__APPLE__)
-/* On APFS holes need to be at least 4096x4097 bytes */
-#define MIN_HOLE 16781312
-#else
-/* Elsewhere we work with 4096*10 bytes */
-#define MIN_HOLE 409600
-#endif
+/* This should be large enough that any OS/filesystem that
+ * does support sparse files is certain to store a gap this big
+ * as a hole. */
+/* A few data points:
+ * = ZFS on FreeBSD needs this to be at least 200kB
+ * = macOS APFS needs this to be at least 4096x4097 bytes
+ *
+ * 32MiB here is bigger than either of the above.
+ */
+#define MIN_HOLE (32 * 1024UL * 1024UL)
 
 #if defined(_WIN32) && !defined(__CYGWIN__)
 #include <winioctl.h>

Index: src/external/bsd/libarchive/dist/tar/bsdtar.c
diff -u src/external/bsd/libarchive/dist/tar/bsdtar.c:1.3 src/external/bsd/libarchive/dist/tar/bsdtar.c:1.4
--- src/external/bsd/libarchive/dist/tar/bsdtar.c:1.3	Sun Jun  9 15:47:56 2024
+++ src/external/bsd/libarchive/dist/tar/bsdtar.c	Thu Oct 17 12:42:08 2024
@@ -1,26 +1,8 @@
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
  * 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 "bsdtar_platform.h"
@@ -43,6 +25,9 @@
 #ifdef HAVE_LANGINFO_H
 #include <langinfo.h>
 #endif
+#ifdef HAVE_LIMITS_H
+#include <limits.h>
+#endif
 #ifdef HAVE_LOCALE_H
 #include <locale.h>
 #endif

Index: src/external/bsd/libarchive/dist/tar/write.c
diff -u src/external/bsd/libarchive/dist/tar/write.c:1.4 src/external/bsd/libarchive/dist/tar/write.c:1.5
--- src/external/bsd/libarchive/dist/tar/write.c:1.4	Sun Jun  9 15:47:56 2024
+++ src/external/bsd/libarchive/dist/tar/write.c	Thu Oct 17 12:42:08 2024
@@ -1,27 +1,9 @@
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
  * Copyright (c) 2003-2007 Tim Kientzle
  * Copyright (c) 2012 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 "bsdtar_platform.h"
@@ -32,7 +14,9 @@
 #ifdef HAVE_SYS_STAT_H
 #include <sys/stat.h>
 #endif
-#ifdef HAVE_ATTR_XATTR_H
+#if HAVE_SYS_XATTR_H
+#include <sys/xattr.h>
+#elif HAVE_ATTR_XATTR_H
 #include <attr/xattr.h>
 #endif
 #ifdef HAVE_ERRNO_H
@@ -944,7 +928,9 @@ write_hierarchy(struct bsdtar *bsdtar, s
 
 		while (entry != NULL) {
 			write_file(bsdtar, a, entry);
-			archive_entry_free(entry);
+			if (entry != spare_entry) {
+				archive_entry_free(entry);
+			}
 			entry = spare_entry;
 			spare_entry = NULL;
 		}

Index: src/external/bsd/libarchive/dist/tar/test/test_basic.c
diff -u src/external/bsd/libarchive/dist/tar/test/test_basic.c:1.3 src/external/bsd/libarchive/dist/tar/test/test_basic.c:1.4
--- src/external/bsd/libarchive/dist/tar/test/test_basic.c:1.3	Sun Jun  9 15:47:56 2024
+++ src/external/bsd/libarchive/dist/tar/test/test_basic.c	Thu Oct 17 12:42:08 2024
@@ -1,26 +1,8 @@
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
  * 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"
 
Index: src/external/bsd/libarchive/dist/tar/test/test_option_C_upper.c
diff -u src/external/bsd/libarchive/dist/tar/test/test_option_C_upper.c:1.3 src/external/bsd/libarchive/dist/tar/test/test_option_C_upper.c:1.4
--- src/external/bsd/libarchive/dist/tar/test/test_option_C_upper.c:1.3	Sun Jun  9 15:47:56 2024
+++ src/external/bsd/libarchive/dist/tar/test/test_option_C_upper.c	Thu Oct 17 12:42:08 2024
@@ -1,26 +1,8 @@
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
  * Copyright (c) 2010 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"
 
Index: src/external/bsd/libarchive/dist/tar/test/test_option_U_upper.c
diff -u src/external/bsd/libarchive/dist/tar/test/test_option_U_upper.c:1.3 src/external/bsd/libarchive/dist/tar/test/test_option_U_upper.c:1.4
--- src/external/bsd/libarchive/dist/tar/test/test_option_U_upper.c:1.3	Sun Jun  9 15:47:56 2024
+++ src/external/bsd/libarchive/dist/tar/test/test_option_U_upper.c	Thu Oct 17 12:42:08 2024
@@ -1,26 +1,8 @@
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
  * Copyright (c) 2010 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"
 
Index: src/external/bsd/libarchive/dist/tar/test/test_option_s.c
diff -u src/external/bsd/libarchive/dist/tar/test/test_option_s.c:1.3 src/external/bsd/libarchive/dist/tar/test/test_option_s.c:1.4
--- src/external/bsd/libarchive/dist/tar/test/test_option_s.c:1.3	Sun Jun  9 15:47:56 2024
+++ src/external/bsd/libarchive/dist/tar/test/test_option_s.c	Thu Oct 17 12:42:08 2024
@@ -1,26 +1,8 @@
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
  * 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"
 
Index: src/external/bsd/libarchive/dist/tar/test/test_symlink_dir.c
diff -u src/external/bsd/libarchive/dist/tar/test/test_symlink_dir.c:1.3 src/external/bsd/libarchive/dist/tar/test/test_symlink_dir.c:1.4
--- src/external/bsd/libarchive/dist/tar/test/test_symlink_dir.c:1.3	Sun Jun  9 15:47:56 2024
+++ src/external/bsd/libarchive/dist/tar/test/test_symlink_dir.c	Thu Oct 17 12:42:08 2024
@@ -1,26 +1,8 @@
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
  * 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"
 

Index: src/external/bsd/libarchive/dist/tar/test/test_copy.c
diff -u src/external/bsd/libarchive/dist/tar/test/test_copy.c:1.4 src/external/bsd/libarchive/dist/tar/test/test_copy.c:1.5
--- src/external/bsd/libarchive/dist/tar/test/test_copy.c:1.4	Sun Jun  9 15:47:56 2024
+++ src/external/bsd/libarchive/dist/tar/test/test_copy.c	Thu Oct 17 12:42:08 2024
@@ -1,26 +1,8 @@
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
  * 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"
 
@@ -190,7 +172,7 @@ create_tree(void)
 #define LIMIT_USTAR 100
 
 static void
-verify_tree(size_t limit)
+verify_tree(size_t limit, const char *format)
 {
 	char name1[260];
 	char name2[260];
@@ -203,6 +185,7 @@ verify_tree(size_t limit)
 		/* Verify a file named "f/abcdef..." */
 		snprintf(name1, sizeof(name1), "f/%s", filenames[i]);
 		if (i <= limit) {
+			failure("Verifying %s", format);
 			assertFileExists(name1);
 			assertFileContents(name1, (int)strlen(name1), name1);
 		}
@@ -210,6 +193,7 @@ verify_tree(size_t limit)
 		snprintf(name2, sizeof(name2), "l/%s", filenames[i]);
 		if (i + 2 <= limit) {
 			/* Verify hardlink "l/abcdef..." */
+			failure("Verifying %s", format);
 			assertIsHardlink(name1, name2);
 			/* Verify hardlink "m/abcdef..." */
 			name2[0] = 'm';
@@ -220,13 +204,16 @@ verify_tree(size_t limit)
 			/* Verify symlink "s/abcdef..." */
 			snprintf(name1, sizeof(name1), "s/%s", filenames[i]);
 			snprintf(name2, sizeof(name2), "../f/%s", filenames[i]);
-			if (strlen(name2) <= limit)
+			if (strlen(name2) <= limit) {
+				failure("Verifying %s", format);
 				assertIsSymlink(name1, name2, 0);
+			}
 		}
 
 		/* Verify dir "d/abcdef...". */
 		snprintf(name1, sizeof(name1), "d/%s", filenames[i]);
 		if (i + 1 <= limit) { /* +1 for trailing slash */
+			failure("Verifying %s", format);
 			if (assertIsDir(name1, -1)) {
 				/* TODO: opendir/readdir this
 				 * directory and make sure
@@ -246,7 +233,7 @@ verify_tree(size_t limit)
 			char dir[2];
 			dir[0] = *dp; dir[1] = '\0';
 			d = opendir(dir);
-			failure("Unable to open dir '%s'", dir);
+			failure("Unable to open dir '%s' for testing %s", dir, format);
 			if (!assert(d != NULL))
 				continue;
 			while ((de = readdir(d)) != NULL) {
@@ -278,25 +265,25 @@ verify_tree(size_t limit)
 }
 
 static void
-copy_basic(void)
+copy_basic(const char *extra_args, const char *name)
 {
 	int r;
 
 	/* NOTE: for proper operation on cygwin-1.5 and windows, the
-	 * length of the name of the directory below, "plain", must be
+	 * length of the name of the directory below must be
 	 * less than or equal to the length of the name of the original
 	 * directory, "original"  This restriction derives from the
 	 * extremely limited pathname lengths on those platforms.
 	 */
-	assertMakeDir("plain", 0775);
-	assertEqualInt(0, chdir("plain"));
+	assertMakeDir(name, 0775);
+	assertEqualInt(0, chdir(name));
 
 	/*
 	 * Use the tar program to create an archive.
 	 */
-	r = systemf("%s cf archive -C ../original f d l m s >pack.out 2>pack.err",
-	    testprog);
-	failure("Error invoking \"%s cf\"", testprog);
+	r = systemf("%s cf archive %s -C ../original f d l m s >pack.out 2>pack.err",
+	    testprog, extra_args);
+	failure("Error invoking \"%s cf archive %s\"", testprog, extra_args);
 	assertEqualInt(r, 0);
 
 	/* Verify that nothing went to stdout or stderr. */
@@ -314,20 +301,7 @@ copy_basic(void)
 	assertEmptyFile("unpack.err");
 	assertEmptyFile("unpack.out");
 
-	verify_tree(LIMIT_NONE);
-
-	/*
-	 * Unpack a second time to make sure that things are still ok
-	 */
-	r = systemf("%s xf archive >unpack.out 2>unpack.err", testprog);
-	failure("Error invoking %s xf archive", testprog);
-	assertEqualInt(r, 0);
-
-	/* Verify that nothing went to stdout or stderr. */
-	assertEmptyFile("unpack.err");
-	assertEmptyFile("unpack.out");
-
-	verify_tree(LIMIT_NONE);
+	verify_tree(LIMIT_NONE, name);
 	assertEqualInt(0, chdir(".."));
 }
 
@@ -370,8 +344,8 @@ copy_ustar(void)
 	assertEmptyFile("unpack.err");
 	assertEmptyFile("unpack.out");
 
-	verify_tree(LIMIT_USTAR);
-	assertEqualInt(0, chdir("../.."));
+	verify_tree(LIMIT_USTAR, "ustar");
+	assertEqualInt(0, chdir(".."));
 }
 
 DEFINE_TEST(test_copy)
@@ -380,8 +354,11 @@ DEFINE_TEST(test_copy)
 	create_tree(); /* Create sample files in "original" dir. */
 
 	/* Test simple "tar -c | tar -x" pipeline copy. */
-	copy_basic();
+	copy_basic("", "default");
 
 	/* Same, but constrain to ustar format. */
 	copy_ustar();
+
+	/* Same, but with pax format. */
+	copy_basic(" --format pax", "pax");
 }

Index: src/external/bsd/libarchive/dist/test_utils/test_common.h
diff -u src/external/bsd/libarchive/dist/test_utils/test_common.h:1.3 src/external/bsd/libarchive/dist/test_utils/test_common.h:1.4
--- src/external/bsd/libarchive/dist/test_utils/test_common.h:1.3	Sun Jun  9 15:47:56 2024
+++ src/external/bsd/libarchive/dist/test_utils/test_common.h	Thu Oct 17 12:42:08 2024
@@ -48,6 +48,9 @@
 #endif
 
 #include <sys/types.h>  /* Windows requires this before sys/stat.h */
+#if !HAVE_SUSECONDS_T
+#define suseconds_t long
+#endif
 #include <sys/stat.h>
 
 #if HAVE_DIRENT_H
@@ -313,7 +316,7 @@ int assertion_non_empty_file(const char 
 int assertion_set_nodump(const char *, int, const char *);
 int assertion_text_file_contents(const char *, int, const char *buff, const char *f);
 int assertion_umask(const char *, int, int);
-int assertion_utimes(const char *, int, const char *, long, long, long, long );
+int assertion_utimes(const char *, int, const char *, time_t, suseconds_t, time_t, suseconds_t);
 int assertion_version(const char*, int, const char *, const char *);
 
 void skipping_setup(const char *, int);
Index: src/external/bsd/libarchive/dist/test_utils/test_main.c
diff -u src/external/bsd/libarchive/dist/test_utils/test_main.c:1.3 src/external/bsd/libarchive/dist/test_utils/test_main.c:1.4
--- src/external/bsd/libarchive/dist/test_utils/test_main.c:1.3	Sun Jun  9 15:47:56 2024
+++ src/external/bsd/libarchive/dist/test_utils/test_main.c	Thu Oct 17 12:42:08 2024
@@ -85,6 +85,10 @@
 #include <membership.h>
 #endif
 
+#ifndef nitems
+#define nitems(arr) (sizeof(arr) / sizeof((arr)[0]))
+#endif
+
 /*
  *
  * Windows support routines
@@ -121,6 +125,8 @@
 #define access _access
 #undef chdir
 #define chdir _chdir
+#undef chmod
+#define chmod _chmod
 #endif
 #ifndef fileno
 #define fileno _fileno
@@ -217,7 +223,8 @@ my_CreateSymbolicLinkA(const char *linkn
 	static BOOLEAN (WINAPI *f)(LPCSTR, LPCSTR, DWORD);
 	DWORD attrs;
 	static int set;
-	int ret, tmpflags, llen, tlen;
+	int ret, tmpflags;
+	size_t llen, tlen;
 	int flags = 0;
 	char *src, *tgt, *p;
 	if (!set) {
@@ -233,10 +240,10 @@ my_CreateSymbolicLinkA(const char *linkn
 	if (tlen == 0 || llen == 0)
 		return (0);
 
-	tgt = malloc((tlen + 1) * sizeof(char));
+	tgt = malloc(tlen + 1);
 	if (tgt == NULL)
 		return (0);
-	src = malloc((llen + 1) * sizeof(char));
+	src = malloc(llen + 1);
 	if (src == NULL) {
 		free(tgt);
 		return (0);
@@ -1237,16 +1244,19 @@ assertion_file_contains_lines_any_order(
 	}
 	expected_count = i;
 	if (expected_count) {
-		expected = malloc(sizeof(char *) * expected_count);
+		expected = calloc(expected_count, sizeof(*expected));
 		if (expected == NULL) {
 			failure_start(pathname, line, "Can't allocate memory");
 			failure_finish(NULL);
-			free(expected);
-			free(buff);
-			return (0);
+			goto cleanup;
 		}
 		for (i = 0; lines[i] != NULL; ++i) {
 			expected[i] = strdup(lines[i]);
+			if (expected[i] == NULL) {
+				failure_start(pathname, line, "Can't allocate memory");
+				failure_finish(NULL);
+				goto cleanup;
+			}
 		}
 	}
 
@@ -1264,9 +1274,7 @@ assertion_file_contains_lines_any_order(
 		if (actual == NULL) {
 			failure_start(pathname, line, "Can't allocate memory");
 			failure_finish(NULL);
-			free(expected);
-			free(buff);
-			return (0);
+			goto cleanup;
 		}
 		for (j = 0, p = buff; p < buff + buff_size;
 		    p += 1 + strlen(p)) {
@@ -1279,8 +1287,6 @@ assertion_file_contains_lines_any_order(
 
 	/* Erase matching lines from both lists */
 	for (i = 0; i < expected_count; ++i) {
-		if (expected[i] == NULL)
-			continue;
 		for (j = 0; j < actual_count; ++j) {
 			if (actual[j] == NULL)
 				continue;
@@ -1303,9 +1309,9 @@ assertion_file_contains_lines_any_order(
 			++actual_failure;
 	}
 	if (expected_failure == 0 && actual_failure == 0) {
-		free(buff);
-		free(expected);
 		free(actual);
+		free(expected);
+		free(buff);
 		return (1);
 	}
 	failure_start(file, line, "File doesn't match: %s", pathname);
@@ -1313,6 +1319,7 @@ assertion_file_contains_lines_any_order(
 		if (expected[i] != NULL) {
 			logprintf("  Expected but not present: %s\n", expected[i]);
 			free(expected[i]);
+			expected[i] = NULL;
 		}
 	}
 	for (j = 0; j < actual_count; ++j) {
@@ -1320,9 +1327,15 @@ assertion_file_contains_lines_any_order(
 			logprintf("  Present but not expected: %s\n", actual[j]);
 	}
 	failure_finish(NULL);
-	free(buff);
-	free(expected);
+cleanup:
 	free(actual);
+	if (expected != NULL) {
+		for (i = 0; i < expected_count; ++i)
+			if (expected[i] != NULL)
+				free(expected[i]);
+		free(expected);
+	}
+	free(buff);
 	return (0);
 }
 
@@ -1766,16 +1779,17 @@ is_symlink(const char *file, int line,
 	    FILE_FLAG_OPEN_REPARSE_POINT;
 
 	/* Replace slashes with backslashes in pathname */
-	pn = malloc((strlen(pathname) + 1) * sizeof(char));
-	p = pathname;
-	s = pn;
-	while(*p != '\0') {
-		if(*p == '/')
+	pn = malloc(strlen(pathname) + 1);
+	if (pn == NULL) {
+		failure_start(file, line, "Can't allocate memory");
+		failure_finish(NULL);
+		return (0);
+	}
+	for (p = pathname, s = pn; *p != '\0'; p++, s++) {
+		if (*p == '/')
 			*s = '\\';
 		else
 			*s = *p;
-		p++;
-		s++;
 	}
 	*s = '\0';
 
@@ -2083,8 +2097,8 @@ assertion_umask(const char *file, int li
 
 /* Set times, report failures. */
 int
-assertion_utimes(const char *file, int line,
-    const char *pathname, long at, long at_nsec, long mt, long mt_nsec)
+assertion_utimes(const char *file, int line, const char *pathname,
+    time_t at, suseconds_t at_nsec, time_t mt, suseconds_t mt_nsec)
 {
 	int r;
 
@@ -2950,7 +2964,6 @@ setTestAcl(const char *path)
 	acl_permset_t permset;
 	const uid_t uid = 1;
 	uuid_t uuid;
-	int i;
 	const acl_perm_t acl_perms[] = {
 		ACL_READ_DATA,
 		ACL_WRITE_DATA,
@@ -2992,7 +3005,7 @@ setTestAcl(const char *path)
 	failure("acl_get_permset() error: %s", strerror(errno));
 	if (assertEqualInt(r, 0) == 0)
 		goto testacl_free;
-	for (i = 0; i < (int)(sizeof(acl_perms) / sizeof(acl_perms[0])); i++) {
+	for (size_t i = 0; i < nitems(acl_perms); i++) {
 		r = acl_add_perm(permset, acl_perms[i]);
 		failure("acl_add_perm() error: %s", strerror(errno));
 		if (assertEqualInt(r, 0) == 0)
@@ -3642,7 +3655,7 @@ test_run(int i, const char *tmpdir)
 static void
 usage(const char *program)
 {
-	static const int limit = sizeof(tests) / sizeof(tests[0]);
+	static const int limit = nitems(tests);
 	int i;
 
 	printf("Usage: %s [options] <test> <test> ...\n", program);
@@ -3874,12 +3887,13 @@ get_test_set(int *test_set, int limit, c
 int
 main(int argc, char **argv)
 {
-	static const int limit = sizeof(tests) / sizeof(tests[0]);
-	int test_set[sizeof(tests) / sizeof(tests[0])];
+	static const int limit = nitems(tests);
+	int test_set[nitems(tests)];
 	int i = 0, j = 0, tests_run = 0, tests_failed = 0, option;
-	int testprogdir_len;
+	size_t testprogdir_len;
+	size_t tmplen;
 #ifdef PROGRAM
-	int tmp2_len;
+	size_t tmp2_len;
 #endif
 	time_t now;
 	struct tm *tmptr;
@@ -3922,7 +3936,7 @@ main(int argc, char **argv)
 	 */
 	progname = p = argv[0];
 	testprogdir_len = strlen(progname) + 1;
-	if ((testprogdir = (char *)malloc(testprogdir_len)) == NULL)
+	if ((testprogdir = malloc(testprogdir_len)) == NULL)
 	{
 		fprintf(stderr, "ERROR: Out of memory.");
 		exit(1);
@@ -3950,7 +3964,7 @@ main(int argc, char **argv)
 #endif
 	{
 		/* Fixup path for relative directories. */
-		if ((testprogdir = (char *)realloc(testprogdir,
+		if ((testprogdir = realloc(testprogdir,
 			strlen(pwd) + 1 + strlen(testprogdir) + 1)) == NULL)
 		{
 			fprintf(stderr, "ERROR: Out of memory.");
@@ -3977,6 +3991,9 @@ main(int argc, char **argv)
 		tmp = getenv("TEMPDIR");
 	else
 		tmp = "/tmp";
+	tmplen = strlen(tmp);
+	while (tmplen > 0 && tmp[tmplen - 1] == '/')
+		tmplen--;
 
 	/* Allow -d to be controlled through the environment. */
 	if (getenv(ENVBASE "_DEBUG") != NULL)
@@ -4070,7 +4087,7 @@ main(int argc, char **argv)
 	if (testprogfile == NULL)
 	{
 		tmp2_len = strlen(testprogdir) + 1 + strlen(PROGRAM) + 1;
-		if ((tmp2 = (char *)malloc(tmp2_len)) == NULL)
+		if ((tmp2 = malloc(tmp2_len)) == NULL)
 		{
 			fprintf(stderr, "ERROR: Out of memory.");
 			exit(1);
@@ -4083,7 +4100,7 @@ main(int argc, char **argv)
 
 	{
 		char *testprg;
-		int testprg_len;
+		size_t testprg_len;
 #if defined(_WIN32) && !defined(__CYGWIN__)
 		/* Command.com sometimes rejects '/' separators. */
 		testprg = strdup(testprogfile);
@@ -4129,16 +4146,16 @@ main(int argc, char **argv)
 #endif
 		strftime(tmpdir_timestamp, sizeof(tmpdir_timestamp),
 		    "%Y-%m-%dT%H.%M.%S", tmptr);
-		if ((strlen(tmp) + 1 + strlen(progname) + 1 +
-		    strlen(tmpdir_timestamp) + 1 + 3) >
-		    (sizeof(tmpdir) / sizeof(char))) {
+		if (tmplen + 1 + strlen(progname) + 1 +
+		    strlen(tmpdir_timestamp) + 1 + 3 >=
+		    nitems(tmpdir)) {
 			fprintf(stderr,
 			    "ERROR: Temp directory pathname too long\n");
 			exit(1);
 		}
-		snprintf(tmpdir, sizeof(tmpdir), "%s/%s.%s-%03d", tmp,
-		    progname, tmpdir_timestamp, i);
-		if (assertMakeDir(tmpdir,0755))
+		snprintf(tmpdir, sizeof(tmpdir), "%.*s/%s.%s-%03d",
+		    (int)tmplen, tmp, progname, tmpdir_timestamp, i);
+		if (assertMakeDir(tmpdir, 0755))
 			break;
 		if (i >= 999) {
 			fprintf(stderr,

Index: src/external/bsd/libarchive/include/config_netbsd.h
diff -u src/external/bsd/libarchive/include/config_netbsd.h:1.13 src/external/bsd/libarchive/include/config_netbsd.h:1.14
--- src/external/bsd/libarchive/include/config_netbsd.h:1.13	Sun Jun  9 15:47:56 2024
+++ src/external/bsd/libarchive/include/config_netbsd.h	Thu Oct 17 12:42:09 2024
@@ -170,16 +170,16 @@
 /* #undef ARCHIVE_XATTR_LINUX */
 
 /* Version number of bsdcat */
-#define BSDCAT_VERSION_STRING "3.7.4"
+#define BSDCAT_VERSION_STRING "3.7.7"
 
 /* Version number of bsdcpio */
-#define BSDCPIO_VERSION_STRING "3.7.4"
+#define BSDCPIO_VERSION_STRING "3.7.7"
 
 /* Version number of bsdtar */
-#define BSDTAR_VERSION_STRING "3.7.4"
+#define BSDTAR_VERSION_STRING "3.7.7"
 
 /* Version number of bsdunzip */
-#define BSDUNZIP_VERSION_STRING "3.7.4"
+#define BSDUNZIP_VERSION_STRING "3.7.7"
 
 /* Define to 1 if the system has the type `ace_t'. */
 /* #undef HAVE_ACE_T */
@@ -698,9 +698,6 @@
 /* Define to 1 if you have the <libxml/xmlwriter.h> header file. */
 /* #undef HAVE_LIBXML_XMLWRITER_H */
 
-/* Define to 1 if you have the `z' library (-lz). */
-#define HAVE_LIBZ 1
-
 /* Define to 1 if you have the `zstd' library (-lzstd). */
 /* #undef HAVE_LIBZSTD */
 
@@ -1122,9 +1119,6 @@
 /* Define to 1 if you have the <sys/poll.h> header file. */
 #define HAVE_SYS_POLL_H 1
 
-/* Define to 1 if you have the <sys/queue.h> header file. */
-#define HAVE_SYS_QUEUE_H 1
-
 /* Define to 1 if you have the <sys/richacl.h> header file. */
 /* #undef HAVE_SYS_RICHACL_H */
 
@@ -1257,7 +1251,7 @@
 /* Define to 1 if you have a working FS_IOC_GETFLAGS */
 /* #undef HAVE_WORKING_FS_IOC_GETFLAGS */
 
-/* Define to 1 if you have the <zlib.h> header file. */
+/* Define to 1 if you have zlib >= 1.2.1 */
 #define HAVE_ZLIB_H 1
 
 /* Define to 1 if you have the <zstd.h> header file. */
@@ -1280,10 +1274,10 @@
 #define ICONV_CONST 
 
 /* Version number of libarchive as a single integer */
-#define LIBARCHIVE_VERSION_NUMBER "3007004"
+#define LIBARCHIVE_VERSION_NUMBER "3007007"
 
 /* Version number of libarchive */
-#define LIBARCHIVE_VERSION_STRING "3.7.4"
+#define LIBARCHIVE_VERSION_STRING "3.7.7"
 
 /* Define to 1 if `lstat' dereferences a symlink specified with a trailing
    slash. */
@@ -1313,7 +1307,7 @@
 #define PACKAGE_NAME "libarchive"
 
 /* Define to the full name and version of this package. */
-#define PACKAGE_STRING "libarchive 3.7.4"
+#define PACKAGE_STRING "libarchive 3.7.7"
 
 /* Define to the one symbol short name of this package. */
 #define PACKAGE_TARNAME "libarchive"
@@ -1322,7 +1316,7 @@
 #define PACKAGE_URL ""
 
 /* Define to the version of this package. */
-#define PACKAGE_VERSION "3.7.4"
+#define PACKAGE_VERSION "3.7.7"
 
 /* Define to 1 if PCRE2_STATIC needs to be defined. */
 /* #undef PCRE2_STATIC */
@@ -1440,7 +1434,7 @@
 
 
 /* Version number of package */
-#define VERSION "3.7.4"
+#define VERSION "3.7.7"
 
 /* Define to '0x0502' for Windows Server 2003 APIs. */
 /* #undef WINVER */

Reply via email to