[Catalyst-dev] Corrupted PNG Files after Running catalyst.pl Script

Conrad Halling conrad.halling at gmail.com
Mon Jan 2 04:49:57 GMT 2012


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.com







More information about the Catalyst-dev mailing list