The following replacement for the DecodeBase64 routine in MIMEStream.pm
should fix the problem with top-level Base64-encoded attachments getting
corrupted. This fix will be included in revision 1.34, so if you don't
want to hand-patch your sanitizer then just wait a few days... :-)
sub DecodeBase64
{
my $reader = shift;
my $line = shift;
# This hacks the decoder to handle mangled Base64 text properly, by
# properly ignoring white space etc. Note that this will lose the
# last 1-3 bytes of data if it isn't properly padded. We also record
# the encoded line-length, so we can re-encode stuff using the same
# length.
#
if (!$reader->{"DecodeBase64llen"})
{
$line =~ s/[^A-Za-z0-9\/+\n=]+//gs;
my $nlpos = int((3*(index($line, "\n") + 1)) / 4);
$line =~ s/\n//gs;
my $llen = int((3*length($line)) / 4);
my $t = $llen;
$t = $nlpos if (($nlpos < $llen) && ($nlpos > 0));
$reader->{"DecodeBase64llen"} = $t;
print STDERR "Set llen to $t (data=$llen, nl=$nlpos)\n";
}
else
{
$line =~ s/[^A-Za-z0-9\/+=]+//gs;
}
$line = $reader->{"DecodeBase64"} . $line;
$line =~ s/^((?:....)*)(.*?)$/$1/s;
$reader->{"DecodeBase64"} = $2;
return decode_base64($line);
}
-- Bjarni R. Einarsson PGP: 02764305, B7A3AB89 03643@xyz.molar.is -><- http://bre.klaki.net/Check out my open-source email sanitizer: http://mailtools.anomy.net/
-- This mailing list's home page is: http://mailtools.anomy.net/archives/anomy-bugs/ There you can find subscription instructions and possibly an archive. Molar.is is a free Icelandic mailing list service.