Skip to content

Commit a0beba0

Browse files
Fix bad request for multipart form data with boundary split
Fix a bad request (400) response for multipart form data requests with a large header which leads to a split inside the boundary because of the read buffer size inside the SocketStream class. The parse function inside the MultipartFormDataParser wrongly erase the receive buffer if it doesn't find the boundary inside the buffer during first call.
1 parent 70f4d7d commit a0beba0

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

httplib.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5011,10 +5011,9 @@ class MultipartFormDataParser {
50115011
while (buf_size() > 0) {
50125012
switch (state_) {
50135013
case 0: { // Initial boundary
5014-
buf_erase(buf_find(dash_boundary_crlf_));
5015-
if (dash_boundary_crlf_.size() > buf_size()) { return true; }
5016-
if (!buf_start_with(dash_boundary_crlf_)) { return false; }
5017-
buf_erase(dash_boundary_crlf_.size());
5014+
auto pos = buf_find(dash_boundary_crlf_);
5015+
if (pos == buf_size()) { return true; }
5016+
buf_erase(pos + dash_boundary_crlf_.size());
50185017
state_ = 1;
50195018
break;
50205019
}

0 commit comments

Comments
 (0)