Subject: | evidently a bug in either Imager (0.98) or PerlIO::via(::CBC) |
Date: | Thu, 06 Feb 2014 18:09:55 +0200 |
To: | bug-Imager [...] rt.cpan.org |
From: | Thanos Chatziathanassiou <tchatzi [...] arx.net> |
Hey there, I've encountered an issue that (unfortunately) do not have
the time to properly trace: Imager dies rather violently when calling
$imager->read() after using a PerlIO::via::CBC, regardless of method of
reading.
Some sample code to illustrate:
---8<---
#!/usr/bin/perl -w
use strict;
use Imager;
use PerlIO::via::CBC;
my $src = "/path/to/cbc-encrypted/file.jpg";
PerlIO::via::CBC->config(
'key' => "Some passphrase",
'cipher' => "Crypt::Rijndael",
'salt' => 1,
'header' => 'salt'
);
my $img = Imager->new;
open(my $fh, '<:via(PerlIO::via::CBC)', $src);
binmode($fh);
#CASE 1: pass the filehandle directly to Imager
$img->read(fh => $fh, type => 'jpeg') or die "Cannot read: ", $img->errstr;
#this dies with "Cannot read: Not a JPEG file: starts with random_bytes"
#(eg 0x53 0x61)
#note that these bytes are nowhere to be found in either the original
#or the decrypted file.
#this also happens with
$img->read(fd => fileno($fh), type => 'jpeg') or die "Cannot read: ",
$img->errstr;
#CASE 2: read into scalar and pass a) by reference or b) by value
my $size= (-s $src);
my $offset = 0;
my $imgdata;
while ($size > 32) { #we can leave out a whole padding block in the end
my $read = read($fh,$imgdata,262144,$offset);
#warn "read $read data, $size to go\n";
$size -= $read;
$offset += $read;
}
close($fh);
$img->read(data => \$imgdata, type => 'jpeg') or die "Cannot read: ",
$img->errstr;
#this dies horribly with "panic: sv_setpvn called with negative strlen #
at /usr/local/lib64/perl5/Imager/File/JPEG.pm line 44."
$img->read(data => $imgdata, type => 'jpeg') or die "Cannot read: ",
$img->errstr;
#this works.
---8<---
All this on an up-to-date Centos 6.5 x86_64 system (with default perl
5.10.1) and Imager-0.98 (built from source).
If I there's any more info I failed to provide, please let me know.
Best Regards,
Thanos Chatziathanassiou
Message body not shown because it is not plain text.