Skip Menu |
 

This queue is for tickets about the PDF-API2 CPAN distribution.

Report information
The Basics
Id: 117940
Status: resolved
Priority: 0/
Queue: PDF-API2

People
Owner: Nobody in particular
Requestors: jv [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 2.028
Fixed in: 2.029

Attachments


Subject: Allow PNG to be read from an already opened filehandle, just like JPG
Download (untitled) / with headers
text/plain 231b
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;
Download (untitled) / with headers
text/plain 455b
On Sun Sep 18 11:00:08 2016, JV wrote: Show quoted text
> 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.
I just tried creating a test for this, and it seems that the open() function already works when given a filehandle instead of a filename. Were you seeing different behavior?
Subject: Re: [rt.cpan.org #117940] Allow PNG to be read from an already opened filehandle, just like JPG
Date: Fri, 7 Oct 2016 19:43:20 +0200
To: "Steve Simms via RT" <bug-PDF-API2 [...] rt.cpan.org>
From: Johan Vromans <jvromans [...] squirrel.nl>
Download (untitled) / with headers
text/plain 1.1k
On Fri, 7 Oct 2016 12:35:38 -0400 "Steve Simms via RT" <bug-PDF-API2@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=117940 > > > On Sun Sep 18 11:00:08 2016, JV wrote:
> > 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.
> > I just tried creating a test for this, and it seems that the open() > function already works when given a filehandle instead of a filename. > Were you seeing different behavior?
I tried: my $pdf = PDF::API2->new; open( my $fd, '<:raw', "icon.png"); my $p = $pdf->image_png($fd); print $PDF::API2::VERSION, ", width = ", $p->width, "\n"; This gives: Use of uninitialized value in print at x.pl line 11. 2.028, width = OTOH: my $p = $pdf->image_png("icon.png"); print $PDF::API2::VERSION, ", width = ", $p->width, "\n"; This gives: 2.028, width = 500 So the former does something, but it definitely doesn't create the desired image. Does this help? Thanks, Johan
Download (untitled) / with headers
text/plain 1.4k
Yes, that helped me create relevant tests, thanks. I extended the patch to cover GIF and PNM images as well, and updated the POD. This will be in the next release (2.029). On Fri Oct 07 13:43:39 2016, jvromans@squirrel.nl wrote: Show quoted text
> On Fri, 7 Oct 2016 12:35:38 -0400 > "Steve Simms via RT" <bug-PDF-API2@rt.cpan.org> wrote: >
> > <URL: https://rt.cpan.org/Ticket/Display.html?id=117940 > > > > > On Sun Sep 18 11:00:08 2016, JV wrote:
> > > 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.
> > > > I just tried creating a test for this, and it seems that the open() > > function already works when given a filehandle instead of a filename. > > Were you seeing different behavior?
> > I tried: > > my $pdf = PDF::API2->new; > open( my $fd, '<:raw', "icon.png"); > my $p = $pdf->image_png($fd); > print $PDF::API2::VERSION, ", width = ", $p->width, "\n"; > > This gives: > > Use of uninitialized value in print at x.pl line 11. > 2.028, width = > > OTOH: > > my $p = $pdf->image_png("icon.png"); > print $PDF::API2::VERSION, ", width = ", $p->width, "\n"; > > This gives: > > 2.028, width = 500 > > So the former does something, but it definitely doesn't create the desired > image. > > Does this help? > > Thanks, > Johan


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.