]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imapc: Don't trust mail stream to have correct CRLFs
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 18 Jun 2018 16:13:30 +0000 (19:13 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 26 Jun 2018 08:29:40 +0000 (11:29 +0300)
It's not that expensive to just recalculate them. If they're not correct in
the stream, it can result in e.g. truncated emails due to wrong virtual_size
being used in body_size calculation. The wrong CRLFs can especially happen
if plugins modify the stream in istream_opened() hook.

src/lib-storage/index/imapc/imapc-mail-fetch.c

index b543a92a0e81ba301cbfa607857baeb6786fc596..42b32d2f39a6481d711da398b432e28e68be7738 100644 (file)
@@ -589,12 +589,15 @@ void imapc_mail_init_stream(struct imapc_mail *mail)
           smaller than the fetched message header. In this case change the
           size as well, otherwise reading via istream-mail will fail. */
        if (mail->body_fetched || imail->data.physical_size < size) {
-               if (mail->body_fetched)
+               if (mail->body_fetched) {
                        imail->data.inexact_total_sizes = FALSE;
+                       /* Don't trust any existing virtual_size. Also don't
+                          set it to size, because there's no guarantees about
+                          the content having proper CRLF newlines, especially
+                          not if istream_opened() has changed the stream. */
+                       imail->data.virtual_size = (uoff_t)-1;
+               }
                imail->data.physical_size = size;
-               /* we'll assume that the remote server is working properly and
-                  sending CRLF linefeeds */
-               imail->data.virtual_size = size;
        }
 
        imail->data.stream_has_only_header = !mail->body_fetched;