--- amavisd.orig 2006-01-28 15:31:53.000000000 +0900 +++ amavisd 2006-05-16 01:07:03.000000000 +0900 @@ -1392,6 +1392,7 @@ # A wrapper for Encode::encode, avoiding a bug in Perl 5.8.0 which causes # Encode::encode to loop and fill memory when given a tainted string +use Encode::Guess; sub safe_encode($$;$) { if (!$unicode_aware) { $_[1] } # just return the second argument else { @@ -1399,7 +1400,12 @@ $check = 0 if !defined($check); # taintedness of the string, with UTF-8 flag unconditionally off my($taint) = Encode::encode('ascii',substr($str,0,0)); - $taint . Encode::encode($encoding,untaint($str),$check); # preserve taint + my $enc = guess_encoding(untaint($str), qw/euc-jp shiftjis 7bit-jis/); + if (ref($enc)){ + $taint . Encode::encode($encoding,$enc->decode(untaint($str)),$check); # preserve taint + }else{ + $taint . Encode::encode($encoding,untaint($str),$check); # preserve taint + } } }