e967c8b899
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. Reviewed by: kientzle Approved by: re (kib) MFC after: 3 days
199 lines
6.6 KiB
C
199 lines
6.6 KiB
C
/*-
|
|
* 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);
|
|
|
|
}
|