From: Brian Harring Date: Thu, 23 Sep 2010 10:21:09 +0000 (-0400) Subject: correct a mismatch- you tell libarchive something is consumed only after you've actua... X-Git-Tag: v3.0.0a~890 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=87772ef98a29a20cd22f522a1fd50709775f9692;p=thirdparty%2Flibarchive.git correct a mismatch- you tell libarchive something is consumed only after you've actually consumed it. Once you've consumed a read_ahead block, the data it points to is volatile. Mainline trunk currently currently wouldn't cause issues with this usage, but the usage violates the api contract (and will have issues under libtransform) so fixing it. SVN-Revision: 2687 --- diff --git a/libarchive/archive_read_support_compression_compress.c b/libarchive/archive_read_support_compression_compress.c index 2461975e5..72125d6b1 100644 --- a/libarchive/archive_read_support_compression_compress.c +++ b/libarchive/archive_read_support_compression_compress.c @@ -95,6 +95,7 @@ struct private_data { /* Input variables. */ const unsigned char *next_in; size_t avail_in; + size_t consume_unnotified; int bit_buffer; int bits_avail; size_t bytes_in_section; @@ -420,6 +421,11 @@ getbits(struct archive_read_filter *self, int n) while (state->bits_avail < n) { if (state->avail_in <= 0) { + if (state->consume_unnotified) { + __archive_read_filter_consume(self->upstream, + state->consume_unnotified); + state->consume_unnotified = 0; + } state->next_in = __archive_read_filter_ahead(self->upstream, 1, &ret); @@ -427,8 +433,7 @@ getbits(struct archive_read_filter *self, int n) return (-1); if (ret < 0 || state->next_in == NULL) return (ARCHIVE_FATAL); - state->avail_in = ret; - __archive_read_filter_consume(self->upstream, ret); + state->consume_unnotified = state->avail_in = ret; } state->bit_buffer |= *state->next_in++ << state->bits_avail; state->avail_in--;