Skip to content

lib-mail: message-parser - Fix out-of-bounds read on empty preamble#297

Open
nishat-06 wants to merge 1 commit into
dovecot:mainfrom
nishat-06:message-parser-prologue-empty-preamble
Open

lib-mail: message-parser - Fix out-of-bounds read on empty preamble#297
nishat-06 wants to merge 1 commit into
dovecot:mainfrom
nishat-06:message-parser-prologue-empty-preamble

Conversation

@nishat-06

Copy link
Copy Markdown
Contributor

Re-parsing a multipart message from cached parts with
MESSAGE_PARSER_FLAG_INCLUDE_MULTIPART_BLOCKS, on a message whose MIME
part has an empty preamble (the boundary is the first thing in the body):

block: hdr=(nil) size=18446744073709551614
Panic: nearest_power(18446744073709551615): calculation would overflow

preparsed_parse_prologue_more() scans backwards from the boundary's
trailing CRLF for the newline that precedes --boundary. With no preamble
the boundary sits at the very start of the prologue block, so the scan runs
off the front and exits with cur == block_r->data - 1. data[-1] happens
to be the \n ending the multipart part header, so the -- check passes on
data[0]/data[1] and block_r->size = cur - block_r->data underflows to a
near-SIZE_MAX value. The prologue block is then handed to the consumer with
that size, which over-reads (the panic above is a consumer appending it).

Reachable via message_parser_init_from_parts() when a caller re-parses a
message against its cached message_part tree and asks for multipart blocks.

Handle the no-preamble case explicitly: when the backward scan finds no
newline, confirm the block starts with -- and return an empty prologue.
Regression test added to test-message-parser.c.

@cmouse

cmouse commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Thank you, we'll take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants