]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-compression: istream-lz4 - Fix calling i_stream_read*() with a full buffer.
authorStephan Bosch <stephan.bosch@open-xchange.com>
Sun, 13 Oct 2019 16:49:28 +0000 (18:49 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Fri, 6 Mar 2020 09:00:50 +0000 (09:00 +0000)
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.

src/lib-compression/istream-lz4.c
src/lib-compression/test-compression.c

index cb5ca5cc7411fe295e16bfc037b22e1a5a7aa443..b7100ec6e6f31da3445bb559210ff392c64d33a0 100644 (file)
@@ -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;
index f62d7d60949594ec473179d775644b933bf8c9fd..14db3b25865aefb493081e8b275fbb48b3c7b23a 100644 (file)
@@ -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);