Skip to content


Subversion checkout URL

You can clone with
Download ZIP


multipart request sometimes causes infinit loop #182

wants to merge 1 commit into from

2 participants


I found multipart request sometimes causes infinit loop.
This is very rare case and not occurs on proper way to use of Mojolicious.
You can reproduce it by parsing request twice with hash or hash reference for argument.
Parsing request twice may not be a good idea but avoiding the infinit loop makes the class more reliable.

I encountered this when I was working on a plugin which reconstract the request with modified %ENV inside on_process.


Yes, parsing multiple times is a very bad idea and i'm sure it will cause many more problems.
This does not seem like a real solution though.

@kraih kraih closed this

Ok. I'll look for another workround. Thank you.


I'm sure you'll find a lot of helpful tests in "t/mojo/message.t", there are many special cases that would have to be tested for reparsing too.


Thanks. I'll look into that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 22, 2011
  1. avoid infinit loop on multipart parse

    sugama authored
This page is out of date. Refresh to see the latest.
Showing with 30 additions and 0 deletions.
  1. +4 −0 lib/Mojo/Content/
  2. +26 −0 t/mojo/content2.t
4 lib/Mojo/Content/
@@ -163,6 +163,10 @@ sub _parse_multipart {
elsif (($self->{multi_state} || '') eq 'multipart_body') {
last unless $self->_parse_multipart_body($boundary);
+ else {
+ last;
+ }
26 t/mojo/content2.t
@@ -0,0 +1,26 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More tests => 1;
+use Mojo::Content::MultiPart;
+use Mojo::Message::Request;
+local $SIG{ALRM} = sub { die "timeout\n" }; alarm 2;
+my $req_seed = <<EOF;
+GET /foo HTTP/1.0
+Content-Type: multipart/mixed; boundary="abcdefg"
+$req_seed =~ s{\x0a}{\x0d\x0a}g;
+my $req = Mojo::Message::Request->new;
+is(1, 1, 'no infinit loop');
Something went wrong with that request. Please try again.