Subject: | Allow PNG to be read from an already opened filehandle, just like JPG |
The following patch against 2.028 allows PNG files to be read from an already openened filehandle.
It also eliminates superfluous open/binmode calls, and protects against dangerous file names by using the 3-argument form of open.
Subject: | PDF-API2-2.028-PNG_open.patch |
*** PDF/API2/Resource/XObject/Image/PNG.pm~ 2016-06-09 00:24:09.000000000 +0200
--- PDF/API2/Resource/XObject/Image/PNG.pm 2016-09-18 16:38:37.563107168 +0200
***************
*** 25,36 ****
$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);
- binmode($fh);
seek($fh,8,0);
$self->{' stream'}='';
$self->{' nofilt'}=1;
--- 25,38 ----
$self->{' apipdf'}=$pdf;
my $fh = IO::File->new;
! if ( ref($file) ) {
! $fh = $file;
! }
! else {
! open( $fh, '<:raw', $file);
! }
my ($buf,$l,$crc,$w,$h,$bpc,$cs,$cm,$fm,$im,$palete,$trns);
seek($fh,8,0);
$self->{' stream'}='';
$self->{' nofilt'}=1;