Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing multipart request without Content-Length header fails #2222

Open
maxhq opened this issue Jan 15, 2025 · 1 comment
Open

Parsing multipart request without Content-Length header fails #2222

maxhq opened this issue Jan 15, 2025 · 1 comment

Comments

@maxhq
Copy link

maxhq commented Jan 15, 2025

  • Mojolicious version: 9.35
  • Perl version: 5.36.0
  • Operating system: Debian Bookworm (12.5)

Steps to reproduce the behavior

use v5.36;
use Mojo::Message::Request;

for my $with_len (0..1) {
    my $req = Mojo::Message::Request->new;
    $req->parse("GET /foo/bar/baz.html?foo13 HTTP/1.1\x0d\x0a");
    $req->parse("Content-Length: 128\x0d\x0a") if $with_len;
    $req->parse("Content-Type: multipart/form-data; boundary=----------0xKhTmLbOuNdArY\x0d\x0a\x0d\x0a");
    $req->parse("\x0d\x0a------------0xKhTmLbOuNdArY\x0d\x0a");
    $req->parse("Content-Disposition: form-data; name=\"text1\"\x0d\x0a");
    $req->parse("\x0d\x0ahallo welt test123");
    $req->parse("\x0d\x0a------------0xKhTmLbOuNdArY--");

    printf "%7s content-length: progress: %3i, body_size: %3i, text1: %s\n",
        'with'.($with_len ? '' : 'out'),
        $req->content->progress,
        $req->content->body_size,
        ($req->body_params->param('text1') // '');
}

# without content-length: progress: 128, body_size:  31, text1: 
#    with content-length: progress: 128, body_size: 128, text1: hallo welt test123

Expected behavior

Parsing should also work if no Content-Length was specified as this header does not seem to be mandatory for multipart/form-data (not mentioned in https://www.rfc-editor.org/rfc/rfc7578.html).

Actual behavior

The progress field hints that all data is parsed but for some reason the parts are not available.

@kraih
Copy link
Member

kraih commented Jan 16, 2025

Pretty sure that would be invalid according to the main HTTP spec.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants