From: Stephan Bosch Date: Sun, 13 Oct 2019 16:49:28 +0000 (+0200) Subject: lib-compression: istream-lz4 - Fix calling i_stream_read*() with a full buffer. X-Git-Tag: 2.3.11.2~567 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3e7bc69d7945906c9d40eb23c6b4d85782f3ebd8;p=thirdparty%2Fdovecot%2Fcore.git lib-compression: istream-lz4 - Fix calling i_stream_read*() with a full buffer. Before, this read and discarded one chunk of the compressed parent stream data, causing data corruption. Fixed by checking whether the buffer is full first. --- diff --git a/src/lib-compression/istream-lz4.c b/src/lib-compression/istream-lz4.c index cb5ca5cc74..b7100ec6e6 100644 --- a/src/lib-compression/istream-lz4.c +++ b/src/lib-compression/istream-lz4.c @@ -92,6 +92,10 @@ static ssize_t i_stream_lz4_read(struct istream_private *stream) size_t size; int ret; + /* if we already have max_buffer_size amount of data, fail here */ + if (stream->pos - stream->skip >= i_stream_get_max_buffer_size(&stream->istream)) + return -2; + if (!zstream->header_read) { if ((ret = i_stream_lz4_read_header(zstream)) <= 0) { stream->istream.eof = TRUE; diff --git a/src/lib-compression/test-compression.c b/src/lib-compression/test-compression.c index f62d7d6094..14db3b2586 100644 --- a/src/lib-compression/test-compression.c +++ b/src/lib-compression/test-compression.c @@ -94,6 +94,8 @@ static void test_compression_handler(const struct compression_handler *handler) if (seeked) break; seeked = TRUE; + i_stream_seek(input, 1); + (void)i_stream_read(input); i_stream_seek(input, 0); } i_stream_destroy(&input);