Skip to content

Fix out-of-bounds read on malformed uuencode "begin" line#55

Open
iliaal wants to merge 1 commit into
php:masterfrom
iliaal:pr/uudecode-begin-oob
Open

Fix out-of-bounds read on malformed uuencode "begin" line#55
iliaal wants to merge 1 commit into
php:masterfrom
iliaal:pr/uudecode-begin-oob

Conversation

@iliaal
Copy link
Copy Markdown

@iliaal iliaal commented Jun 7, 2026

The three uudecode loops (mailparse_msg_extract_uue, _enum_uue, mailparse_uudecode_all) matched a 6-byte begin prefix and then read the filename unconditionally at buffer[10], assuming a begin <mode> <name> layout. A short line such as begin 644\n (strlen 10) puts buffer[10] at or past the NUL terminator, reading into stack garbage; the trailing-whitespace trim could also underflow to origfilename[-1] on an empty filename. Both are reachable from attacker-controlled message bodies.

Clamp the filename offset to the actual line length (&buffer[len > 10 ? 10 : len]), guard the trim loop with len > 0, and cast the isspace() argument to unsigned char.

The three uudecode loops (mailparse_msg_extract_uue, _enum_uue and
mailparse_uudecode_all) matched a "begin " prefix (6 bytes) and then
unconditionally read the filename at buffer[10], assuming the
"begin <mode> <name>" layout. A short line such as "begin 644\n"
(strlen 10) put buffer[10] at or past the NUL terminator, reading
into stack/heap garbage. The subsequent trailing-whitespace trim
(`while (isspace(origfilename[len-1]))`) could also underflow to
origfilename[-1] when the filename was empty.

Clamp the filename offset to the actual line length and guard the trim
loop with len > 0. Also cast the isspace() argument to unsigned char to
avoid UB on bytes with the high bit set.
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.

1 participant