Skip Menu |
 

This queue is for tickets about the MIME-tools CPAN distribution.

Report information
The Basics
Id: 71041
Status: resolved
Priority: 0/
Queue: MIME-tools

People
Owner: dfs+pause [...] roaringpenguin.com
Requestors: ais523 [...] bham.ac.uk
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 5.502
Fixed in: (no value)



Subject: Header parsing fails with misleading error message with unusual $\ values (particularly newline)
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 1120
When $\ has a nonstandard value, MIME::Parser::process_header ends up writing out stray $\s to the internal $headstr scalar (I couldn't quite track down where this was happening, but read_chunk seems plausible). As a result, the resulting header can't be parsed. This is particularly confusing with $\ set to \n (probably the most common non-null value), because the leading newline is interpreted as a zero-length header, which MIME::Parser interprets as an error in parsing (because not the whole header was parsed), giving an error message saying that the erroneous line is the line before the first line. Fixing this is likely a simple matter of a "local $\" somewhere near the start of process_header, and would probably be faster than documenting the restriction. Information common in bug reports that is almost certainly irrelevant in this case: $ perl -v This is perl, v5.10.1 (*) built for i486-linux-gnu-thread-multi $ uname -a Linux desert 2.6.32-34-generic #77-Ubuntu SMP Tue Sep 13 19:40:53 UTC 2011 i686 GNU/Linux To reproduce, set $\ to \n, then try to parse any message with at least one header line.
MIME-Version: 1.0
X-Canit-Geo: No geolocation information available for 192.168.10.23
X-Canit-Archived-As: base/20110921 / 01Fzq4dGb
X-Spam-Flag: NO
X-Virus-Scanned: Debian amavisd-new at bestpractical.com
Content-Type: text/plain; charset="utf-8"
X-RT-Original-Encoding: utf-8
X-Spam-Score: -6.923
Authentication-Results: hipster.bestpractical.com (amavisd-new); dkim=pass header.i= [...] roaringpenguin.com
Received: from localhost (localhost [127.0.0.1]) by hipster.bestpractical.com (Postfix) with ESMTP id 2CBC92409B6 for <cpan-bug+MIME-tools [...] hipster.bestpractical.com>; Wed, 21 Sep 2011 10:04:24 -0400 (EDT)
Received: from hipster.bestpractical.com ([127.0.0.1]) by localhost (hipster.bestpractical.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id oI0MBeLSxAIR for <cpan-bug+MIME-tools [...] hipster.bestpractical.com>; Wed, 21 Sep 2011 10:04:22 -0400 (EDT)
Received: from la.mx.develooper.com (x1.develooper.com [207.171.7.70]) by hipster.bestpractical.com (Postfix) with SMTP id 66A4B240906 for <bug-MIME-tools [...] rt.cpan.org>; Wed, 21 Sep 2011 10:04:22 -0400 (EDT)
Received: (qmail 29427 invoked by uid 103); 21 Sep 2011 14:04:21 -0000
Received: from x16.dev (10.0.100.26) by x1.dev with QMQP; 21 Sep 2011 14:04:21 -0000
Received: from roaringpenguin.com (HELO colo3.roaringpenguin.com) (70.38.112.54) by 16.mx.develooper.com (qpsmtpd/0.80/v0.80-19-gf52d165) with ESMTP; Wed, 21 Sep 2011 07:04:18 -0700
Received: from vanadium.roaringpenguin.com (vanadium.roaringpenguin.com [192.168.10.23]) by colo3.roaringpenguin.com (8.14.3/8.14.3/Debian-5+lenny1) with ESMTP id p8LE4DE9011504 for <bug-MIME-tools [...] rt.cpan.org>; Wed, 21 Sep 2011 10:04:14 -0400
Received: from hydrogen.roaringpenguin.com (hydrogen.roaringpenguin.com [192.168.10.1]) by vanadium.roaringpenguin.com (8.14.3/8.14.3/Debian-9.4) with ESMTP id p8LE4Cd5023736 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT) for <bug-MIME-tools [...] rt.cpan.org>; Wed, 21 Sep 2011 10:04:13 -0400
Delivered-To: cpan-bug+MIME-tools [...] hipster.bestpractical.com
Subject: Re: [rt.cpan.org #71041] Header parsing fails with misleading error message with unusual $\ values (particularly newline)
X-Spam-Check-BY: 16.mx.develooper.com
Dkim-Signature: v=1; a=rsa-sha1; c=relaxed; d=roaringpenguin.com; h=date :from:to:subject:message-id:in-reply-to:references:mime-version :content-type:content-transfer-encoding; s=beta; bh=ts5gKoX2fFeF gAqFriq6EXsrjGE=; b=ASJ0rLxaTlicVAXGVSHUIJel6F+DpvFf96orAL4f0AGQ bxIVYHmDHb2tEaY8mfPtdB6BF12pI0VSYQS1n9rSRGcEaKCu++DlSKNAfUUAY3P1 /XqYD01YoPvgCV+ru6FSlTaHWkxdizbwW1LLc4/OAdMtB0cBXj68vRyoAUDS3aY=
Date: Wed, 21 Sep 2011 10:04:12 -0400
X-Spam-Level:
To: bug-MIME-tools [...] rt.cpan.org
Content-Transfer-Encoding: 7bit
X-Scanned-BY: CanIt (www . roaringpenguin . com) on 192.168.7.18
X-Scanned-BY: MIMEDefang 2.72 on 192.168.10.23
From dfs [...] roaringpenguin.com Wed Sep 21 10: 04:24 2011
In-Reply-To: <rt-3.8.HEAD-20564-1316302200-989.71041-4-0 [...] rt.cpan.org>
X-Spam-Status: No, score=-6.923 tagged_above=-99.9 required=10 tests=[AWL=0.076, BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_HI=-5, SPF_FAIL=0.001] autolearn=ham
X-Mailer: Claws Mail 3.7.6 (GTK+ 2.20.1; i686-pc-linux-gnu)
X-Canit-Archive-Cluster: SQVyZJxqklY5buiWXYCN4T/BjiM
References: <RT-Ticket-71041 [...] rt.cpan.org> <rt-3.8.HEAD-20564-1316302200-989.71041-4-0 [...] rt.cpan.org>
Message-ID: <20110921100412.1a5c262d [...] hydrogen.roaringpenguin.com>
Organization: Roaring Penguin Software Inc.
Return-Path: <dfs [...] roaringpenguin.com>
X-RT-Mail-Extension: mime-tools
X-Original-To: cpan-bug+MIME-tools [...] hipster.bestpractical.com
X-Canitpro-Stream: outgoing (inherits from default)
From: "David F. Skoll" <dfs [...] roaringpenguin.com>
RT-Message-ID: <rt-3.8.HEAD-20562-1316613865-1088.71041-0-0 [...] rt.cpan.org>
Content-Length: 1239
Download (untitled) / with headers
text/plain 1.2k
Hi, Thanks for your bug report. I've made the following change which will appear in the next release. Please confirm that the patch below fixes the problem for you. Regards, David. diff --git a/lib/MIME/Parser.pm b/lib/MIME/Parser.pm index 2047bd2..4735a76 100644 --- a/lib/MIME/Parser.pm +++ b/lib/MIME/Parser.pm @@ -1153,6 +1153,7 @@ sub parse { my $entity; local $/ = "\n"; ### just to be safe + local $\ = undef; # CPAN ticket #71041 $self->init_parse; $entity = $self->process_part($in, undef); ### parse! diff --git a/t/ticket-71041.t b/t/ticket-71041.t new file mode 100644 index 0000000..519783b --- /dev/null +++ b/t/ticket-71041.t @@ -0,0 +1,24 @@ +use Test::More tests => 1; + +use MIME::Parser; + +my $parser = MIME::Parser->new(); +$parser->output_to_core(1); + +my $message = <<'EOF'; +From: <devnull@example.org> +To: <devnull@example.com> +Subject: Ticket #71041 test +Message-Id: <cheese@burger.org> +MIME-Version: 1.0 +Content-Type: text/plain + +This should parse properly. +EOF + +# Set $\ to something wacky +$\ = "\n"; + +my $entity = $parser->parse_data($message); +my $head = $entity->head; +is ($head->get('From'), "<devnull\@example.org>\n", 'Header was parsed as expected');
MIME-Version: 1.0
In-Reply-To: <rt-3.8.HEAD-20562-1316613865-1088.71041-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
References: <RT-Ticket-71041 [...] rt.cpan.org> <rt-3.8.HEAD-20564-1316302200-989.71041-4-0 [...] rt.cpan.org> <20110921100412.1a5c262d [...] hydrogen.roaringpenguin.com> <rt-3.8.HEAD-20562-1316613865-1088.71041-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-20564-1316733549-1735.71041-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
From: ais523 [...] bham.ac.uk
X-RT-Original-Encoding: utf-8
Content-Length: 305
Download (untitled) / with headers
text/plain 305b
On Wed Sep 21 10:04:25 2011, dfs@roaringpenguin.com wrote: Show quoted text
> Hi, > > Thanks for your bug report. I've made the following change which will > appear in the next release. Please confirm that the patch below fixes > the problem for you.
I can confirm that the patch fixes the problem. Thanks for the fix!
MIME-Version: 1.0
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-31486-1339164037-1150.71041-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 108
Download (untitled) / with headers
text/plain 108b
Hi, I have just uploaded MIME-tools-5.503 to CPAN, which I believe resolves this ticket. Regards, David.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.