]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Fix assert-crash in special partial mail parsing failures
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 18 Aug 2021 12:04:53 +0000 (14:04 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Thu, 26 Aug 2021 09:13:24 +0000 (09:13 +0000)
This happened for example if:
 - mail_precache() started parsing mail
 - header was parsed, but mail body parsing failed due to mail size mismatch
 - vsize parsing doesn't restart header parsing, because header size is already known
 - body parsing assert-crashes because there is no messsage parser initialized

Fixes:
Panic: file index-mail.c: line 1290 (index_mail_parse_body): assertion failed: (data->parser_ctx != NULL)

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

index 37abde321b3b811395714013b184a6ccd5fcac7c..f21c155d6eaa9ee0b09f3e66f1ebccd6610f43f5 100644 (file)
@@ -1367,9 +1367,13 @@ int index_mail_init_stream(struct index_mail *mail,
        if (hdr_size != NULL || body_size != NULL)
                (void)get_cached_msgpart_sizes(mail);
 
-       if (hdr_size != NULL || body_size != NULL || want_attachment_kw) {
+       bool want_body_parsing = want_attachment_kw ||
+               (body_size != NULL && !data->body_size_set &&
+                (data->access_part & PARSE_BODY) != 0);
+
+       if (hdr_size != NULL || body_size != NULL || want_body_parsing) {
                i_stream_seek(data->stream, 0);
-               if (!data->hdr_size_set || want_attachment_kw) {
+               if (!data->hdr_size_set || want_body_parsing) {
                        if ((data->access_part & (PARSE_HDR | PARSE_BODY)) != 0) {
                                (void)get_cached_parts(mail);
                                if (index_mail_parse_headers_internal(mail, NULL) < 0)
@@ -1389,10 +1393,10 @@ int index_mail_init_stream(struct index_mail *mail,
                        *hdr_size = data->hdr_size;
        }
 
-       if (body_size != NULL || want_attachment_kw) {
+       if (body_size != NULL || want_body_parsing) {
                if (!data->body_size_set && body_size != NULL)
                        index_mail_get_cached_body_size(mail);
-               if (!data->body_size_set || want_attachment_kw) {
+               if (!data->body_size_set || want_body_parsing) {
                        i_stream_seek(data->stream,
                                      data->hdr_size.physical_size);
                        if ((data->access_part & PARSE_BODY) != 0) {