Skip Menu |

This queue is for tickets about the MailTools CPAN distribution.

Report information
The Basics
Id: 16037
Status: resolved
Priority: 0/
Queue: MailTools

People
Owner: Nobody in particular
Requestors: jgmyers [...] proofpoint.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 1.67
Fixed in: (no value)



Subject: Optimize some regexes
The attached patch optimizes some regexes in Mail::Address. Without the * after the [], Perl's C stack overflowed when parsing an extremely long quoted-string.
diff -ur MailTools-1.67/blib/lib/Mail/Address.pm MailTools-1.67-fix/blib/lib/Mail/Address.pm --- MailTools-1.67/blib/lib/Mail/Address.pm 2005-01-20 01:17:54.000000000 -0800 +++ MailTools-1.67-fix/blib/lib/Mail/Address.pm 2005-11-22 11:26:25.000000000 -0800 @@ -119,8 +119,8 @@ next; } - s/^("([^"\\]|\\.)*")\s*// # "..." - || s/^(\[([^\]\\]|\\.)*\])\s*// # [...] + s/^("(?:[^"\\]*|\\.)*")\s*// # "..." + || s/^(\[(?:[^\]\\]*|\\.)*\])\s*// # [...] || s/^([^\s\Q()<>\@,;:\\".[]\E]+)\s*// || s/^([\Q()<>\@,;:\\".[]\E])\s*// and do { push(@words, $1); next; }; diff -ur MailTools-1.67/Mail/Address.pm MailTools-1.67-fix/Mail/Address.pm --- MailTools-1.67/Mail/Address.pm 2005-01-20 01:17:54.000000000 -0800 +++ MailTools-1.67-fix/Mail/Address.pm 2005-11-22 11:26:25.000000000 -0800 @@ -119,8 +119,8 @@ next; } - s/^("([^"\\]|\\.)*")\s*// # "..." - || s/^(\[([^\]\\]|\\.)*\])\s*// # [...] + s/^("(?:[^"\\]*|\\.)*")\s*// # "..." + || s/^(\[(?:[^\]\\]*|\\.)*\])\s*// # [...] || s/^([^\s\Q()<>\@,;:\\".[]\E]+)\s*// || s/^([\Q()<>\@,;:\\".[]\E])\s*// and do { push(@words, $1); next; }; Only in MailTools-1.67-fix/Mail: Address.pm~
Your patch was not on the latest version, I already had changed some things in it. Working a little further on the regexes, my choice would be: if( s/^(?:"(?:[^"\\]+|\\.)*")\s*// # "..." || s/^(?:\[(?:[^\]\\]+|\\.)*\])\s*// # [...] || s/^(?:[^\s()<>\@,;:\\".[\]]+)\s*// || s/^(?:[()<>\@,;:\\".[\]])\s*// ) { push(@words, $1); next; } Do you think this is right? More "?:" and your '*' became '+'
From: jgmyers [...] proofpoint.com
Good catch on the * to +. I believe the outermost parens cannot be ?: as that would make the $1 used later be undefined.
Oops, you're right: parens required. Use release 1.69, soon at CPAN