Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 10 Aug 2011 08:40:59 +0000 (UTC)
From:      Martin Matuska <mm@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org
Subject:   svn commit: r224752 - in stable/8/lib/libarchive: . test
Message-ID:  <201108100840.p7A8exid032790@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mm
Date: Wed Aug 10 08:40:59 2011
New Revision: 224752
URL: http://svn.freebsd.org/changeset/base/224752

Log:
  MFC r224691, r224700 [1]:
  
  MFC r224961:
  Add compatibility for ISO images created with unfixed makefs that
  violated ECMA-119 (ISO9660): allow reserved4 to be 0x20 in PVD.
  This allows tar to read FreeBSD distribution ISO images created
  with makefs prior to NetBSD bin/45217 bugfix (up to 9.0-BETA1).
  
  In addition, merge following important bugfixes from
  libarchive's release/2.8 branch:
  
  Revision 2812:
  Merge 2811 from trunk:  Don't try to verify that compression-level=0
  produces larger results than the default compression, since this isn't
  true for all versions of liblzma.
  
  Revision 2817:
  Merge 2814 from trunk: Fix Issue 121 (mtree parser error)
  http://code.google.com/p/libarchive/issues/detail?id=121
  
  Revision 2820:
  Fix issue 119.
  Change the file location check that a file location does not exceed
  volume block. New one is that a file content does not exceed volume
  block(end of an ISO image). It is better than previous check even
  if the issue did not happen.
  
  While reading an ISO image generated by an older version of mkisofs
  utility, a file location indicates the end the ISO image if its file
  size is zero and it is the last file of all files of the ISO image,
  so it is possible that the location value is the same as the number
  of the total block of the ISO image.
  
  http://code.google.com/p/libarchive/issues/detail?id=119
  
  Revision 2955:
  Issue 134:  Fix libarchive 2.8 crashing in archive_write_finish() when
  the open has failed and we're trying to write Zip format.
  
  http://code.google.com/p/libarchive/issues/detail?id=134
  
  Revision 2958:
  Followup on Issue 134:
   1) Port test_open_failure to libarchive 2.8 branch to test
      the problem reported in Issue 134.
      This test also shows that archive_read_open() sometimes
      fails to report open errors correctly.
   2) Fix the bug in archive_read.c
   3) Comment out the tests that close functions are invoked
      promptly when open fails; that's fully fixed in libarchive 3.0,
      but I don't think it's worth fixing here.
  
  Revision 3484:
  Use uintmax_t with %ju
  
  Revision 3487:
  Fix issue 163.
  Correctly allocate enough memory for a input buffer saved.
  
  http://code.google.com/p/libarchive/issues/detail?id=163
  
  Revision 3542:
  Merge 2516, 2536 from trunk:  Allow path table offset values of
  0 and 18, which are used by some ISO writers.
  
  MFC r224700 [1]:
  Merge revision 3554 from libarchive's release/2.8 branch:
  
  Partial merge of 2431 from trunk:  Retry writes on EINTR.
  This should fix the SIGINT handler in bsdtar.
  Note:  The rest of r2431 can't be merged, since it interacts
  with a big write-side rearchitecture.
  
  PR:		bin/149409 [1]
  Reviewed by:	kientzle

Added:
  stable/8/lib/libarchive/test/test_open_failure.c
     - copied unchanged from r224691, head/lib/libarchive/test/test_open_failure.c
Modified:
  stable/8/lib/libarchive/archive_read.c
  stable/8/lib/libarchive/archive_read_support_compression_uu.c
  stable/8/lib/libarchive/archive_read_support_format_iso9660.c
  stable/8/lib/libarchive/archive_read_support_format_mtree.c
  stable/8/lib/libarchive/archive_write_open_fd.c
  stable/8/lib/libarchive/archive_write_open_file.c
  stable/8/lib/libarchive/archive_write_open_filename.c
  stable/8/lib/libarchive/archive_write_set_compression_xz.c
  stable/8/lib/libarchive/archive_write_set_format_zip.c
  stable/8/lib/libarchive/test/Makefile
  stable/8/lib/libarchive/test/test_read_format_mtree.c
  stable/8/lib/libarchive/test/test_write_compress_lzma.c
  stable/8/lib/libarchive/test/test_write_compress_xz.c
Directory Properties:
  stable/8/lib/libarchive/   (props changed)

Modified: stable/8/lib/libarchive/archive_read.c
==============================================================================
--- stable/8/lib/libarchive/archive_read.c	Wed Aug 10 08:34:00 2011	(r224751)
+++ stable/8/lib/libarchive/archive_read.c	Wed Aug 10 08:40:59 2011	(r224752)
@@ -377,6 +377,12 @@ build_stream(struct archive_read *a)
 
 		/* If no bidder, we're done. */
 		if (best_bidder == NULL) {
+			/* Verify the final pipelin by asking it for some data. */
+			__archive_read_filter_ahead(a->filter, 1, &avail);
+			if (avail < 0) {
+				cleanup_filters(a);
+				return (ARCHIVE_FATAL);
+			}
 			a->archive.compression_name = a->filter->name;
 			a->archive.compression_code = a->filter->code;
 			return (ARCHIVE_OK);
@@ -389,17 +395,11 @@ build_stream(struct archive_read *a)
 		filter->bidder = best_bidder;
 		filter->archive = a;
 		filter->upstream = a->filter;
-		r = (best_bidder->init)(filter);
-		if (r != ARCHIVE_OK) {
-			free(filter);
-			return (r);
-		}
 		a->filter = filter;
-		/* Verify the filter by asking it for some data. */
-		__archive_read_filter_ahead(filter, 1, &avail);
-		if (avail < 0) {
+		r = (best_bidder->init)(a->filter);
+		if (r != ARCHIVE_OK) {
 			cleanup_filters(a);
-			return (ARCHIVE_FATAL);
+			return (r);
 		}
 	}
 }

Modified: stable/8/lib/libarchive/archive_read_support_compression_uu.c
==============================================================================
--- stable/8/lib/libarchive/archive_read_support_compression_uu.c	Wed Aug 10 08:34:00 2011	(r224751)
+++ stable/8/lib/libarchive/archive_read_support_compression_uu.c	Wed Aug 10 08:40:59 2011	(r224752)
@@ -381,7 +381,17 @@ ensure_in_buff_size(struct archive_read_
 		unsigned char *ptr;
 		size_t newsize;
 
-		newsize = uudecode->in_allocated << 1;
+		/*
+		 * Calculate a new buffer size for in_buff.
+		 * Increase its value until it has enough size we need.
+		 */
+		newsize = uudecode->in_allocated;
+		do {
+			if (newsize < IN_BUFF_SIZE*32)
+				newsize <<= 1;
+			else
+				newsize += IN_BUFF_SIZE;
+		} while (size > newsize);
 		ptr = malloc(newsize);
 		if (ptr == NULL ||
 		    newsize < uudecode->in_allocated) {

Modified: stable/8/lib/libarchive/archive_read_support_format_iso9660.c
==============================================================================
--- stable/8/lib/libarchive/archive_read_support_format_iso9660.c	Wed Aug 10 08:34:00 2011	(r224751)
+++ stable/8/lib/libarchive/archive_read_support_format_iso9660.c	Wed Aug 10 08:40:59 2011	(r224752)
@@ -709,16 +709,18 @@ isSVD(struct iso9660 *iso9660, const uns
 
 	/* Location of Occurrence of Type L Path Table must be
 	 * available location,
-	 * > SYSTEM_AREA_BLOCK(16) + 2 and < Volume Space Size. */
+	 * >= SYSTEM_AREA_BLOCK(16) + 2 and < Volume Space Size. */
 	location = archive_le32dec(h+SVD_type_L_path_table_offset);
-	if (location <= SYSTEM_AREA_BLOCK+2 || location >= volume_block)
+	if (location < SYSTEM_AREA_BLOCK+2 || location >= volume_block)
 		return (0);
 
-	/* Location of Occurrence of Type M Path Table must be
-	 * available location,
-	 * > SYSTEM_AREA_BLOCK(16) + 2 and < Volume Space Size. */
+	/* The Type M Path Table must be at a valid location (WinISO
+	 * and probably other programs omit this, so we allow zero)
+	 *
+	 * >= SYSTEM_AREA_BLOCK(16) + 2 and < Volume Space Size. */
 	location = archive_be32dec(h+SVD_type_M_path_table_offset);
-	if (location <= SYSTEM_AREA_BLOCK+2 || location >= volume_block)
+	if ((location > 0 && location < SYSTEM_AREA_BLOCK+2)
+	    || location >= volume_block)
 		return (0);
 
 	/* Read Root Directory Record in Volume Descriptor. */
@@ -781,16 +783,17 @@ isEVD(struct iso9660 *iso9660, const uns
 
 	/* Location of Occurrence of Type L Path Table must be
 	 * available location,
-	 * > SYSTEM_AREA_BLOCK(16) + 2 and < Volume Space Size. */
+	 * >= SYSTEM_AREA_BLOCK(16) + 2 and < Volume Space Size. */
 	location = archive_le32dec(h+PVD_type_1_path_table_offset);
-	if (location <= SYSTEM_AREA_BLOCK+2 || location >= volume_block)
+	if (location < SYSTEM_AREA_BLOCK+2 || location >= volume_block)
 		return (0);
 
 	/* Location of Occurrence of Type M Path Table must be
 	 * available location,
-	 * > SYSTEM_AREA_BLOCK(16) + 2 and < Volume Space Size. */
+	 * >= SYSTEM_AREA_BLOCK(16) + 2 and < Volume Space Size. */
 	location = archive_be32dec(h+PVD_type_m_path_table_offset);
-	if (location <= SYSTEM_AREA_BLOCK+2 || location >= volume_block)
+	if ((location > 0 && location < SYSTEM_AREA_BLOCK+2)
+	    || location >= volume_block)
 		return (0);
 
 	/* Reserved field must be 0. */
@@ -862,19 +865,24 @@ isPVD(struct iso9660 *iso9660, const uns
 	 * available location,
 	 * > SYSTEM_AREA_BLOCK(16) + 2 and < Volume Space Size. */
 	location = archive_le32dec(h+PVD_type_1_path_table_offset);
-	if (location <= SYSTEM_AREA_BLOCK+2 || location >= volume_block)
+	if (location < SYSTEM_AREA_BLOCK+2 || location >= volume_block)
 		return (0);
 
-	/* Location of Occurrence of Type M Path Table must be
-	 * available location,
-	 * > SYSTEM_AREA_BLOCK(16) + 2 and < Volume Space Size. */
+	/* The Type M Path Table must also be at a valid location
+	 * (although ECMA 119 requires a Type M Path Table, WinISO and
+	 * probably other programs omit it, so we permit a zero here)
+	 *
+	 * >= SYSTEM_AREA_BLOCK(16) + 2 and < Volume Space Size. */
 	location = archive_be32dec(h+PVD_type_m_path_table_offset);
-	if (location <= SYSTEM_AREA_BLOCK+2 || location >= volume_block)
+	if ((location > 0 && location < SYSTEM_AREA_BLOCK+2)
+	    || location >= volume_block)
 		return (0);
 
 	/* Reserved field must be 0. */
+	/* FreeBSD: makefs erroneously created images with 0x20 */
 	for (i = 0; i < PVD_reserved4_size; ++i)
-		if (h[PVD_reserved4_offset + i] != 0)
+		if (h[PVD_reserved4_offset + i] != 0 &&
+		    h[PVD_reserved4_offset + i] != 32)
 			return (0);
 
 	/* Reserved field must be 0. */
@@ -1677,6 +1685,7 @@ parse_file_info(struct archive_read *a, 
 	const unsigned char *rr_start, *rr_end;
 	const unsigned char *p;
 	size_t dr_len;
+	uint64_t fsize;
 	int32_t location;
 	int flags;
 
@@ -1685,6 +1694,7 @@ parse_file_info(struct archive_read *a, 
 	dr_len = (size_t)isodirrec[DR_length_offset];
 	name_len = (size_t)isodirrec[DR_name_len_offset];
 	location = archive_le32dec(isodirrec + DR_extent_offset);
+	fsize = toi(isodirrec + DR_size_offset, DR_size_size);
 	/* Sanity check that dr_len needs at least 34. */
 	if (dr_len < 34) {
 		archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
@@ -1703,7 +1713,10 @@ parse_file_info(struct archive_read *a, 
 	 * link or file size is zero. As far as I know latest mkisofs
 	 * do that.
 	 */
-	if (location >= iso9660->volume_block) {
+	if (location > 0 &&
+	    (location + ((fsize + iso9660->logical_block_size -1)
+	       / iso9660->logical_block_size)) >
+	      (unsigned int)iso9660->volume_block) {
 		archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
 		    "Invalid location of extent of file");
 		return (NULL);
@@ -1719,7 +1732,7 @@ parse_file_info(struct archive_read *a, 
 	memset(file, 0, sizeof(*file));
 	file->parent = parent;
 	file->offset = iso9660->logical_block_size * (uint64_t)location;
-	file->size = toi(isodirrec + DR_size_offset, DR_size_size);
+	file->size = fsize;
 	file->mtime = isodate7(isodirrec + DR_date_offset);
 	file->ctime = file->atime = file->mtime;
 

Modified: stable/8/lib/libarchive/archive_read_support_format_mtree.c
==============================================================================
--- stable/8/lib/libarchive/archive_read_support_format_mtree.c	Wed Aug 10 08:34:00 2011	(r224751)
+++ stable/8/lib/libarchive/archive_read_support_format_mtree.c	Wed Aug 10 08:40:59 2011	(r224752)
@@ -525,6 +525,7 @@ parse_file(struct archive_read *a, struc
 	/* Initialize reasonable defaults. */
 	mtree->filetype = AE_IFREG;
 	archive_entry_set_size(entry, 0);
+	archive_string_empty(&mtree->contents_name);
 
 	/* Parse options from this line. */
 	parsed_kws = 0;
@@ -613,9 +614,8 @@ parse_file(struct archive_read *a, struc
 	}
 
 	/*
-	 * If there is a contents file on disk, use that size;
-	 * otherwise leave it as-is (it might have been set from
-	 * the mtree size= keyword).
+	 * Check for a mismatch between the type in the specification and
+	 * the type of the contents object on disk.
 	 */
 	if (st != NULL) {
 		mismatched_type = 0;
@@ -660,6 +660,11 @@ parse_file(struct archive_read *a, struc
 		}
 	}
 
+	/*
+	 * If there is a contents file on disk, pick some of the metadata
+	 * from that file.  For most of these, we only set it from the contents
+	 * if it wasn't already parsed from the specification.
+	 */
 	if (st != NULL) {
 		if ((parsed_kws & MTREE_HAS_DEVICE) == 0 &&
 		    (archive_entry_filetype(entry) == AE_IFCHR ||

Modified: stable/8/lib/libarchive/archive_write_open_fd.c
==============================================================================
--- stable/8/lib/libarchive/archive_write_open_fd.c	Wed Aug 10 08:34:00 2011	(r224751)
+++ stable/8/lib/libarchive/archive_write_open_fd.c	Wed Aug 10 08:40:59 2011	(r224752)
@@ -51,7 +51,6 @@ __FBSDID("$FreeBSD$");
 #include "archive.h"
 
 struct write_fd_data {
-	off_t		offset;
 	int		fd;
 };
 
@@ -122,12 +121,16 @@ file_write(struct archive *a, void *clie
 	ssize_t	bytesWritten;
 
 	mine = (struct write_fd_data *)client_data;
-	bytesWritten = write(mine->fd, buff, length);
-	if (bytesWritten <= 0) {
-		archive_set_error(a, errno, "Write error");
-		return (-1);
+	for (;;) {
+		bytesWritten = write(mine->fd, buff, length);
+		if (bytesWritten <= 0) {
+			if (errno == EINTR)
+				continue;
+			archive_set_error(a, errno, "Write error");
+			return (-1);
+		}
+		return (bytesWritten);
 	}
-	return (bytesWritten);
 }
 
 static int

Modified: stable/8/lib/libarchive/archive_write_open_file.c
==============================================================================
--- stable/8/lib/libarchive/archive_write_open_file.c	Wed Aug 10 08:34:00 2011	(r224751)
+++ stable/8/lib/libarchive/archive_write_open_file.c	Wed Aug 10 08:40:59 2011	(r224752)
@@ -86,12 +86,16 @@ file_write(struct archive *a, void *clie
 	size_t	bytesWritten;
 
 	mine = client_data;
-	bytesWritten = fwrite(buff, 1, length, mine->f);
-	if (bytesWritten < length) {
-		archive_set_error(a, errno, "Write error");
-		return (-1);
+	for (;;) {
+		bytesWritten = fwrite(buff, 1, length, mine->f);
+		if (bytesWritten <= 0) {
+			if (errno == EINTR)
+				continue;
+			archive_set_error(a, errno, "Write error");
+			return (-1);
+		}
+		return (bytesWritten);
 	}
-	return (bytesWritten);
 }
 
 static int

Modified: stable/8/lib/libarchive/archive_write_open_filename.c
==============================================================================
--- stable/8/lib/libarchive/archive_write_open_filename.c	Wed Aug 10 08:34:00 2011	(r224751)
+++ stable/8/lib/libarchive/archive_write_open_filename.c	Wed Aug 10 08:40:59 2011	(r224752)
@@ -142,12 +142,16 @@ file_write(struct archive *a, void *clie
 	ssize_t	bytesWritten;
 
 	mine = (struct write_file_data *)client_data;
-	bytesWritten = write(mine->fd, buff, length);
-	if (bytesWritten <= 0) {
-		archive_set_error(a, errno, "Write error");
-		return (-1);
+	for (;;) {
+		bytesWritten = write(mine->fd, buff, length);
+		if (bytesWritten <= 0) {
+			if (errno == EINTR)
+				continue;
+			archive_set_error(a, errno, "Write error");
+			return (-1);
+		}
+		return (bytesWritten);
 	}
-	return (bytesWritten);
 }
 
 static int

Modified: stable/8/lib/libarchive/archive_write_set_compression_xz.c
==============================================================================
--- stable/8/lib/libarchive/archive_write_set_compression_xz.c	Wed Aug 10 08:34:00 2011	(r224751)
+++ stable/8/lib/libarchive/archive_write_set_compression_xz.c	Wed Aug 10 08:40:59 2011	(r224752)
@@ -421,8 +421,8 @@ drive_compressor(struct archive_write *a
 			archive_set_error(&a->archive, ENOMEM,
 			    "lzma compression error: "
 			    "%ju MiB would have been needed",
-			    (lzma_memusage(&(state->stream)) + 1024 * 1024 -1)
-			    / (1024 * 1024));
+			    (uintmax_t)((lzma_memusage(&(state->stream)) + 1024 * 1024 -1)
+				/ (1024 * 1024)));
 			return (ARCHIVE_FATAL);
 		default:
 			/* Any other return value indicates an error. */

Modified: stable/8/lib/libarchive/archive_write_set_format_zip.c
==============================================================================
--- stable/8/lib/libarchive/archive_write_set_format_zip.c	Wed Aug 10 08:34:00 2011	(r224751)
+++ stable/8/lib/libarchive/archive_write_set_format_zip.c	Wed Aug 10 08:40:59 2011	(r224752)
@@ -502,6 +502,9 @@ archive_write_zip_finish(struct archive_
 	int entries;
 	int ret;
 
+	if (a->compressor.write == NULL)
+		return (ARCHIVE_OK);
+
 	zip = a->format_data;
 	l = zip->central_directory;
 

Modified: stable/8/lib/libarchive/test/Makefile
==============================================================================
--- stable/8/lib/libarchive/test/Makefile	Wed Aug 10 08:34:00 2011	(r224751)
+++ stable/8/lib/libarchive/test/Makefile	Wed Aug 10 08:40:59 2011	(r224752)
@@ -25,6 +25,7 @@ TESTS= \
 	test_fuzz.c				\
 	test_link_resolver.c			\
 	test_open_fd.c				\
+	test_open_failure.c			\
 	test_open_file.c			\
 	test_open_filename.c			\
 	test_pax_filename_encoding.c		\

Copied: stable/8/lib/libarchive/test/test_open_failure.c (from r224691, head/lib/libarchive/test/test_open_failure.c)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/8/lib/libarchive/test/test_open_failure.c	Wed Aug 10 08:40:59 2011	(r224752, copy of r224691, head/lib/libarchive/test/test_open_failure.c)
@@ -0,0 +1,198 @@
+/*-
+ * Copyright (c) 2003-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"
+__FBSDID("$FreeBSD$");
+
+#define MAGIC 123456789
+struct my_data {
+	int magic;
+	int read_return;
+	int read_called;
+	int write_return;
+	int write_called;
+	int open_return;
+	int open_called;
+	int close_return;
+	int close_called;
+};
+
+static ssize_t
+my_read(struct archive *a, void *_private, const void **buff)
+{
+	struct my_data *private = (struct my_data *)_private;
+	assertEqualInt(MAGIC, private->magic);
+	++private->read_called;
+	return (private->read_return);
+}
+
+static ssize_t
+my_write(struct archive *a, void *_private, const void *buff, size_t s)
+{
+	struct my_data *private = (struct my_data *)_private;
+	assertEqualInt(MAGIC, private->magic);
+	++private->write_called;
+	return (private->write_return);
+}
+
+static int
+my_open(struct archive *a, void *_private)
+{
+	struct my_data *private = (struct my_data *)_private;
+	assertEqualInt(MAGIC, private->magic);
+	++private->open_called;
+	return (private->open_return);
+}
+
+static int
+my_close(struct archive *a, void *_private)
+{
+	struct my_data *private = (struct my_data *)_private;
+	assertEqualInt(MAGIC, private->magic);
+	++private->close_called;
+	return (private->close_return);
+}
+
+
+DEFINE_TEST(test_open_failure)
+{
+	struct archive *a;
+	struct my_data private;
+
+	memset(&private, 0, sizeof(private));
+	private.magic = MAGIC;
+	private.open_return = ARCHIVE_FATAL;
+	a = archive_read_new();
+	assert(a != NULL);
+	assertEqualInt(ARCHIVE_FATAL,
+	    archive_read_open(a, &private, my_open, my_read, my_close));
+	assertEqualInt(1, private.open_called);
+	assertEqualInt(0, private.read_called);
+	assertEqualInt(1, private.close_called);
+	assertEqualInt(ARCHIVE_OK, archive_read_finish(a));
+	assertEqualInt(1, private.open_called);
+	assertEqualInt(0, private.read_called);
+	assertEqualInt(1, private.close_called);
+
+	memset(&private, 0, sizeof(private));
+	private.magic = MAGIC;
+	private.open_return = ARCHIVE_FAILED;
+	a = archive_read_new();
+	assert(a != NULL);
+	assertEqualInt(ARCHIVE_FAILED,
+	    archive_read_open(a, &private, my_open, my_read, my_close));
+	assertEqualInt(1, private.open_called);
+	assertEqualInt(0, private.read_called);
+	assertEqualInt(1, private.close_called);
+	assertEqualInt(ARCHIVE_OK, archive_read_finish(a));
+	assertEqualInt(1, private.open_called);
+	assertEqualInt(0, private.read_called);
+	assertEqualInt(1, private.close_called);
+
+	memset(&private, 0, sizeof(private));
+	private.magic = MAGIC;
+	private.open_return = ARCHIVE_WARN;
+	a = archive_read_new();
+	assert(a != NULL);
+	assertEqualInt(ARCHIVE_WARN,
+	    archive_read_open(a, &private, my_open, my_read, my_close));
+	assertEqualInt(1, private.open_called);
+	assertEqualInt(0, private.read_called);
+	assertEqualInt(1, private.close_called);
+	assertEqualInt(ARCHIVE_OK, archive_read_finish(a));
+	assertEqualInt(1, private.open_called);
+	assertEqualInt(0, private.read_called);
+	assertEqualInt(1, private.close_called);
+
+	memset(&private, 0, sizeof(private));
+	private.magic = MAGIC;
+	private.open_return = ARCHIVE_OK;
+	private.read_return = ARCHIVE_FATAL;
+	a = archive_read_new();
+	assert(a != NULL);
+	assertEqualInt(ARCHIVE_OK,
+	    archive_read_support_compression_compress(a));
+	assertEqualInt(ARCHIVE_OK, archive_read_support_format_tar(a));
+	assertEqualInt(ARCHIVE_FATAL,
+	    archive_read_open(a, &private, my_open, my_read, my_close));
+	assertEqualInt(1, private.open_called);
+	assertEqualInt(1, private.read_called);
+	assertEqualInt(1, private.close_called);
+	assertEqualInt(ARCHIVE_OK, archive_read_finish(a));
+	assertEqualInt(1, private.open_called);
+	assertEqualInt(1, private.read_called);
+	assertEqualInt(1, private.close_called);
+
+	memset(&private, 0, sizeof(private));
+	private.magic = MAGIC;
+	private.open_return = ARCHIVE_FATAL;
+	a = archive_write_new();
+	assert(a != NULL);
+	assertEqualInt(ARCHIVE_FATAL,
+	    archive_write_open(a, &private, my_open, my_write, my_close));
+	assertEqualInt(1, private.open_called);
+	assertEqualInt(0, private.write_called);
+	// Broken in 2.8, fixed in 3.0
+	//assertEqualInt(1, private.close_called);
+	assertEqualInt(ARCHIVE_OK, archive_write_finish(a));
+	assertEqualInt(1, private.open_called);
+	assertEqualInt(0, private.write_called);
+	assertEqualInt(1, private.close_called);
+
+	memset(&private, 0, sizeof(private));
+	private.magic = MAGIC;
+	private.open_return = ARCHIVE_FATAL;
+	a = archive_write_new();
+	assert(a != NULL);
+	archive_write_set_compression_compress(a);
+	archive_write_set_format_zip(a);
+	assertEqualInt(ARCHIVE_FATAL,
+	    archive_write_open(a, &private, my_open, my_write, my_close));
+	assertEqualInt(1, private.open_called);
+	assertEqualInt(0, private.write_called);
+	// Broken in 2.8, fixed in 3.0
+	//assertEqualInt(1, private.close_called);
+	assertEqualInt(ARCHIVE_OK, archive_write_finish(a));
+	assertEqualInt(1, private.open_called);
+	assertEqualInt(0, private.write_called);
+	assertEqualInt(1, private.close_called);
+
+	memset(&private, 0, sizeof(private));
+	private.magic = MAGIC;
+	private.open_return = ARCHIVE_FATAL;
+	a = archive_write_new();
+	assert(a != NULL);
+	archive_write_set_compression_gzip(a);
+	assertEqualInt(ARCHIVE_FATAL,
+	    archive_write_open(a, &private, my_open, my_write, my_close));
+	assertEqualInt(1, private.open_called);
+	assertEqualInt(0, private.write_called);
+	// Broken in 2.8, fixed in 3.0
+	//assertEqualInt(1, private.close_called);
+	assertEqualInt(ARCHIVE_OK, archive_write_finish(a));
+	assertEqualInt(1, private.open_called);
+	assertEqualInt(0, private.write_called);
+	assertEqualInt(1, private.close_called);
+
+}

Modified: stable/8/lib/libarchive/test/test_read_format_mtree.c
==============================================================================
--- stable/8/lib/libarchive/test/test_read_format_mtree.c	Wed Aug 10 08:34:00 2011	(r224751)
+++ stable/8/lib/libarchive/test/test_read_format_mtree.c	Wed Aug 10 08:40:59 2011	(r224752)
@@ -134,10 +134,53 @@ test_read_format_mtree2(void)
 	assertEqualInt(ARCHIVE_OK, archive_read_finish(a));
 }
 
+/*
+ * Reported to libarchive.googlecode.com as Issue 121.
+ */
+static void
+test_read_format_mtree3(void)
+{
+	static char archive[] =
+	    "#mtree\n"
+	    "a type=file contents=file\n"
+	    "b type=link link=a\n"
+	    "c type=file contents=file\n";
+	struct archive_entry *ae;
+	struct archive *a;
+
+	assertMakeDir("mtree3", 0777);
+	assertChdir("mtree3");
+	assertMakeFile("file", 0644, "file contents");
+
+	assert((a = archive_read_new()) != NULL);
+	assertEqualIntA(a, ARCHIVE_OK,
+	    archive_read_support_compression_all(a));
+	assertEqualIntA(a, ARCHIVE_OK,
+	    archive_read_support_format_all(a));
+	assertEqualIntA(a, ARCHIVE_OK,
+	    archive_read_open_memory(a, archive, sizeof(archive)));
+	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
+	assertEqualString(archive_entry_pathname(ae), "a");
+	assertEqualInt(archive_entry_filetype(ae), AE_IFREG);
+	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
+	assertEqualString(archive_entry_pathname(ae), "b");
+	assertEqualInt(archive_entry_filetype(ae), AE_IFLNK);
+	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
+	assertEqualString(archive_entry_pathname(ae), "c");
+	assertEqualInt(archive_entry_filetype(ae), AE_IFREG);
+
+	assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
+	assertEqualInt(ARCHIVE_OK, archive_read_close(a));
+	assertEqualInt(ARCHIVE_OK, archive_read_finish(a));
+
+	assertChdir("..");
+}
+
 
 
 DEFINE_TEST(test_read_format_mtree)
 {
 	test_read_format_mtree1();
 	test_read_format_mtree2();
+	test_read_format_mtree3();
 }

Modified: stable/8/lib/libarchive/test/test_write_compress_lzma.c
==============================================================================
--- stable/8/lib/libarchive/test/test_write_compress_lzma.c	Wed Aug 10 08:34:00 2011	(r224751)
+++ stable/8/lib/libarchive/test/test_write_compress_lzma.c	Wed Aug 10 08:40:59 2011	(r224752)
@@ -185,10 +185,15 @@ DEFINE_TEST(test_write_compress_lzma)
 	archive_write_close(a);
 	assert(0 == archive_write_finish(a));
 
-	/* Level 0 really does result in larger data. */
+	/* It would be nice to assert that compression-level=0 produced
+	 * consistently larger/smaller results than the default compression,
+	 * but the results here vary a lot depending on the version of liblzma
+	 * being used. */
+	/* 
 	failure("Compression-level=0 wrote %d bytes; default wrote %d bytes",
 	    (int)used2, (int)used1);
 	assert(used2 > used1);
+	*/
 
 	assert((a = archive_read_new()) != NULL);
 	assertA(0 == archive_read_support_format_all(a));

Modified: stable/8/lib/libarchive/test/test_write_compress_xz.c
==============================================================================
--- stable/8/lib/libarchive/test/test_write_compress_xz.c	Wed Aug 10 08:34:00 2011	(r224751)
+++ stable/8/lib/libarchive/test/test_write_compress_xz.c	Wed Aug 10 08:40:59 2011	(r224752)
@@ -193,10 +193,14 @@ DEFINE_TEST(test_write_compress_xz)
 	archive_write_close(a);
 	assert(0 == archive_write_finish(a));
 
-	/* Level 0 really does result in larger data. */
+	/* I would like to assert that compression-level=0 results in
+	 * larger data than the default compression, but that's not true
+	 * for all versions of liblzma. */
+	/*
 	failure("Compression-level=0 wrote %d bytes; default wrote %d bytes",
 	    (int)used2, (int)used1);
 	assert(used2 > used1);
+	*/
 
 	assert((a = archive_read_new()) != NULL);
 	assertA(0 == archive_read_support_format_all(a));



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