Repository navigation
Fix OOB read for short multipart boundries - #2651
Merged
Merged
Conversation
There was a problem hiding this comment.
🟡 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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 indexpos2 - 4which becomes -1 therefor a OOB read.Also a reordering in RequestImpl to fix a harmless bug that
pos < input.length()is evaluated after the readinput[pos] == '?'. Which is fine in reality because the tailing\0in C strings. But still wroth fixing.