Post without Account — your post will be reviewed, and if appropriate, posted under Anonymous. You can also use this link to report any problems registering or logging in.

RT 33970 - Patch to report errors opening PNG image files

  • 0 Replies
  • 1804 Views
*

Offline Phil

  • Global Moderator
  • Sr. Member
  • *****
  • 437
    • View Profile
RT 33970 - Patch to report errors opening PNG image files
« October 21, 2016, 12:58:43 PM »
Mon Mar 10 16:26:47 2008 RBS [...] cpan.org - Ticket created
Subject:    Patch to report errors opening PNG image files

PNG.pm does not die when an open() fails, resulting in mysterious
undefined value errors. The attached patch adds an "or die()" to the
open() and removes a possibly duplicate open.

Also, here is a series of other similar lines of code that don't happen
to be biting me (yet):

Code: [Select]
c:\perl\site\lib\PDF\API2\Resource\ColorSpace\Indexed\ACTFile.pm:   
open($fh,$file);
c:\perl\site\lib\PDF\API2\Resource\Font\Postscript.pm           :   
open(INF,$file);
c:\perl\site\lib\PDF\API2\Resource\Font\Postscript.pm           :   
open($fh,$file) || return undef;
c:\perl\site\lib\PDF\API2\Resource\XObject\Image\GIF.pm         :   
open($fh,$file);
c:\perl\site\lib\PDF\API2\Resource\XObject\Image\JPEG.pm        :     
 open($fh,$file);
c:\perl\site\lib\PDF\API2\Resource\XObject\Image\PNM.pm         :   
open(INF,$file);
c:\perl\site\lib\PDF\API2\Resource\XObject\Image\TIFF.pm        :   
open($self->{fh},"< $file");
c:\perl\site\lib\PDF\API2\Util.pm                               :     
     open($fh,"$dir/PDF/API2/Resource/unipaper.txt");
c:\perl\site\lib\PDF\API2\Util.pm                               :     
     open($fh,"$dir/PDF/API2/Resource/uniglyph.txt");
c:\perl\site\lib\PDF\API2\Util.pm                               :     
     open($fh,"$dir/PDF/API2/Resource/unicolor.txt");
Subject:    png.diff

Code: [Select]
--- c:\Perl\site\lib\PDF\API2\Resource\XObject\Image\PNG.pm Mon Mar 10 16:22:54 2008
+++ PNG.pm Mon Mar 10 16:23:10 2008
@@ -65,11 +65,9 @@
     $self->{' apipdf'}=$pdf;
 
     my $fh = IO::File->new;
-    open($fh,$file);
-    binmode($fh,':raw');
 
     my ($buf,$l,$crc,$w,$h,$bpc,$cs,$cm,$fm,$im,$palete,$trns);
-    open($fh,$file);
+    open($fh,$file) or die "$!: $file\n";
     binmode($fh);
     seek($fh,8,0);
     $self->{' stream'}='';
#
Mon Apr 27 14:45:49 2009 otto.hirr [...] olabinc.com - Correspondence added

carried to PDF::API3 as https://rt.cpan.org/Ticket/Display.html?id=45488
#
Mon Apr 27 14:45:50 2009 The RT System itself - Status changed from 'new' to 'open'
#
Subject:    [rt.cpan.org #33970]
Date:    Mon, 15 Feb 2016 16:50:41 -0500
To:    bug-PDF-API2 [...] rt.cpan.org
From:    Phil M Perry

I could get behind this request to not silently err on failure to open a file. The only question is whether a "die" is the best thing to do, or should some recovery attempt take place to limp along (give an error message in that case)? Adding an "or die" to all file operations (at least, opens and closes) shouldn't be rocket science, if there are any such cases still open.
#
Sun Oct 09 17:48:54 2016 steve [...] deefs.net - Correspondence added

I bet you wouldn't have guessed that it would take 8.5 years for this to get done!

These checks will be in the next release (2.029).
#
Sun Oct 09 17:48:59 2016 steve [...] deefs.net - Status changed from 'open' to 'patched'
#
Mon Oct 10 09:20:27 2016 steve [...] deefs.net - Severity Important deleted
#
Mon Oct 10 09:20:27 2016 steve [...] deefs.net - Fixed in 2.029 added
#
Mon Oct 10 09:20:57 2016 steve [...] deefs.net - Status changed from 'patched' to 'resolved'