Skip Menu |

This queue is for tickets about the App-Wallflower CPAN distribution.

Report information
The Basics
Id: 104754
Status: resolved
Priority: 0/
Queue: App-Wallflower

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

Bug Information
Severity: Normal
Broken in: 1.005
Fixed in: 1.006



Subject: Scramble Images
When running wallflower, the image is stored to static/image.jpg, but it's content is all messed up. Please find attached an example. This is the command I used: wallflower --application script.cgi --dir static/ Here is an example application: #!perl use Mojolicious::Lite; get '/' => sub { my $c = shift; $c->render(template => 'index'); }; app->start; __DATA__ @@ index.html.ep <html> <body> <h1>Image</h1> <img src="/image.jpg" /> </body> </html> @@ image.jpg (base64) R0lGODlhoACgAPfKAGet+oe16PTy72Sq94+55/fz8Gyv+cdQUKenp4CAgGex/qVsfoKWzX19fV5eXl1dXVRUVNzc3MpNSubm5s5NSsbGxouLi7GxsZKSkmxsbGhoaFZWVmOf4sZNTWuv+ri4uNHR0W6q8Wa1/6F2lMlOTJycnHJycs1KR81KRllZWWuu971aY4i153Kk2nV1dWum5W2x/dvb28nJyWRkZG2x/Gqv+G2m5oeHh3C3/2mv+ZmZmby8vJC55sxeXui3t2Sp9vj07leFuGag4s1hYc1kZJC66Pv27mah42Kf4vf08G+q63Gq6sxfX8pKSMpaWWay/stcXG6y/sdOTeezs2qt955xoKdnkmat+vfz74e152yv+G6y/GSp98lKSGyu+ERgf8NYXlmJvrFbgmS1/2ix/I+DuV2Sy2yy/Gy0/2Od22mo72qq6tQxRm6p759yitFGQGe4/9RHP2W0/VqMwm2y/sxLRm2x+12RykJceViIvaN0kG2w+22r84+Du12TzUhnimmw+dMzSWmp8Gqu916SzWys9e/v73Sj6Gyv+miw+3Cs9IqJw46EqJl4q2Op9muw+6Jsmmus9X+Y0lR/rmCX1Hif3rtPcGey/Gel6m+2/2ex/Wmw+2K4/4KVzGqu+G+1//n28pO961+U0V6Uz1N9rKZ1kmaz/maj56BvnnOj6MBXXsVEYH2X2Gex/EVigWez/FJ9q7tQc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O0a8fBBuQVVom0YdCdDghkwj3WKN3BBygYtmESw2KAOg0gBM7Q6lKHjm5Cp+lWGWuIGz38LIm1okTHD10VzQ7Xc26DxFC6AG6xdWlnT69izYy+a87bI6ga1i2bPXlTs5pbewVsnXXZ3CtEgLQ9XH559VJu7qX/M2Ry8cqiSncYSZhvAR99/UHl2XnyZGeiffXhZ9t5KESilzAYJrJZABukRhWBUFurX0Vv0NfQhVHrx1hICWZ3lQHSlGWJIiUGhFRAAOw== __END__
Subject: image.jpg
Download image.jpg
image/jpeg 3.8k
image.jpg
Subject: Re: [rt.cpan.org #104754] Scramble Images
Date: Wed, 3 Jun 2015 09:11:35 +0200
To: Alexander Becker via RT <bug-App-Wallflower [...] rt.cpan.org>
From: "Philippe Bruhat (BooK)" <book [...] cpan.org>
On Thu, May 28, 2015 at 01:46:26PM -0400, Alexander Becker via RT wrote: Show quoted text
> > This is the command I used: > wallflower --application script.cgi --dir static/ >
I copy/pasted your application in a script.cgi file on my Linux box, and ran: $ wallflower -a script.cgi -d static 200 / => static/index.html [74] 200 /image.jpg => static/image.jpg [3973] $ file static/image.jpg static/image.jpg: GIF image data, version 89a, 160 x 160 $ identify static/image.jpg static/image.jpg[0] GIF 160x160 160x160+0+0 8-bit sRGB 256c 3.97KB 0.000u 0:00.000 static/image.jpg[1] GIF 115x23 160x160+22+66 8-bit sRGB 256c 3.97KB 0.000u 0:00.000 So this is a GIF image with two frames. Looking at it with my browser, it looks fine (shows a Tk window with the text "Perl + Tk" with a blinking "+"). Running the application in parallel with `plackup -p 5000 script.cgi`, I did: $ lwp-request -des http://localhost:5000/image.jpg 200 OK Date: Tue, 02 Jun 2015 22:38:57 GMT Date: Tue, 02 Jun 2015 22:38:57 GMT Accept-Ranges: bytes ETag: "beb5ffb6b02170dea496b600198ee13e" Server: HTTP::Server::PSGI Content-Length: 3973 Content-Type: image/jpeg Last-Modified: Tue, 02 Jun 2015 22:38:41 GMT Client-Date: Tue, 02 Jun 2015 22:38:57 GMT Client-Peer: 127.0.0.1:5000 Client-Response-Num: 1 Apart from the fact that a GIF image is served with a content-type of image/jpeg, I didn't see anything weird. I then downloaded the attached image, and compared it with the one downloaded by wallflower: $ ls -l image.jpg static/image.jpg -rw-r----- 1 book book 3978 Jun 3 00:52 image.jpg -rw-r--r-- 1 book book 3973 Jun 3 00:40 static/image.jpg So there's 5 extra bytes, it seems. When comparing two hexdumps (basically comparing the text output of running the `hexdump` command on both files), the first difference I found was an extra 0x0d... Could if be an issue with DOS/Unix end-of-lines? (You're on Windows, aren't you?) What about opening the file for writing in binary mode? Does the following patch work for you? diff --git a/lib/Wallflower.pm b/lib/Wallflower.pm index b34aa34..9771c8a 100644 --- a/lib/Wallflower.pm +++ b/lib/Wallflower.pm @@ -125,7 +125,7 @@ sub get { # get a file to save the content in my $dir = ( $file = $target )->dir; $dir->mkpath if !-e $dir; - open my $fh, '>', $file or croak "Can't open $file for writing: $!"; + open my $fh, '> :raw :bytes', $file or croak "Can't open $file for writing: $!"; # copy content to the file if ( ref $content eq 'ARRAY' ) { -- Philippe Bruhat (BooK) When the employee is a fool, so is the employer. (Moral from Groo The Wanderer #26 (Epic))
Am Mi 03. Jun 2015, 03:11:44, BOOK schrieb: Show quoted text
> On Thu, May 28, 2015 at 01:46:26PM -0400, Alexander Becker via RT > wrote:
> > > > This is the command I used: > > wallflower --application script.cgi --dir static/ > >
> > I copy/pasted your application in a script.cgi file on my Linux box, > and ran: > > $ wallflower -a script.cgi -d static > 200 / => static/index.html [74] > 200 /image.jpg => static/image.jpg [3973] > > $ file static/image.jpg > static/image.jpg: GIF image data, version 89a, 160 x 160 > > $ identify static/image.jpg > static/image.jpg[0] GIF 160x160 160x160+0+0 8-bit sRGB 256c 3.97KB > 0.000u 0:00.000 > static/image.jpg[1] GIF 115x23 160x160+22+66 8-bit sRGB 256c 3.97KB > 0.000u 0:00.000 > > So this is a GIF image with two frames. Looking at it with my browser, > it > looks fine (shows a Tk window with the text "Perl + Tk" with a > blinking "+"). > > Running the application in parallel with `plackup -p 5000 script.cgi`, > I did: > > $ lwp-request -des http://localhost:5000/image.jpg > 200 OK > Date: Tue, 02 Jun 2015 22:38:57 GMT > Date: Tue, 02 Jun 2015 22:38:57 GMT > Accept-Ranges: bytes > ETag: "beb5ffb6b02170dea496b600198ee13e" > Server: HTTP::Server::PSGI > Content-Length: 3973 > Content-Type: image/jpeg > Last-Modified: Tue, 02 Jun 2015 22:38:41 GMT > Client-Date: Tue, 02 Jun 2015 22:38:57 GMT > Client-Peer: 127.0.0.1:5000 > Client-Response-Num: 1 > > Apart from the fact that a GIF image is served with a content-type of > image/jpeg, I didn't see anything weird. > > I then downloaded the attached image, and compared it with the one > downloaded by wallflower: > > $ ls -l image.jpg static/image.jpg > -rw-r----- 1 book book 3978 Jun 3 00:52 image.jpg > -rw-r--r-- 1 book book 3973 Jun 3 00:40 static/image.jpg > > So there's 5 extra bytes, it seems. When comparing two hexdumps > (basically > comparing the text output of running the `hexdump` command on both > files), > the first difference I found was an extra 0x0d... Could if be an issue > with DOS/Unix end-of-lines? (You're on Windows, aren't you?) What > about > opening the file for writing in binary mode? > > Does the following patch work for you? > > diff --git a/lib/Wallflower.pm b/lib/Wallflower.pm > index b34aa34..9771c8a 100644 > --- a/lib/Wallflower.pm > +++ b/lib/Wallflower.pm > @@ -125,7 +125,7 @@ sub get { > # get a file to save the content in > my $dir = ( $file = $target )->dir; > $dir->mkpath if !-e $dir; > - open my $fh, '>', $file or croak "Can't open $file for > writing: $!"; > + open my $fh, '> :raw :bytes', $file or croak "Can't open > $file for writing: $!"; > > # copy content to the file > if ( ref $content eq 'ARRAY' ) {
Yes, it worked! Once the file was written in binary mode, the image could be displayed. You were also right about the OS, I'm on Windows here.
On Wed Jun 03 13:51:18 2015, ASB wrote: Show quoted text
> Am Mi 03. Jun 2015, 03:11:44, BOOK schrieb:
> > > > Does the following patch work for you? > >
> > Yes, it worked! > Once the file was written in binary mode, the image could be displayed. >
So, after further investigation, the :bytes layer is unnecessary, since the content MUST be bytes according to the PSGI standard: https://metacpan.org/pod/distribution/PSGI/PSGI.pod#Body I'll apply the patch with only :raw and make a release shortly. Thanks! -- BooK
Am Mi 03. Jun 2015, 16:58:58, BOOK schrieb: Show quoted text
> On Wed Jun 03 13:51:18 2015, ASB wrote:
> > Am Mi 03. Jun 2015, 03:11:44, BOOK schrieb:
> > > > > > Does the following patch work for you? > > >
> > > > Yes, it worked! > > Once the file was written in binary mode, the image could be displayed. > >
> > So, after further investigation, the :bytes layer is unnecessary, since > the content MUST be bytes according to the PSGI standard: > https://metacpan.org/pod/distribution/PSGI/PSGI.pod#Body > > I'll apply the patch with only :raw and make a release shortly. > > Thanks! > > -- BooK
I quickly confirmed it. Omitting the :bytes option yields the same results. Thanks for patching!