Skip to content

class MultipartFormDataParser cannot handle content starts with 2 CRLF #1317

@Gavin1937

Description

@Gavin1937

Description:

when handling multipart/form-data content, function httplib::detail::MultipartFormDataParser::parse() will fail contents that does not start with the boundary delimiter (line #3798).

cpp-httplib/httplib.h

Lines 3796 to 3798 in caa31aa

auto pattern = dash_ + boundary_ + crlf_;
if (pattern.size() > buf_size()) { return true; }
if (!buf_start_with(pattern)) { return false; }

example multipart/form-data content:

\r\n\r\n------53014704754052338\r\nContent-Disposition: form-data; name=\"file\"; filename=\"346ba067e51efc5f.jpg\"\r\nContent-Type: image/jpeg\r\n\r\n\377\330\377............

Above form-data work perfectly with other websites.

However, I think RFC 2046 acquiesce CRLF preceding the boundary delimiter line

The CRLF preceding the boundary delimiter line is conceptually
attached to the boundary

Is this a bug? Or I misunderstand how boundary delimiter works?

Possible fix:

maybe left trim all the CRLFs before parsing form-data?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions