Subject: | Bug in deGIF sub -- LZW code size should not exceed 12 |
Test:
use PDF::API2;
my $pdf = PDF::API2->new;
my $page = $pdf->page();
my $gfx = $page->gfx();
my $gif = $pdf->image_gif('Sunflower_as_gif_websafe.gif');
my $img = $gfx->image($gif,0,0);
$pdf->saveas('test_api2-gif.pdf');
Resulting PDF is broken, Adobe Reader says 'Insufficient data for an image.'
Image source is http://en.wikipedia.org/wiki/File:Sunflower_as_gif_websafe.gif, but any GIF image will do, that's large enough to reach code 4096 in compression table. Uncommenting debugging output, that's present in deGIF, shows that compression size gets to 13 bits for one iteration, that can not be with GIF compression. To fix, condition to increase code size can be changed to
$bits++ if $nextcode == 1<<$bits and $bits < 12;
It looks like this bug has been there for quite some time.