Bug #13213 Updated: Unknown image format
ID: 13213
Comment by: mul@rentapacs.com
Old Reported By: pulstar@mail.com
Reported By: mul@rentapacs.com
Status: Analyzed
Bug Type: GetImageSize related
Operating System: Linux RedHat 7.1
PHP Version: 4.1.1
New Comment:
Solution: Read additional bytes to resync on the marker sequence. If
marker length is too short, nothing is lost. If too long, one marker
will be missing. Besides that APPn in $info array will contain
consistent entries and no bogus markers. Uhm, ... and if the JPEG
format follows the spec and contains correct marker lengths, it will
work also ;-)
This patch against 4.1.1 might do the trick:
--- ext/standard/image.c.orig Sat Aug 11 19:03:37 2001
+++ ext/standard/image.c Tue Jan 22 22:10:42 2002
@@ -253,12 +253,20 @@
/* {{{ php_next_marker
*/
-static unsigned int php_next_marker(int socketd, FILE *fp, int
issock)
+static unsigned int php_next_marker(int socketd, FILE *fp, int issock,
int isfirst)
/* get next marker byte from file */
{
int c;
- /* get marker byte, swallowing possible padding */
+ if (!isfirst) {
+ /* swallow bytes resulting from short marker length */
+ do {
+ if ((c = FP_FGETC(socketd, fp, issock)) ==
EOF)
+ return M_EOI; /* we hit EOF */
+ } while (c != 0xff);
+ }
+
+ /* get marker byte, swallowing possible 0xff padding */
do {
if ((c = FP_FGETC(socketd, fp, issock)) == EOF)
return M_EOI; /* we hit EOF */
@@ -320,12 +328,14 @@
static struct gfxinfo *php_handle_jpeg (int socketd, FILE *fp, int
issock, pval *info)
{
struct gfxinfo *result = NULL;
+ int isfirst = 1; /* First marker after JPEG sig 'FF D8
FF' */
unsigned int marker;
char tmp[2];
unsigned char a[4];
for (;;) {
- marker = php_next_marker(socketd, fp, issock);
+ marker = php_next_marker(socketd, fp, issock,
isfirst);
+ isfirst = 0;
switch (marker) {
case M_SOF0:
case M_SOF1:
Previous Comments:
------------------------------------------------------------------------
[2002-01-22 13:15:04] mul@rentapacs.com
Offending images contain COM marker with length parameter two bytes
short. This breaks further decoding of JPEG header - GetImageSize()
cannot return useful information.
------------------------------------------------------------------------
[2002-01-11 17:09:08] lobbin@php.net
I experience the same on 4.1.1
------------------------------------------------------------------------
[2002-01-07 10:17:09] pulstar@mail.com
ID: 13213
Updated by: lobbin
I get a 404 not found on this url.
http://www.dr-micro.net/files/gis.php
Sorry. I sent this script to the server months ago and somebody removed
it from there... Please try again.
------------------------------------------------------------------------
[2002-01-07 08:49:28] lobbin@php.net
I get a 404 not found on this url.
------------------------------------------------------------------------
[2001-09-08 15:07:33] pulstar@mail.com
GetImageSize() don't recognize the JPG image format generated by a
software called Arles Image Web Page Creator. I make a test script,
that you can see at the address below. There have also links to sample
images, etc.
http://www.dr-micro.net/files/gis.php
The browser display the images normally. This program website is at
http://www.digitaldutch.com
------------------------------------------------------------------------
Edit this bug report at http://bugs.php.net/?id=13213&edit=1
Thread (6 messages)