drogonframework / drogonframework/drogon
MultiPartParser skips fields when sending empty files
- Dominant language
- C++
- Stars
- 14.3k
- Forks
- 1.4k
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 14
Description
**Describe the bug**
`MultiPartParser` does not parse the request body correctly when an empty file is transmitted as the first member of the body.
**To Reproduce**
1. Create a POST Endpoint that reads out the multipart body.
2. Create a sample HTML page that has a `` as the first input in a form
3. Add more of whatever types
4. Dispatch the form without supplying a file
5. Endpoint reads out no parameters
**Expected behavior**
The `MultiPartParser` should return the request body with the parameters set.
Currently, `MultiPartParser::parse` returns `-1` with an empty ``
**Screenshots**
If applicable, add screenshots to help explain your problem.
**Desktop (please complete the following information):**
- OS: Linux
- Browser: Firefox
- Version: 133.0.3
The bug also occurs on chrome.
**Additional context**
The implementation of `MultiPartParser::parseEntity` is faulty in that it expects each multi-part file to have a filename.
When sending a form that has no filename set, the parser stops parsing subsequent fields.
The offending code is the conditional at `MultiPart.cc:214`
Here's an excerpt of the failing request body:
```
-----------------------------105238891342303886541107959621
Content-Disposition: form-data; name="cover"; filename=""
Content-Type: application/octet-stream
-----------------------------105238891342303886541107959621
Content-Disposition: form-data; name="abstract"
test
-----------------------------105238891342303886541107959621
Content-Disposition: form-data; name="language"
test
-----------------------------105238891342303886541107959621--
```
Contributor guide
Assessment
This issue has not been assessed yet.