Subject: | Negative offset to vec in lvalue context |
A bug in Perl 5.26 causes PDF::API2 to crash when loading PNG images. See https://rt.perl.org/Public/Bug/Display.html?id=131083 for details.
The attached patch adds a workaround for this problem, in case it is not solved in time for the 5.26 release.
Subject: | PDF_API2_Resource_XObject_Image_PNG.patch |
*** PDF/API2/Resource/XObject/Image/PNG.pm~ 2017-04-11 18:03:15.841626104 +0200
--- PDF/API2/Resource/XObject/Image/PNG.pm 2017-04-11 18:00:44.084060531 +0200
***************
*** 264,269 ****
--- 264,275 ----
}
}
+ # Prevent "Negative offset to vec in lvalue context" for Perl 5.26.
+ sub __vec {
+ return 0 if $_[1] < 0;
+ vec( $_[0], $_[1], $_[2] );
+ }
+
sub unprocess {
my ($bpc,$bpp,$comp,$width,$height,$scanline,$sstream)=@_;
my $stream=uncompress($$sstream);
***************
*** 280,286 ****
$clear=$line;
} elsif($filter==1) {
foreach my $x (0..length($line)-1) {
! vec($clear,$x,8)=(vec($line,$x,8)+vec($clear,$x-$bpp,8))%256;
}
} elsif($filter==2) {
foreach my $x (0..length($line)-1) {
--- 286,292 ----
$clear=$line;
} elsif($filter==1) {
foreach my $x (0..length($line)-1) {
! vec($clear,$x,8)=(vec($line,$x,8)+__vec($clear,$x-$bpp,8))%256;
}
} elsif($filter==2) {
foreach my $x (0..length($line)-1) {
***************
*** 288,299 ****
}
} elsif($filter==3) {
foreach my $x (0..length($line)-1) {
! vec($clear,$x,8)=(vec($line,$x,8)+floor((vec($clear,$x-$bpp,8)+vec($prev,$x,8))/2))%256;
}
} elsif($filter==4) {
# die "paeth/png filter not supported.";
foreach my $x (0..length($line)-1) {
! vec($clear,$x,8)=(vec($line,$x,8)+PaethPredictor(vec($clear,$x-$bpp,8),vec($prev,$x,8),vec($prev,$x-$bpp,8)))%256;
}
}
$prev=$clear;
--- 294,305 ----
}
} elsif($filter==3) {
foreach my $x (0..length($line)-1) {
! vec($clear,$x,8)=(vec($line,$x,8)+floor((__vec($clear,$x-$bpp,8)+vec($prev,$x,8))/2))%256;
}
} elsif($filter==4) {
# die "paeth/png filter not supported.";
foreach my $x (0..length($line)-1) {
! vec($clear,$x,8)=(vec($line,$x,8)+PaethPredictor(__vec($clear,$x-$bpp,8),vec($prev,$x,8),__vec($prev,$x-$bpp,8)))%256;
}
}
$prev=$clear;