]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: istream-mail - Fix assert-crash on handling corrupted mail size
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 15 Jun 2020 07:33:53 +0000 (10:33 +0300)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Thu, 25 Jun 2020 05:47:22 +0000 (05:47 +0000)
In some situations the "Cached message size smaller than expected" error
handling could have resulted in:

Panic: file istream.c: line 315 (i_stream_read_memarea): assertion failed: (old_size <= _stream->pos - _stream->skip)

src/lib-storage/index/istream-mail.c

index 365f8c897e10e1af7e2b24e2a7199b76898e8084..3cb3571479735bf3bbbe580517490f20ed7c7264 100644 (file)
@@ -124,7 +124,8 @@ i_stream_mail_read(struct istream_private *stream)
                        i_stream_mail_set_size_corrupted(mstream, size);
                        /* istream code expects that the position has not changed
                           when read error occurs, so move pos back. */
-                       stream->pos -= size;
+                       i_assert(stream->pos >= (size_t)ret);
+                       stream->pos -= ret;
                        return -1;
                }
        } else if (ret == -1 && stream->istream.eof) {