drogonframework / drogonframework/drogon

MultiPartParser skips fields when sending empty files

Open
#2,235 0 comments 0 reactions 0 assignees View on GitHub
enhancement
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.