Subject: | parsing bug in HTTP::Message::parse() |
Hi!
I've stumbled across a bug in multi-part messages in HTTP::Message. If the message content contains something that looks like a header, it accidentally gets detected as a header. However, a blank line after a header should signal the end of headers, and below it, the start of content as per the spec. It just looks like your regex needs some tweeking, or maybe do something like this:
sub parse
{
my($class, $str) = @_;
my ($headPart,$contentPart) = split(/\r?\n\r?\n/,$str,2);
my @hdr;
while ($headPart =~ s/^([^ \t:]+)[ \t]*: ?(.*)\n?//) {
push(@hdr, $1, $2);
}
new($class, \@hdr, $contentPart);
}
I've included a sample program to reproduce the problem so you can see better what I'm trying to say. If you look at the Dumper() output for the part "3fc90c2f106c4dc7e7742d6bb12b68f7" you'll see that it got detected
incorrectly.
Let me know if there is anything i can do to help.
#!/usr/bin/perl -w
use strict;
use HTTP::Message;
use HTTP::Headers;
use Data::Dumper;
my $content = '------------0xKhTmLbOuNdArY
Content-Disposition: form-data; name="fp720eb62d5af0f1d87412b385533c196c"
1
------------0xKhTmLbOuNdArY
Content-Disposition: form-data; name="trid720eb62d5af0f1d87412b385533c196c"
779758
------------0xKhTmLbOuNdArY
Content-Disposition: form-data; name="673bb732f4790c8cc3a63e5489bdb25b"; filename=""
------------0xKhTmLbOuNdArY
Content-Disposition: form-data; name="3fc90c2f106c4dc7e7742d6bb12b68f7"
some data
------------0xKhTmLbOuNdArY
Content-Disposition: form-data; name="42a6fca55664038ee398f7ceb14e4835"
aoeu:aoeu
------------0xKhTmLbOuNdArY--
';
my $headers = HTTP::Headers->new;
$headers->header( 'content-type' => 'multipart/form-data; boundary=----------0xKhTmLbOuNdArY' );
my $m = HTTP::Message->new($headers,$content);
foreach my $part ($m->parts)
{
print STDERR Dumper($part);
}