The bug against Perl5 at https://rt.perl.org/rt3/Ticket/Display.html?id=38812
may very well be an Encode error. If one uses valgrind on this program from that ticket:
use strict;
#use Devel::Peek;
my @t = qw/230 13 90 65 34 239 86 15 8 26 181 25 305 123 22 139 111 6 3
100 37 1 20 1 166 1 300 19 1 42 153 81 106 114 67 1 32 34/;
open OUT, '>:encoding(iso-8859-1)', 'out.xml' or die "$!";
my $string = join "\x{fffd}", map { '.'x$_ } @t;
#Dump $string;
print OUT $string;
close OUT or die "$!";
one gets errors about using uninitialized values. It turns out that Encode is calling utf8n_to_uvchr() with bad data. Here is the relevant line from the output:
encode_method(interpreter*, encode_s const*, encpage_s const*, sv*, int, unsigned int*, sv*, int*, sv*) (Encode.xs:182)