decodemail aborts while parsing a 207-byte message. Both the Ubuntu
package 3.17 and a build of the 3.21 release (2025-12-11) die with
SIGABRT (signal 6). The C library reports heap corruption
("double free or corruption (out)"; another 3.17 run of the same input
reported "malloc(): unaligned tcache chunk detected").

The input is the 207 bytes produced by:

    poc = (b'From MAILER-DAEMON Mon Sep 17 00:00:00 2001\n'
           b'From: a \x00d@st>\n'
           b'To: [email protected]\n'
           b'Content-Type: multipart/d; boundary=B\n'
           b'\n'
           b'--B\n'
           b'Content-Ty" : Fipart: R\x1ft>\n'
           b'\xffFrom MGILER-DAEMON Mon Sep 17 00:00:00 2;01ry=B\n'
           b'\n'
           b'--B\n'
           b'Cent-Type: ')

Run: decodemail --no-config INPUT OUTPUT

An AddressSanitizer build of the same library reports a negative size
passed to memcpy in mu_hdrent_create (libmailutils/mailbox/header.c).
header_parse skips leading whitespace with while (ISLWSP(fv[0])) and
does not stop at the end of the field value. When the value is
whitespace through the end of the header block, fv moves past fv_end,
vsize becomes -1, and that length is passed to memcpy.

The 3.21 binary aborts on this input. The bound should be
while (fv < fv_end && ISLWSP(fv[0])).

I have not shown this on imap4d. This is separate from the nested-multipart
report, the
parse822 stack overflow, and the save_return NULL dereference I am
sending separately.

If this report is helpful, please attribute the report to Zhaoyang Li and
Xiang Li from AOSP Lab @Nankai University.

Reply via email to