drogon icon indicating copy to clipboard operation
drogon copied to clipboard

MultiPartParser skips fields when sending empty files

Open 27justin opened this issue 1 year ago • 0 comments

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 <input type="file" /> 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 <input type="file" />

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--

27justin avatar Dec 22 '24 22:12 27justin