Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Catalyst: Dev

Corrupted PNG Files after Running catalyst.pl Script

 

 

Catalyst dev RSS feed   Index | Next | Previous | View Threaded


conrad.halling at gmail

Jan 1, 2012, 8:49 PM

Post #1 of 3 (663 views)
Permalink
Corrupted PNG Files after Running catalyst.pl Script

When I use the catalyst command to create a new project on my Windows
laptop, I find that the PNG files in root/static/images directory are
corrupted and cannot be displayed in the web page.

I am using ActiveState ActivePerl 5.14.2 Build 1402 with Windows Vista. I
used ActiveState's Perl Package Manager (PPM) to install Catalyst-Runtime
5.90007 and Catalyst-Devel 1.36.

After some investigation using the Cygwin dump utility, I discovered that
each PNG file is one byte shorter than the original file, and this is caused
by the conversion of the 5th and 6th bytes of the file, "0d0a", to "0a"
during the copy process (conversion of CRLF to LF). This immediately
suggests that the files are being copied as text files and not as binary
files (a crucial distinction for Windows that is not relevant for
Linux/Unix/Mac OS X).

Original file:

$ dump btn_88x31_built_shadow.png
btn_88x31_built_shadow.png:
00000000 8950 4e47 0d0a 1a0a 0000 000d 4948 4452 .PNG........IHDR

Copied file:

$ dump btn_88x31_built_shadow.png
btn_88x31_built_shadow.png:
00000000 8950 4e47 0a1a 0a00 0000 0d49 4844 5200 .PNG.......IHDR.

I read the source code for Catalyst::Helper and found that the _mk_images
method gets the content of each PNG file by calling the get_sharedir_file
method. This method creates a Path::Class::File object on which it calls the
slurp method to get and return the contents of the PNG file.

my $file = file( $dist_dir, @filename);
Carp::confess("Cannot find $file") unless -r $file;
my $contents = $file->slurp;
return $contents;

I can find no indication that Path::Class::File is reading the file using
binmode, and I believe this is causing the conversion of the "0d0a" to "0a"
when it reads the file.

A possible fix for this bug is to pass a ":raw" iomode to the slurp method,
as follows:

my $contents = $file->slurp( iomode => "<:raw" );

I have not tested this solution because it appears that the
get_sharedir_file method is used also to obtain text files, and I'm
uncertain what the side-effects of this possible fix will be on text files.


--
Conrad Halling
conrad.halling [at] gmail





_______________________________________________
Catalyst-dev mailing list
Catalyst-dev [at] lists
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev


bobtfish at bobtfish

Jan 2, 2012, 3:36 AM

Post #2 of 3 (616 views)
Permalink
Re: Corrupted PNG Files after Running catalyst.pl Script [In reply to]

On 2 Jan 2012, at 04:49, Conrad Halling wrote:

> A possible fix for this bug is to pass a ":raw" iomode to the slurp
> method,
> as follows:
>
> my $contents = $file->slurp( iomode => "<:raw" );
>
> I have not tested this solution because it appears that the
> get_sharedir_file method is used also to obtain text files, and I'm
> uncertain what the side-effects of this possible fix will be on text
> files.

We should be slurping files verbatim, always (including the text files).

I've made this change and pushed it to master - can you try this for
me to ensure the issue is corrected before I release it?

git://git.shadowcat.co.uk/catagits/Catalyst-Devel

Thanks in advance!

Cheers
t0m



_______________________________________________
Catalyst-dev mailing list
Catalyst-dev [at] lists
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev


conrad.halling at gmail

Jan 2, 2012, 6:12 PM

Post #3 of 3 (623 views)
Permalink
Re: Corrupted PNG Files after Running catalyst.pl Script [In reply to]

Tomas Doran wrote:

> On 2 Jan 2012, at 04:49, Conrad Halling wrote:
>
> > A possible fix for this bug is to pass a ":raw" iomode to the slurp
> > method, as follows:
> >
> > my $contents = $file->slurp( iomode => "<:raw" );
> >
> > I have not tested this solution because it appears that the
> > get_sharedir_file method is used also to obtain text files, and I'm
> > uncertain what the side-effects of this possible fix will be on text
> > files.
>
> We should be slurping files verbatim, always (including the text
> files).
>
> I've made this change and pushed it to master - can you try this for me
> to ensure the issue is corrected before I release it?
>
> git://git.shadowcat.co.uk/catagits/Catalyst-Devel
>
> Thanks in advance!
>
> Cheers
> t0m

The fix works. Thanks!

--
Conrad Halling
conrad.halling [at] sphaerula




_______________________________________________
Catalyst-dev mailing list
Catalyst-dev [at] lists
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev

Catalyst dev RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.