Skip to content

Fix OOB read for short multipart boundries - #2651

Merged
an-tao merged 1 commit into
drogonframework:masterfrom
marty1885:fix-multipart-parse
Oct 30, 2026
Merged

an-tao merged 1 commit into
drogonframework:masterfrom
marty1885:fix-multipart-parse

Conversation

@marty1885

@marty1885 marty1885 commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

The current multi part parser does not handle short invalid multipart bodies correctly. For the multipart body A\r\nA (which is invalid according to RFC). The parser will attempt to read at index pos2 - 4 which becomes -1 therefor a OOB read.

Also a reordering in RequestImpl to fix a harmless bug that pos < input.length() is evaluated after the read input[pos] == '?'. Which is fine in reality because the tailing \0 in C strings. But still wroth fixing.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The regression test can pass despite the out-of-bounds read, so it needs AddressSanitizer coverage or another deterministic check.

1 open issue
What changed in this PR

This PR hardens request parsing against out-of-bounds reads in malformed multipart bodies and parameter input.

Changes:

  • Reject empty multipart boundaries and insufficient data before boundary-related reads.
  • Check parameter input bounds before accessing characters.
  • Add regression cases for nearby boundaries and a boundary at the end of the body.
File Description
lib/​src/​MultiPart.cc Adds bounds checks around multipart boundary processing.
lib/​src/​HttpRequestImpl.cc Moves bounds checks before character access in parameter parsing.
lib/​tests/​unittests/​MultiPartParserTest.cc Adds malformed multipart rejection tests.

Review effort: Balanced

@an-tao
an-tao merged commit 4ceee68 into drogonframework:master Oct 30, 2026
34 checks passed
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.

3 participants