Subject: | Text::PDF::ASCII85Decode outfilt completely broken |
Text::PDF::ASCII85Decode::outfilt is trivially but completely broken.
It outputs each groups of 5 ASCII characters in reverse order. Here is
the output of btoa (original format):
$ cat HW
Hello world
$ ./btoa -o HW
xbtoa Begin
87cURD]j7BEbo7n
xbtoa End N 12 c E a S 452 R 57362
Here is Text::PDF:
$ cat test.pl
#perl -w
use Text::PDF::Filter;
use strict;
my $f = Text::PDF::ASCII85Decode->new;
my $str = $f->outfilt("Hello world\n", 1);
print "$str\n";
$ perl -Mblib test.pl
RUc78B7j]Dn7obE
Compare the pairs of 5:
87cUR D]j7B Ebo7n
RUc78 B7j]D n7obE
The bug is here:
for ($j = 0; $j < 4; $j++)
{ $c[$j] = $b - int($b / 85) * 85 + 33; $b /= 85; }
$res .= pack("C5", @c, $b + 33);
(and the analagous code for the end of file case)
The expression $b - int($b / 85) * 85 + 33; $b /= 85;
picks off the (virtual) base 85 digits from low to high, when it should
be from high to low.