Post without Account — your post will be reviewed, and if appropriate, posted under Anonymous.

RT 121073 - Negative offset to vec in lvalue context (PNG)

  • 4 Replies
  • 722 Views
*

Offline Phil

  • Global Moderator
  • Sr. Member
  • *****
  • 356
    • View Profile
Tue Apr 11 12:08:04 2017 jv [...] cpan.org - Ticket created
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

Code: [Select]
*** 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;
« Last Edit: April 18, 2017, 10:19:23 AM by Phil »

*

Offline Phil

  • Global Moderator
  • Sr. Member
  • *****
  • 356
    • View Profile
Re: RT 121073 - Negative offset to vec in lvalue context (PNG)
« Reply #1: April 13, 2017, 01:43:32 PM »
Hmm. So this patch is a workaround for a Perl bug, rather than something wrong in PDF::API2's code? 

  • Is this bug something that's going to blow up every time you use Perl 5.26 and handle PNG images, or is it a rare edge case? Has it been confirmed to show up in PDF::API2?
  • If we implement this patch, it won't cause problems once Perl is fixed?
  • Are there any penalties in using this patch, such as much slower operation, or a difference in how PNG images are rendered? Can we safely assume that even once Perl is fixed, that we can keep the patch in and it won't hurt anything?
If everyone is satisfied that these conditions are met, I can go ahead and put the patch in release 3.003 (end of this month). If Perl gets patched before 5.26 is released, I can back out the patch. When is 5.26 coming out, and we could confirm whether or not the patch is needed? If it's within a week or two, I would rather wait to see if the patch is still needed.

*

Offline sciurius

  • Jr. Member
  • **
  • 67
    • View Profile
    • Website
Re: RT 121073 - Negative offset to vec in lvalue context (PNG)
« Reply #2: April 14, 2017, 04:48:42 AM »
Yes. We're the victim, not the cause.

1. Amost every time (depends on the filter used).
2. No, it is up/backwards compatible.
3. Speed loss is neglectible (I did time it).

But the best would be if they fix it before 5.26 comes out. I suggest applying this workaround fix only if 5.26 is released with the bug.

*

Offline Phil

  • Global Moderator
  • Sr. Member
  • *****
  • 356
    • View Profile
Re: RT 121073 - Negative offset to vec in lvalue context (PNG)
« Reply #3: April 14, 2017, 02:36:33 PM »
OK, I'll wait until Perl 5.26 comes out, and put in the fix if needed. Since I don't monitor Perl releases like you apparently do, please bump this thread to let me know one way or the other.

*

Offline Phil

  • Global Moderator
  • Sr. Member
  • *****
  • 356
    • View Profile
Re: RT 121073 - Negative offset to vec in lvalue context (PNG)
« Reply #4: December 25, 2017, 07:05:12 PM »
 PhilterPaper commented on Jul 18

JV tells me that Perl 5.26 was fixed before release, so this bug is no longer applicable. Closing.