Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 28 Jul 2018 23:47:22 +0000 (UTC)
From:      Martin Matuska <mm@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-vendor@freebsd.org
Subject:   svn commit: r336851 - in vendor/libarchive/dist: . cat cpio libarchive libarchive/test tar tar/test test_utils
Message-ID:  <201807282347.w6SNlM13034429@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mm
Date: Sat Jul 28 23:47:22 2018
New Revision: 336851
URL: https://svnweb.freebsd.org/changeset/base/336851

Log:
  Update vendor/libarchive/dist to git 2c8c83b9731ff822fad6cc8c670ea5519c366a14
  
  Important vendor changes:
    PR #993: Chdir to -C directory for metalog processing
    OSS-Fuzz #4969: Check size of the extended time field in zip archives
    PR #973: Record informational compression level in gzip header

Added:
  vendor/libarchive/dist/tar/test/test_option_C_mtree.c   (contents, props changed)
Modified:
  vendor/libarchive/dist/.travis.yml
  vendor/libarchive/dist/CMakeLists.txt
  vendor/libarchive/dist/Makefile.am
  vendor/libarchive/dist/cat/bsdcat.c
  vendor/libarchive/dist/cpio/cpio.c
  vendor/libarchive/dist/libarchive/archive_entry.c
  vendor/libarchive/dist/libarchive/archive_entry.h
  vendor/libarchive/dist/libarchive/archive_openssl_hmac_private.h
  vendor/libarchive/dist/libarchive/archive_read.c
  vendor/libarchive/dist/libarchive/archive_read_disk_windows.c
  vendor/libarchive/dist/libarchive/archive_read_support_format_mtree.c
  vendor/libarchive/dist/libarchive/archive_read_support_format_zip.c
  vendor/libarchive/dist/libarchive/archive_virtual.c
  vendor/libarchive/dist/libarchive/archive_write_add_filter_gzip.c
  vendor/libarchive/dist/libarchive/archive_write_disk_windows.c
  vendor/libarchive/dist/libarchive/archive_write_set_format_ar.c
  vendor/libarchive/dist/libarchive/test/test_sparse_basic.c
  vendor/libarchive/dist/libarchive/test/test_write_filter_gzip.c
  vendor/libarchive/dist/libarchive/test/test_write_filter_zstd.c
  vendor/libarchive/dist/tar/bsdtar.c
  vendor/libarchive/dist/tar/test/CMakeLists.txt
  vendor/libarchive/dist/tar/test/test_option_fflags.c
  vendor/libarchive/dist/tar/write.c
  vendor/libarchive/dist/test_utils/test_main.c

Modified: vendor/libarchive/dist/.travis.yml
==============================================================================
--- vendor/libarchive/dist/.travis.yml	Sat Jul 28 23:29:36 2018	(r336850)
+++ vendor/libarchive/dist/.travis.yml	Sat Jul 28 23:47:22 2018	(r336851)
@@ -25,6 +25,6 @@ matrix:
 before_install:
   - if [ `uname` = "Darwin" ]; then brew update; fi
 install:
-  - if [ `uname` = "Darwin" ]; then brew install xz lzop lz4 zstd; fi
+  - if [ `uname` = "Darwin" ]; then brew install xz lz4 zstd; fi
 script:
   - build/ci_build.sh

Modified: vendor/libarchive/dist/CMakeLists.txt
==============================================================================
--- vendor/libarchive/dist/CMakeLists.txt	Sat Jul 28 23:29:36 2018	(r336850)
+++ vendor/libarchive/dist/CMakeLists.txt	Sat Jul 28 23:47:22 2018	(r336851)
@@ -493,7 +493,7 @@ IF(ENABLE_LZO)
   INCLUDE(FindPackageHandleStandardArgs)
   FIND_PACKAGE_HANDLE_STANDARD_ARGS(LZO2 DEFAULT_MSG LZO2_LIBRARY LZO2_INCLUDE_DIR)
 ELSE(ENABLE_LZO)
-  SET(LIBZMA_FOUND FALSE) # Override cached value
+  SET(LZO2_FOUND FALSE) # Override cached value
 ENDIF(ENABLE_LZO)
 IF(LZO2_FOUND)
   SET(HAVE_LIBLZO2 1)

Modified: vendor/libarchive/dist/Makefile.am
==============================================================================
--- vendor/libarchive/dist/Makefile.am	Sat Jul 28 23:29:36 2018	(r336850)
+++ vendor/libarchive/dist/Makefile.am	Sat Jul 28 23:47:22 2018	(r336851)
@@ -972,6 +972,7 @@ bsdtar_test_SOURCES= \
 	tar/test/test_help.c \
 	tar/test/test_leading_slash.c \
 	tar/test/test_missing_file.c \
+	tar/test/test_option_C_mtree.c \
 	tar/test/test_option_C_upper.c \
 	tar/test/test_option_H_upper.c \
 	tar/test/test_option_L_upper.c \

Modified: vendor/libarchive/dist/cat/bsdcat.c
==============================================================================
--- vendor/libarchive/dist/cat/bsdcat.c	Sat Jul 28 23:29:36 2018	(r336850)
+++ vendor/libarchive/dist/cat/bsdcat.c	Sat Jul 28 23:47:22 2018	(r336851)
@@ -61,7 +61,7 @@ usage(FILE *stream, int eval)
 static void
 version(void)
 {
-	printf("bsdcat %s - %s\n",
+	printf("bsdcat %s - %s \n",
 	    BSDCAT_VERSION_STRING,
 	    archive_version_details());
 	exit(0);

Modified: vendor/libarchive/dist/cpio/cpio.c
==============================================================================
--- vendor/libarchive/dist/cpio/cpio.c	Sat Jul 28 23:29:36 2018	(r336850)
+++ vendor/libarchive/dist/cpio/cpio.c	Sat Jul 28 23:47:22 2018	(r336851)
@@ -499,7 +499,7 @@ long_help(void)
 static void
 version(void)
 {
-	fprintf(stdout,"bsdcpio %s - %s\n",
+	fprintf(stdout,"bsdcpio %s - %s \n",
 	    BSDCPIO_VERSION_STRING,
 	    archive_version_details());
 	exit(0);

Modified: vendor/libarchive/dist/libarchive/archive_entry.c
==============================================================================
--- vendor/libarchive/dist/libarchive/archive_entry.c	Sat Jul 28 23:29:36 2018	(r336850)
+++ vendor/libarchive/dist/libarchive/archive_entry.c	Sat Jul 28 23:47:22 2018	(r336851)
@@ -1491,7 +1491,7 @@ archive_entry_acl_next(struct archive_entry *entry, in
  * the style of the generated ACL.
  */
 wchar_t *
-archive_entry_acl_to_text_w(struct archive_entry *entry, ssize_t *len,
+archive_entry_acl_to_text_w(struct archive_entry *entry, la_ssize_t *len,
     int flags)
 {
 	return (archive_acl_to_text_w(&entry->acl, len, flags,
@@ -1499,7 +1499,7 @@ archive_entry_acl_to_text_w(struct archive_entry *entr
 }
 
 char *
-archive_entry_acl_to_text(struct archive_entry *entry, ssize_t *len,
+archive_entry_acl_to_text(struct archive_entry *entry, la_ssize_t *len,
     int flags)
 {
 	return (archive_acl_to_text_l(&entry->acl, len, flags, NULL));

Modified: vendor/libarchive/dist/libarchive/archive_entry.h
==============================================================================
--- vendor/libarchive/dist/libarchive/archive_entry.h	Sat Jul 28 23:29:36 2018	(r336850)
+++ vendor/libarchive/dist/libarchive/archive_entry.h	Sat Jul 28 23:47:22 2018	(r336851)
@@ -42,6 +42,7 @@
 
 #include <sys/types.h>
 #include <stddef.h>  /* for wchar_t */
+#include <stdint.h>
 #include <time.h>
 
 #if defined(_WIN32) && !defined(__CYGWIN__)

Modified: vendor/libarchive/dist/libarchive/archive_openssl_hmac_private.h
==============================================================================
--- vendor/libarchive/dist/libarchive/archive_openssl_hmac_private.h	Sat Jul 28 23:29:36 2018	(r336850)
+++ vendor/libarchive/dist/libarchive/archive_openssl_hmac_private.h	Sat Jul 28 23:47:22 2018	(r336851)
@@ -28,7 +28,8 @@
 #include <openssl/hmac.h>
 #include <openssl/opensslv.h>
 
-#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
+#if OPENSSL_VERSION_NUMBER < 0x10100000L || \
+	(defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x20700000L)
 #include <stdlib.h> /* malloc, free */
 #include <string.h> /* memset */
 static inline HMAC_CTX *HMAC_CTX_new(void)

Modified: vendor/libarchive/dist/libarchive/archive_read.c
==============================================================================
--- vendor/libarchive/dist/libarchive/archive_read.c	Sat Jul 28 23:29:36 2018	(r336850)
+++ vendor/libarchive/dist/libarchive/archive_read.c	Sat Jul 28 23:47:22 2018	(r336851)
@@ -821,7 +821,7 @@ archive_read_format_capabilities(struct archive *_a)
  * DO NOT intermingle calls to this function and archive_read_data_block
  * to read a single entry body.
  */
-ssize_t
+la_ssize_t
 archive_read_data(struct archive *_a, void *buff, size_t s)
 {
 	struct archive *a = (struct archive *)_a;

Modified: vendor/libarchive/dist/libarchive/archive_read_disk_windows.c
==============================================================================
--- vendor/libarchive/dist/libarchive/archive_read_disk_windows.c	Sat Jul 28 23:29:36 2018	(r336850)
+++ vendor/libarchive/dist/libarchive/archive_read_disk_windows.c	Sat Jul 28 23:47:22 2018	(r336851)
@@ -117,7 +117,7 @@ struct filesystem {
  */
 
 #define MAX_OVERLAPPED	8
-#define BUFFER_SIZE	(1024 * 8)
+#define READ_BUFFER_SIZE	(1024 * 64) /* Default to 64KB per https://technet.microsoft.com/en-us/library/cc938632.aspx */
 #define DIRECT_IO	0/* Disabled */
 #define ASYNC_IO	1/* Enabled */
 
@@ -567,7 +567,7 @@ start_next_async_read(struct archive_read_disk *a, str
 	/* Allocate read buffer. */
 	if (olp->buff == NULL) {
 		void *p;
-		size_t s = (size_t)align_num_per_sector(t, BUFFER_SIZE);
+		size_t s = (size_t)align_num_per_sector(t, READ_BUFFER_SIZE);
 		p = VirtualAlloc(NULL, s, MEM_COMMIT, PAGE_READWRITE);
 		if (p == NULL) {
 			archive_set_error(&a->archive, ENOMEM,
@@ -683,7 +683,7 @@ _archive_read_data_block(struct archive *_a, const voi
 				break;
 		} while (r == ARCHIVE_OK && t->ol_num_doing < MAX_OVERLAPPED);
 	} else {
-		if (start_next_async_read(a, t) == ARCHIVE_FATAL)
+		if ((r = start_next_async_read(a, t)) == ARCHIVE_FATAL)
 			goto abort_read_data;
 	}
 
@@ -2276,10 +2276,10 @@ setup_sparse_from_disk(struct archive_read_disk *a,
 				if (range.Length.QuadPart > 0)
 					continue;
 			} else {
-				/* The remaining data is hole. */
+				/* The entire file is a hole. Add one data block of size 0 at the end. */
 				archive_entry_sparse_add_entry(entry,
-				    range.FileOffset.QuadPart,
-				    range.Length.QuadPart);
+				    entry_size,
+				    0);
 			}
 			break;
 		} else {

Modified: vendor/libarchive/dist/libarchive/archive_read_support_format_mtree.c
==============================================================================
--- vendor/libarchive/dist/libarchive/archive_read_support_format_mtree.c	Sat Jul 28 23:29:36 2018	(r336850)
+++ vendor/libarchive/dist/libarchive/archive_read_support_format_mtree.c	Sat Jul 28 23:47:22 2018	(r336851)
@@ -49,6 +49,7 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_read_s
 #include "archive.h"
 #include "archive_entry.h"
 #include "archive_private.h"
+#include "archive_rb.h"
 #include "archive_read_private.h"
 #include "archive_string.h"
 #include "archive_pack_dev.h"
@@ -75,8 +76,6 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_read_s
 #define	MTREE_HAS_OPTIONAL	0x0800
 #define	MTREE_HAS_NOCHANGE	0x1000 /* FreeBSD specific */
 
-#define	MTREE_HASHTABLE_SIZE 1024
-
 #define	MAX_LINE_LEN		(1024 * 1024)
 
 struct mtree_option {
@@ -85,13 +84,13 @@ struct mtree_option {
 };
 
 struct mtree_entry {
+	struct archive_rb_node rbnode;
+	struct mtree_entry *next_dup;
 	struct mtree_entry *next;
 	struct mtree_option *options;
 	char *name;
 	char full;
 	char used;
-	unsigned int name_hash;
-	struct mtree_entry *hashtable_next;
 };
 
 struct mtree {
@@ -104,11 +103,12 @@ struct mtree {
 	const char		*archive_format_name;
 	struct mtree_entry	*entries;
 	struct mtree_entry	*this_entry;
-	struct mtree_entry	*entry_hashtable[MTREE_HASHTABLE_SIZE];
+	struct archive_rb_tree	 entry_rbtree;
 	struct archive_string	 current_dir;
 	struct archive_string	 contents_name;
 
 	struct archive_entry_linkresolver *resolver;
+	struct archive_rb_tree rbtree;
 
 	int64_t			 cur_size;
 	char checkfs;
@@ -117,7 +117,6 @@ struct mtree {
 static int	bid_keycmp(const char *, const char *, ssize_t);
 static int	cleanup(struct archive_read *);
 static int	detect_form(struct archive_read *, int *);
-static unsigned int	hash(const char *);
 static int	mtree_bid(struct archive_read *, int);
 static int	parse_file(struct archive_read *, struct archive_entry *,
 		    struct mtree *, struct mtree_entry *, int *);
@@ -219,9 +218,30 @@ free_options(struct mtree_option *head)
 	}
 }
 
+static int
+mtree_cmp_node(const struct archive_rb_node *n1,
+    const struct archive_rb_node *n2)
+{
+	const struct mtree_entry *e1 = (const struct mtree_entry *)n1;
+	const struct mtree_entry *e2 = (const struct mtree_entry *)n2;
+
+	return (strcmp(e1->name, e2->name));
+}
+
+static int
+mtree_cmp_key(const struct archive_rb_node *n, const void *key)
+{
+	const struct mtree_entry *e = (const struct mtree_entry *)n;
+
+	return (strcmp(e->name, key));
+}
+
 int
 archive_read_support_format_mtree(struct archive *_a)
 {
+	static const struct archive_rb_tree_ops rb_ops = {
+		mtree_cmp_node, mtree_cmp_key,
+	};
 	struct archive_read *a = (struct archive_read *)_a;
 	struct mtree *mtree;
 	int r;
@@ -237,6 +257,8 @@ archive_read_support_format_mtree(struct archive *_a)
 	}
 	mtree->fd = -1;
 
+	__archive_rb_tree_init(&mtree->rbtree, &rb_ops);
+
 	r = __archive_read_register_format(a, mtree, "mtree",
            mtree_bid, archive_read_format_mtree_options, read_header, read_data, skip, NULL, cleanup, NULL, NULL);
 
@@ -875,12 +897,11 @@ process_add_entry(struct archive_read *a, struct mtree
     struct mtree_option **global, const char *line, ssize_t line_len,
     struct mtree_entry **last_entry, int is_form_d)
 {
-	struct mtree_entry *entry, *ht_iter;
+	struct mtree_entry *entry;
 	struct mtree_option *iter;
 	const char *next, *eq, *name, *end;
 	size_t name_len, len;
 	int r, i;
-	unsigned int ht_idx;
 
 	if ((entry = malloc(sizeof(*entry))) == NULL) {
 		archive_set_error(&a->archive, errno, "Can't allocate memory");
@@ -891,8 +912,6 @@ process_add_entry(struct archive_read *a, struct mtree
 	entry->name = NULL;
 	entry->used = 0;
 	entry->full = 0;
-	entry->name_hash = 0;
-	entry->hashtable_next = NULL;
 
 	/* Add this entry to list. */
 	if (*last_entry == NULL)
@@ -945,15 +964,17 @@ process_add_entry(struct archive_read *a, struct mtree
 	memcpy(entry->name, name, name_len);
 	entry->name[name_len] = '\0';
 	parse_escapes(entry->name, entry);
-	entry->name_hash = hash(entry->name);
 
-	ht_idx = entry->name_hash % MTREE_HASHTABLE_SIZE;
-	if ((ht_iter = mtree->entry_hashtable[ht_idx]) != NULL) {
-		while (ht_iter->hashtable_next)
-			ht_iter = ht_iter->hashtable_next;
-		ht_iter->hashtable_next = entry;
-	} else {
-		mtree->entry_hashtable[ht_idx] = entry;
+	entry->next_dup = NULL;
+	if (entry->full) {
+		if (!__archive_rb_tree_insert_node(&mtree->rbtree, &entry->rbnode)) {
+			struct mtree_entry *alt;
+			alt = (struct mtree_entry *)__archive_rb_tree_find_node(
+			    &mtree->rbtree, entry->name);
+			while (alt->next_dup)
+				alt = alt->next_dup;
+			alt->next_dup = entry;
+		}
 	}
 
 	for (iter = *global; iter != NULL; iter = iter->next) {
@@ -1148,14 +1169,13 @@ parse_file(struct archive_read *a, struct archive_entr
 		 * with pathname canonicalization, which is a very
 		 * tricky subject.)
 		 */
-		for (mp = mentry->hashtable_next; mp != NULL; mp = mp->hashtable_next) {
-			if (mp->full && !mp->used
-					&& mentry->name_hash == mp->name_hash
-					&& strcmp(mentry->name, mp->name) == 0) {
+		mp = (struct mtree_entry *)__archive_rb_tree_find_node(
+		    &mtree->rbtree, mentry->name);
+		for (; mp; mp = mp->next_dup) {
+			if (mp->full && !mp->used) {
 				/* Later lines override earlier ones. */
 				mp->used = 1;
-				r1 = parse_line(a, entry, mtree, mp,
-				    &parsed_kws);
+				r1 = parse_line(a, entry, mtree, mp, &parsed_kws);
 				if (r1 < r)
 					r = r1;
 			}
@@ -1988,20 +2008,4 @@ readline(struct archive_read *a, struct mtree *mtree, 
 		}
 		find_off = u - mtree->line.s;
 	}
-}
-
-static unsigned int
-hash(const char *p)
-{
-	/* A 32-bit version of Peter Weinberger's (PJW) hash algorithm,
-	   as used by ELF for hashing function names. */
-	unsigned g, h = 0;
-	while (*p != '\0') {
-		h = (h << 4) + *p++;
-		if ((g = h & 0xF0000000) != 0) {
-			h ^= g >> 24;
-			h &= 0x0FFFFFFF;
-		}
-	}
-	return h;
 }

Modified: vendor/libarchive/dist/libarchive/archive_read_support_format_zip.c
==============================================================================
--- vendor/libarchive/dist/libarchive/archive_read_support_format_zip.c	Sat Jul 28 23:29:36 2018	(r336850)
+++ vendor/libarchive/dist/libarchive/archive_read_support_format_zip.c	Sat Jul 28 23:47:22 2018	(r336851)
@@ -511,7 +511,13 @@ process_extra(struct archive_read *a, const char *p, s
 		case 0x5455:
 		{
 			/* Extended time field "UT". */
-			int flags = p[offset];
+			int flags;
+			if (datasize == 0) {
+				archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+				    "Incomplete extended time field");
+				return ARCHIVE_FAILED;
+			}
+			flags = p[offset];
 			offset++;
 			datasize--;
 			/* Flag bits indicate which dates are present. */

Modified: vendor/libarchive/dist/libarchive/archive_virtual.c
==============================================================================
--- vendor/libarchive/dist/libarchive/archive_virtual.c	Sat Jul 28 23:29:36 2018	(r336850)
+++ vendor/libarchive/dist/libarchive/archive_virtual.c	Sat Jul 28 23:47:22 2018	(r336851)
@@ -124,13 +124,13 @@ archive_write_finish_entry(struct archive *a)
 	return ((a->vtable->archive_write_finish_entry)(a));
 }
 
-ssize_t
+la_ssize_t
 archive_write_data(struct archive *a, const void *buff, size_t s)
 {
 	return ((a->vtable->archive_write_data)(a, buff, s));
 }
 
-ssize_t
+la_ssize_t
 archive_write_data_block(struct archive *a, const void *buff, size_t s,
     la_int64_t o)
 {

Modified: vendor/libarchive/dist/libarchive/archive_write_add_filter_gzip.c
==============================================================================
--- vendor/libarchive/dist/libarchive/archive_write_add_filter_gzip.c	Sat Jul 28 23:29:36 2018	(r336850)
+++ vendor/libarchive/dist/libarchive/archive_write_add_filter_gzip.c	Sat Jul 28 23:47:22 2018	(r336851)
@@ -226,7 +226,12 @@ archive_compressor_gzip_open(struct archive_write_filt
 		data->compressed[7] = (uint8_t)(t>>24)&0xff;
 	} else
 		memset(&data->compressed[4], 0, 4);
-	data->compressed[8] = 0; /* No deflate options */
+    if (data->compression_level == 9)
+	    data->compressed[8] = 2;
+    else if(data->compression_level == 1)
+	    data->compressed[8] = 4;
+    else
+	    data->compressed[8] = 0;
 	data->compressed[9] = 3; /* OS=Unix */
 	data->stream.next_out += 10;
 	data->stream.avail_out -= 10;

Modified: vendor/libarchive/dist/libarchive/archive_write_disk_windows.c
==============================================================================
--- vendor/libarchive/dist/libarchive/archive_write_disk_windows.c	Sat Jul 28 23:29:36 2018	(r336850)
+++ vendor/libarchive/dist/libarchive/archive_write_disk_windows.c	Sat Jul 28 23:47:22 2018	(r336851)
@@ -1322,6 +1322,13 @@ restore_entry(struct archive_write_disk *a)
 		}
 	}
 
+	if ((en == ENOENT) && (archive_entry_hardlink(a->entry) != NULL)) {
+		archive_set_error(&a->archive, en,
+			"Hard-link target '%s' does not exist.",
+			archive_entry_hardlink(a->entry));
+		return (ARCHIVE_FAILED);
+	}
+
 	if ((en == EISDIR || en == EEXIST)
 	    && (a->flags & ARCHIVE_EXTRACT_NO_OVERWRITE)) {
 		/* If we're not overwriting, we're done. */

Modified: vendor/libarchive/dist/libarchive/archive_write_set_format_ar.c
==============================================================================
--- vendor/libarchive/dist/libarchive/archive_write_set_format_ar.c	Sat Jul 28 23:29:36 2018	(r336850)
+++ vendor/libarchive/dist/libarchive/archive_write_set_format_ar.c	Sat Jul 28 23:47:22 2018	(r336851)
@@ -180,7 +180,7 @@ archive_write_ar_header(struct archive_write *a, struc
 	}
 
 	memset(buff, ' ', 60);
-	strncpy(&buff[AR_fmag_offset], "`\n", 2);
+	memcpy(&buff[AR_fmag_offset], "`\n", 2);
 
 	if (strcmp(pathname, "/") == 0 ) {
 		/* Entry is archive symbol table in GNU format */
@@ -189,7 +189,7 @@ archive_write_ar_header(struct archive_write *a, struc
 	}
 	if (strcmp(pathname, "__.SYMDEF") == 0) {
 		/* Entry is archive symbol table in BSD format */
-		strncpy(buff + AR_name_offset, "__.SYMDEF", 9);
+		memcpy(buff + AR_name_offset, "__.SYMDEF", 9);
 		goto stat;
 	}
 	if (strcmp(pathname, "//") == 0) {
@@ -225,7 +225,7 @@ archive_write_ar_header(struct archive_write *a, struc
 		 * actually 15 bytes.
 		 */
 		if (strlen(filename) <= 15) {
-			strncpy(&buff[AR_name_offset], 
+			memcpy(&buff[AR_name_offset],
 			    filename, strlen(filename));
 			buff[AR_name_offset + strlen(filename)] = '/';
 		} else {
@@ -248,7 +248,7 @@ archive_write_ar_header(struct archive_write *a, struc
 				return (ARCHIVE_FATAL);
 			}
 
-			strncpy(se, filename, strlen(filename));
+			memcpy(se, filename, strlen(filename));
 			strcpy(se + strlen(filename), "/\n");
 
 			ss = strstr(ar->strtab, se);
@@ -285,11 +285,11 @@ archive_write_ar_header(struct archive_write *a, struc
 		 * archive header.
 		 */
 		if (strlen(filename) <= 16 && strchr(filename, ' ') == NULL) {
-			strncpy(&buff[AR_name_offset], filename, strlen(filename));
+			memcpy(&buff[AR_name_offset], filename, strlen(filename));
 			buff[AR_name_offset + strlen(filename)] = ' ';
 		}
 		else {
-			strncpy(buff + AR_name_offset, "#1/", 3);
+			memcpy(buff + AR_name_offset, "#1/", 3);
 			if (format_decimal(strlen(filename),
 			    buff + AR_name_offset + 3,
 			    AR_name_size - 3)) {

Modified: vendor/libarchive/dist/libarchive/test/test_sparse_basic.c
==============================================================================
--- vendor/libarchive/dist/libarchive/test/test_sparse_basic.c	Sat Jul 28 23:29:36 2018	(r336850)
+++ vendor/libarchive/dist/libarchive/test/test_sparse_basic.c	Sat Jul 28 23:47:22 2018	(r336851)
@@ -118,13 +118,26 @@ create_sparse_file(const char *path, const struct spar
 	assert(handle != INVALID_HANDLE_VALUE);
 	assert(DeviceIoControl(handle, FSCTL_SET_SPARSE, NULL, 0,
 	    NULL, 0, &dmy, NULL) != 0);
+
+	size_t offsetSoFar = 0;
+
 	while (s->type != END) {
 		if (s->type == HOLE) {
-			LARGE_INTEGER distance;
+			LARGE_INTEGER fileOffset, beyondOffset, distanceToMove;
+			fileOffset.QuadPart = offsetSoFar;
+			beyondOffset.QuadPart = offsetSoFar + s->size;
+			distanceToMove.QuadPart = s->size;
 
-			distance.QuadPart = s->size;
-			assert(SetFilePointerEx(handle, distance,
-			    NULL, FILE_CURRENT) != 0);
+			FILE_ZERO_DATA_INFORMATION zeroInformation;
+			zeroInformation.FileOffset = fileOffset;
+			zeroInformation.BeyondFinalZero = beyondOffset;
+
+			DWORD bytesReturned;
+			assert(SetFilePointerEx(handle, distanceToMove,
+				NULL, FILE_CURRENT) != 0);
+			assert(SetEndOfFile(handle) != 0);
+			assert(DeviceIoControl(handle, FSCTL_SET_ZERO_DATA, &zeroInformation,
+				sizeof(FILE_ZERO_DATA_INFORMATION), NULL, 0, &bytesReturned, NULL) != 0);
 		} else {
 			DWORD w, wr;
 			size_t size;
@@ -139,6 +152,7 @@ create_sparse_file(const char *path, const struct spar
 				size -= wr;
 			}
 		}
+		offsetSoFar += s->size;
 		s++;
 	}
 	assertEqualInt(CloseHandle(handle), 1);
@@ -484,10 +498,15 @@ DEFINE_TEST(test_sparse_basic)
 	 * on all platform.
 	 */
 	const struct sparse sparse_file0[] = {
+		// 0             // 1024
 		{ DATA,	 1024 }, { HOLE,   2048000 },
+		// 2049024       // 2051072
 		{ DATA,	 2048 }, { HOLE,   2048000 },
+		// 4099072       // 4103168
 		{ DATA,	 4096 }, { HOLE,  20480000 },
+		// 24583168      // 24591360
 		{ DATA,	 8192 }, { HOLE, 204800000 },
+		// 229391360     // 229391361
 		{ DATA,     1 }, { END,	0 }
 	};
 	const struct sparse sparse_file1[] = {

Modified: vendor/libarchive/dist/libarchive/test/test_write_filter_gzip.c
==============================================================================
--- vendor/libarchive/dist/libarchive/test/test_write_filter_gzip.c	Sat Jul 28 23:29:36 2018	(r336850)
+++ vendor/libarchive/dist/libarchive/test/test_write_filter_gzip.c	Sat Jul 28 23:47:22 2018	(r336851)
@@ -39,6 +39,7 @@ DEFINE_TEST(test_write_filter_gzip)
 	struct archive* a;
 	char *buff, *data;
 	size_t buffsize, datasize;
+	unsigned char *rbuff;
 	char path[16];
 	size_t used1, used2;
 	int i, r, use_prog = 0;
@@ -58,6 +59,7 @@ DEFINE_TEST(test_write_filter_gzip)
 
 	/*
 	 * Write a 100 files and read them all back.
+	 * Use default compression level (6).
 	 */
 	assert((a = archive_write_new()) != NULL);
 	assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a));
@@ -93,6 +95,14 @@ DEFINE_TEST(test_write_filter_gzip)
 	assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a));
 	assertEqualInt(ARCHIVE_OK, archive_write_free(a));
 
+	/* Basic gzip header tests */
+	rbuff = (unsigned char *)buff;
+	assertEqualInt(rbuff[0], 0x1f);
+	assertEqualInt(rbuff[1], 0x8b);
+	assertEqualInt(rbuff[2], 0x08);
+	assertEqualInt(rbuff[3], 0x00);
+	assertEqualInt(rbuff[8], 0); /* RFC 1952 flag for compression level 6 */
+
 	assert((a = archive_read_new()) != NULL);
 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
 	r = archive_read_support_filter_gzip(a);
@@ -116,7 +126,7 @@ DEFINE_TEST(test_write_filter_gzip)
 
 	/*
 	 * Repeat the cycle again, this time setting some compression
-	 * options.
+	 * options. Compression level is 9.
 	 */
 	assert((a = archive_write_new()) != NULL);
 	assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a));
@@ -150,6 +160,14 @@ DEFINE_TEST(test_write_filter_gzip)
 	assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a));
 	assertEqualInt(ARCHIVE_OK, archive_write_free(a));
 
+	/* Basic gzip header tests */
+	rbuff = (unsigned char *)buff;
+	assertEqualInt(rbuff[0], 0x1f);
+	assertEqualInt(rbuff[1], 0x8b);
+	assertEqualInt(rbuff[2], 0x08);
+	assertEqualInt(rbuff[3], 0x00);
+	assertEqualInt(rbuff[8], 2); /* RFC 1952 flag for compression level 9 */
+
 	/* Curiously, this test fails; the test data above compresses
 	 * better at default compression than at level 9. */
 	/*
@@ -181,7 +199,7 @@ DEFINE_TEST(test_write_filter_gzip)
 	assertEqualInt(ARCHIVE_OK, archive_read_free(a));
 
 	/*
-	 * Repeat again, with much lower compression.
+	 * Repeat again, with compression level 1
 	 */
 	assert((a = archive_write_new()) != NULL);
 	assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a));
@@ -212,6 +230,14 @@ DEFINE_TEST(test_write_filter_gzip)
 	failure("Compression-level=1 wrote %d bytes; default wrote %d bytes",
 	    (int)used2, (int)used1);
 	assert(used2 > used1);
+
+	/* Basic gzip header tests */
+	rbuff = (unsigned char *)buff;
+	assertEqualInt(rbuff[0], 0x1f);
+	assertEqualInt(rbuff[1], 0x8b);
+	assertEqualInt(rbuff[2], 0x08);
+	assertEqualInt(rbuff[3], 0x00);
+	assertEqualInt(rbuff[8], 4); /* RFC 1952 flag for compression level 1 */
 
 	assert((a = archive_read_new()) != NULL);
 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));

Modified: vendor/libarchive/dist/libarchive/test/test_write_filter_zstd.c
==============================================================================
--- vendor/libarchive/dist/libarchive/test/test_write_filter_zstd.c	Sat Jul 28 23:29:36 2018	(r336850)
+++ vendor/libarchive/dist/libarchive/test/test_write_filter_zstd.c	Sat Jul 28 23:47:22 2018	(r336851)
@@ -125,7 +125,7 @@ DEFINE_TEST(test_write_filter_zstd)
 	assertEqualIntA(a, ARCHIVE_OK,
 	    archive_write_set_filter_option(a, NULL, "compression-level", "9"));
 	assertEqualIntA(a, ARCHIVE_OK,
-	    archive_write_set_filter_option(a, NULL, "compression-level", "15"));
+	    archive_write_set_filter_option(a, NULL, "compression-level", "6"));
 	assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2));
 	for (i = 0; i < 100; i++) {
 		sprintf(path, "file%03d", i);
@@ -140,7 +140,7 @@ DEFINE_TEST(test_write_filter_zstd)
 	assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a));
 	assertEqualInt(ARCHIVE_OK, archive_write_free(a));
 
-	failure("compression-level=15 wrote %d bytes, default wrote %d bytes",
+	failure("compression-level=6 wrote %d bytes, default wrote %d bytes",
 	    (int)used2, (int)used1);
 	assert(used2 < used1);
 

Modified: vendor/libarchive/dist/tar/bsdtar.c
==============================================================================
--- vendor/libarchive/dist/tar/bsdtar.c	Sat Jul 28 23:29:36 2018	(r336850)
+++ vendor/libarchive/dist/tar/bsdtar.c	Sat Jul 28 23:47:22 2018	(r336851)
@@ -920,7 +920,7 @@ usage(void)
 static void
 version(void)
 {
-	printf("bsdtar %s - %s\n",
+	printf("bsdtar %s - %s \n",
 	    BSDTAR_VERSION_STRING,
 	    archive_version_details());
 	exit(0);

Modified: vendor/libarchive/dist/tar/test/CMakeLists.txt
==============================================================================
--- vendor/libarchive/dist/tar/test/CMakeLists.txt	Sat Jul 28 23:29:36 2018	(r336850)
+++ vendor/libarchive/dist/tar/test/CMakeLists.txt	Sat Jul 28 23:47:22 2018	(r336851)
@@ -28,6 +28,7 @@ IF(ENABLE_TAR AND ENABLE_TEST)
     test_leading_slash.c
     test_missing_file.c
     test_option_C_upper.c
+    test_option_C_mtree.c
     test_option_H_upper.c
     test_option_L_upper.c
     test_option_O_upper.c

Added: vendor/libarchive/dist/tar/test/test_option_C_mtree.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ vendor/libarchive/dist/tar/test/test_option_C_mtree.c	Sat Jul 28 23:47:22 2018	(r336851)
@@ -0,0 +1,73 @@
+/*-
+ * Copyright (c) 2018 The FreeBSD Foundation
+ * All rights reserved.
+ * 
+ * This software was developed by Arshan Khanifar <arshankhanifar@gmail.com>
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+__FBSDID("$FreeBSD$");
+
+DEFINE_TEST(test_option_C_mtree)
+{
+	char *p0;
+	size_t s;
+	int r;
+	p0 = NULL;
+	char *content = "./foo type=file uname=root gname=root mode=0755\n";
+	char *filename = "output.tar";
+
+	/* an absolute path to mtree file */ 
+	char *mtree_file = "/METALOG.mtree";	
+	char *absolute_path = malloc(strlen(testworkdir) + strlen(mtree_file) + 1);
+	strcpy(absolute_path, testworkdir);
+	strcat(absolute_path, mtree_file );
+	
+	/* Create an archive using an mtree file. */
+	assertMakeFile(absolute_path, 0777, content);
+	assertMakeDir("bar", 0775);
+	assertMakeFile("bar/foo", 0777, "abc");
+
+	r = systemf("%s -cf %s -C bar \"@%s\" >step1.out 2>step1.err", testprog, filename, absolute_path);
+
+	failure("Error invoking %s -cf %s -C bar @%s", testprog, filename, absolute_path);
+	assertEqualInt(r, 0);
+	assertEmptyFile("step1.out");
+	assertEmptyFile("step1.err");
+
+	/* Do validation of the constructed archive. */
+
+	p0 = slurpfile(&s, "output.tar");
+	if (!assert(p0 != NULL))
+		goto done;
+	if (!assert(s >= 2048))
+		goto done;
+	assertEqualMem(p0 + 0, "./foo", 5);
+	assertEqualMem(p0 + 512, "abc", 3);
+	assertEqualMem(p0 + 1024, "\0\0\0\0\0\0\0\0", 8);
+	assertEqualMem(p0 + 1536, "\0\0\0\0\0\0\0\0", 8);
+done:
+	free(p0);
+}
+
+

Modified: vendor/libarchive/dist/tar/test/test_option_fflags.c
==============================================================================
--- vendor/libarchive/dist/tar/test/test_option_fflags.c	Sat Jul 28 23:29:36 2018	(r336850)
+++ vendor/libarchive/dist/tar/test/test_option_fflags.c	Sat Jul 28 23:47:22 2018	(r336851)
@@ -25,6 +25,10 @@
 #include "test.h"
 __FBSDID("$FreeBSD$");
 
+#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__BORLANDC__)
+#define chmod _chmod
+#endif
+
 static void
 clear_fflags(const char *pathname)
 {

Modified: vendor/libarchive/dist/tar/write.c
==============================================================================
--- vendor/libarchive/dist/tar/write.c	Sat Jul 28 23:29:36 2018	(r336850)
+++ vendor/libarchive/dist/tar/write.c	Sat Jul 28 23:47:22 2018	(r336851)
@@ -503,7 +503,7 @@ write_archive(struct archive *a, struct bsdtar *bsdtar
 			}
 			set_chdir(bsdtar, arg);
 		} else {
-			if (*arg != '/' && (arg[0] != '@' || arg[1] != '/'))
+			if (*arg != '/')
 				do_chdir(bsdtar); /* Handle a deferred -C */
 			if (*arg == '@') {
 				if (append_archive_filename(bsdtar, a,

Modified: vendor/libarchive/dist/test_utils/test_main.c
==============================================================================
--- vendor/libarchive/dist/test_utils/test_main.c	Sat Jul 28 23:29:36 2018	(r336850)
+++ vendor/libarchive/dist/test_utils/test_main.c	Sat Jul 28 23:47:22 2018	(r336851)
@@ -2115,7 +2115,7 @@ void assertVersion(const char *prog, const char *base)
 	int r;
 	char *p, *q;
 	size_t s;
-	unsigned int prog_len = strlen(base);
+	size_t prog_len = strlen(base);
 
 	r = systemf("%s --version >version.stdout 2>version.stderr", prog);
 	if (r != 0)



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