Skip Menu |
 

This queue is for tickets about the GD CPAN distribution.

Report information
The Basics
Id: 26146
Status: open
Priority: 0/
Queue: GD

People
Owner: Nobody in particular
Requestors: daxbert [...] yahoo.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: _image_type
Date: Fri, 6 Apr 2007 22:00:38 -0700 (PDT)
To: bug-GD [...] rt.cpan.org
From: Daxbert <daxbert [...] yahoo.com>
Download (untitled) / with headers
text/plain 1.5k
I've come across a few .jpg/.jpeg images which do not have the magic first four bytes required by _image_type() in Image.pm.PLS. A sample distribution follows: 377 330 377 333 4 377 330 377 340 22701 377 330 377 341 771 377 330 377 342 16 377 330 377 354 1 377 330 377 355 2 377 330 377 376 3032 If appropriate, I would suggest the following patch below: --------------------------------------------------------------------------------- --- GD/Image.pm.PLS.orig Fri Apr 6 21:50:20 2007 +++ GD/Image.pm.PLS Fri Apr 6 21:51:45 2007 @@ -171,9 +171,7 @@ my $data = shift; my $magic = substr($data,0,4); return 'Png' if $magic eq "\x89PNG"; - return 'Jpeg' if $magic eq "\377\330\377\340"; - return 'Jpeg' if $magic eq "\377\330\377\341"; - return 'Jpeg' if $magic eq "\377\330\377\356"; + return 'Jpeg' if substr($data,0,3) eq "\377\330\377"; return 'Gif' if $magic eq "GIF8"; return 'Gd2' if $magic eq "gd2\000"; return 'Xpm' if substr($data,0,9) eq "/* XPM */"; Show quoted text
____________________________________________________________________________________ Be a PS3 game guru. Get your game face on with the latest PS3 news and previews at Yahoo! Games. http://videogames.yahoo.com/platform?platform=120121
Download (untitled) / with headers
text/plain 1.5k
On Sat Apr 07 01:01:00 2007, daxbert@yahoo.com wrote: Show quoted text
> I've come across a few .jpg/.jpeg images which do not have the > magic first four bytes required by _image_type() in Image.pm.PLS. > > A sample distribution follows: > > 377 330 377 333 4 > 377 330 377 340 22701 > 377 330 377 341 771 > 377 330 377 342 16 > 377 330 377 354 1 > 377 330 377 355 2 > 377 330 377 376 3032 > > If appropriate, I would suggest the following patch below: > >
--------------------------------------------------------------------------------- Show quoted text
> > --- GD/Image.pm.PLS.orig Fri Apr 6 21:50:20 2007 > +++ GD/Image.pm.PLS Fri Apr 6 21:51:45 2007 > @@ -171,9 +171,7 @@ > my $data = shift; > my $magic = substr($data,0,4); > return 'Png' if $magic eq "\x89PNG"; > - return 'Jpeg' if $magic eq "\377\330\377\340"; > - return 'Jpeg' if $magic eq "\377\330\377\341"; > - return 'Jpeg' if $magic eq "\377\330\377\356"; > + return 'Jpeg' if substr($data,0,3) eq "\377\330\377"; > return 'Gif' if $magic eq "GIF8"; > return 'Gd2' if $magic eq "gd2\000"; > return 'Xpm' if substr($data,0,9) eq "/* XPM */"; > >
I second that. I have a file with magic "377 330 377 333", and this patch fixes the problem.
Download (untitled) / with headers
text/plain 1.1k
I've done a bit more research, and here's a slightly more accurate line: return 'Jpeg' if ((substr($data,0,3) eq "\377\330\377") && ord(substr($data,3,1)) >= 0xd0); Explanation is from: http://www.digicamsoft.com/itu/itu-t81-36.html c* are start of frame markers, which should be invalid, if defined before we have quant tables d0-d7: suspect, ("restart" before start?), but apparently at least ffc3 is used by some cameras (including nokia 3650) d8: suspect - Start of Image marker, would be invalid twice in a row d9: suspect - End of Image marker, would indicate a 0x0 image da, dc-df ? - didn't take the time to digest the spec db : OK - (this should be the most common by far) e0-ef: OK - reserved for application-specific extensions f0-fd: OK - reserved for jpeg extensions fe: OK - comment If you want to be more tolerant about passing possibly invalid data to libgd, you can allow any marker whatsoever to go thru: return 'Jpeg' if ((substr($data,0,3) eq "\377\330\377") && ord(substr($data,3,1)) >= 0xc0); More info is available on page 34 of the spec: http://www.digicamsoft.com/itu/itu-t81-38.html


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.