Merge r714,r715 from libarchive.googlecode.com: Fix Debian bug #516577.

Don't crash if client does not provide a skip function.  Extend one
of the test cases to use archive_read_open2() with only a read callback.
This commit is contained in:
kientzle 2009-03-07 01:21:46 +00:00
parent 61bb6e5d74
commit 8639c01b4d
4 changed files with 31 additions and 3 deletions

View File

@ -234,6 +234,8 @@ static int64_t
client_skip_proxy(struct archive_read_filter *self, int64_t request)
{
int64_t r;
if (self->archive->client.skipper == NULL)
return (0);
r = (self->archive->client.skipper)(&self->archive->archive,
self->data, request);
self->archive->archive.raw_position += r;

View File

@ -54,9 +54,29 @@ static ssize_t memory_read_skip(struct archive *, void *, size_t request);
static off_t memory_read_skip(struct archive *, void *, off_t request);
#endif
static ssize_t memory_read(struct archive *, void *, const void **buff);
static int read_open_memory_internal(struct archive *a, void *buff,
size_t size, size_t read_size, int fullapi);
int
read_open_memory(struct archive *a, void *buff, size_t size, size_t read_size)
{
return read_open_memory_internal(a, buff, size, read_size, 1);
}
/*
* As above, but don't register any optional part of the API, to verify
* that internals work correctly with just the minimal entry points.
*/
int
read_open_memory2(struct archive *a, void *buff, size_t size, size_t read_size)
{
return read_open_memory_internal(a, buff, size, read_size, 0);
}
static int
read_open_memory_internal(struct archive *a, void *buff,
size_t size, size_t read_size, int fullapi)
{
struct read_memory_data *mine;
@ -71,8 +91,12 @@ read_open_memory(struct archive *a, void *buff, size_t size, size_t read_size)
mine->read_size = read_size;
mine->copy_buff_size = read_size + 64;
mine->copy_buff = malloc(mine->copy_buff_size);
return (archive_read_open2(a, mine, memory_read_open,
memory_read, memory_read_skip, memory_read_close));
if (fullapi)
return (archive_read_open2(a, mine, memory_read_open,
memory_read, memory_read_skip, memory_read_close));
else
return (archive_read_open2(a, mine, NULL,
memory_read, NULL, NULL));
}
/*

View File

@ -166,6 +166,8 @@ void extract_reference_file(const char *);
/* Special customized read-from-memory interface. */
int read_open_memory(struct archive *, void *, size_t, size_t);
/* "2" version exercises a slightly different set of libarchive APIs. */
int read_open_memory2(struct archive *, void *, size_t, size_t);
/*
* ARCHIVE_VERSION_STAMP first appeared in 1.9 and libarchive 2.2.4.

View File

@ -72,7 +72,7 @@ DEFINE_TEST(test_read_pax_truncated)
assert((a = archive_read_new()) != NULL);
assertA(0 == archive_read_support_format_all(a));
assertA(0 == archive_read_support_compression_all(a));
assertA(0 == read_open_memory(a, buff, i, 13));
assertA(0 == read_open_memory2(a, buff, i, 13));
if (i < 1536) {
assertEqualIntA(a, ARCHIVE_FATAL, archive_read_next_header(a, &ae));