From: Tim Kientzle Date: Thu, 26 Feb 2009 04:35:57 +0000 (-0500) Subject: Add a variant of read_open_memory() that does not register open, X-Git-Tag: v2.7.0~211 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dd92025a5816102bbdc9b4b41b9288b15368fef4;p=thirdparty%2Flibarchive.git Add a variant of read_open_memory() that does not register open, skip, or close callbacks. Use this in read_pax_truncated to partially verify extraction with clients that only register a minimal set of callbacks (recall that only the read callback function is mandatory; in fact, the open callback is deprecated and will likely be removed in libarchive 3.0). Debian bug #516577 SVN-Revision: 714 --- diff --git a/libarchive/test/read_open_memory.c b/libarchive/test/read_open_memory.c index 7370fca65..3f07d08ec 100644 --- a/libarchive/test/read_open_memory.c +++ b/libarchive/test/read_open_memory.c @@ -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)); } /* diff --git a/libarchive/test/test.h b/libarchive/test/test.h index 2e8e7b630..ea9bfc9ad 100644 --- a/libarchive/test/test.h +++ b/libarchive/test/test.h @@ -169,6 +169,8 @@ const char *external_gzip_program(int un); /* 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. diff --git a/libarchive/test/test_read_pax_truncated.c b/libarchive/test/test_read_pax_truncated.c index 2bb956e20..2067a522f 100644 --- a/libarchive/test/test_read_pax_truncated.c +++ b/libarchive/test/test_read_pax_truncated.c @@ -73,7 +73,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));