pajoye          Wed Apr  4 01:34:51 2007 UTC

  Modified files:              (Branch: PHP_5_2)
    /php-src/ext/gd/libgd       gd_gif_in.c 
    /php-src/ext/gd/tests       bug37360.phpt 
  Log:
  - Sync with gd 2.0.35 (bug #52, #60 and #66)
   - Improve TS of gif loading code (Roman Nemecek, Nuno, Pierre)
   - a frame size must be confined to the screen defition (Pierre)
   - be sure to always read the dimensions in the frame and does not use
     the screen size (see #66 for a side effect) (Pierre)
  - Update #37360 test. The frame does not fit the logical screen (specs 
    tell that it must fit) (Pierre)
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/gd/libgd/gd_gif_in.c?r1=1.5.4.2.2.9&r2=1.5.4.2.2.10&diff_format=u
Index: php-src/ext/gd/libgd/gd_gif_in.c
diff -u php-src/ext/gd/libgd/gd_gif_in.c:1.5.4.2.2.9 
php-src/ext/gd/libgd/gd_gif_in.c:1.5.4.2.2.10
--- php-src/ext/gd/libgd/gd_gif_in.c:1.5.4.2.2.9        Thu Mar  8 20:24:53 2007
+++ php-src/ext/gd/libgd/gd_gif_in.c    Wed Apr  4 01:34:50 2007
@@ -61,12 +61,14 @@
 } GifScreen;
 #endif
 
+#if 0
 static struct {
        int     transparent;
        int     delayTime;
        int     inputFlag;
        int     disposal;
 } Gif89 = { -1, -1, -1, 0 };
+#endif
 
 #define STACK_SIZE ((1<<(MAX_LWZ_BITS))*2)
 
@@ -87,14 +89,12 @@
 } LZW_STATIC_DATA;
 
 static int ReadColorMap (gdIOCtx *fd, int number, unsigned char 
(*buffer)[256]);
-static int DoExtension (gdIOCtx *fd, int label, int *Transparent);
-static int GetDataBlock (gdIOCtx *fd, unsigned char *buf);
-static int GetCode (gdIOCtx *fd, CODE_STATIC_DATA *scd, int code_size, int 
flag);
-static int LWZReadByte (gdIOCtx *fd, LZW_STATIC_DATA *sd, int flag, int 
input_code_size);
+static int DoExtension (gdIOCtx *fd, int label, int *Transparent, int 
*ZeroDataBlockP);
+static int GetDataBlock (gdIOCtx *fd, unsigned char *buf, int *ZeroDataBlockP);
+static int GetCode (gdIOCtx *fd, CODE_STATIC_DATA *scd, int code_size, int 
flag, int *ZeroDataBlockP);
+static int LWZReadByte (gdIOCtx *fd, LZW_STATIC_DATA *sd, char flag, int 
input_code_size, int *ZeroDataBlockP);
 
-static void ReadImage (gdImagePtr im, gdIOCtx *fd, int len, int height, 
unsigned char (*cmap)[256], int interlace); /*1.4//, int ignore); */
-
-int ZeroDataBlock;
+static void ReadImage (gdImagePtr im, gdIOCtx *fd, int len, int height, 
unsigned char (*cmap)[256], int interlace, int *ZeroDataBlockP); /*1.4//, int 
ignore); */
 
 gdImagePtr gdImageCreateFromGifSource(gdSourcePtr inSource) /* {{{ */
 {
@@ -124,24 +124,26 @@
 
 gdImagePtr gdImageCreateFromGifCtx(gdIOCtxPtr fd) /* {{{ */
 {
-       /* 1.4       int imageNumber; */
        int BitPixel;
+#if 0
        int ColorResolution;
        int Background;
        int AspectRatio;
+#endif
        int Transparent = (-1);
        unsigned char   buf[16];
        unsigned char   c;
        unsigned char   ColorMap[3][MAXCOLORMAPSIZE];
        unsigned char   localColorMap[3][MAXCOLORMAPSIZE];
-       int             imw, imh;
-       int             useGlobalColormap;
+       int             imw, imh, screen_width, screen_height;
+       int             gif87a, useGlobalColormap;
        int             bitPixel;
        int            i;
        /*1.4//int             imageCount = 0; */
 
+       int ZeroDataBlock = FALSE;
+
        gdImagePtr im = 0;
-       ZeroDataBlock = FALSE;
 
        /*1.4//imageNumber = 1; */
        if (! ReadOK(fd,buf,6)) {
@@ -151,19 +153,26 @@
                return 0;
        }
 
-       if ((strncmp((char*)buf+3, "87a", 3) != 0) && (strncmp((char*)buf+3, 
"89a", 3) != 0)) {
+       if (memcmp((char *)buf+3, "87a", 3) == 0) {
+               gif87a = 1;
+       } else if (memcmp((char *)buf+3, "89a", 3) == 0) {
+               gif87a = 0;
+       } else {
                return 0;
        }
+
        if (! ReadOK(fd,buf,7)) {
                return 0;
        }
+
        BitPixel        = 2<<(buf[4]&0x07);
+#if 0
        ColorResolution = (int) (((buf[4]&0x70)>>3)+1);
        Background      = buf[5];
        AspectRatio     = buf[6];
-
-       imw = LM_to_uint(buf[0],buf[1]);
-       imh = LM_to_uint(buf[2],buf[3]);
+#endif
+       screen_width = imw = LM_to_uint(buf[0],buf[1]);
+       screen_height = imh = LM_to_uint(buf[2],buf[3]);
 
        if (BitSet(buf[4], LOCALCOLORMAP)) {    /* Global Colormap */
                if (ReadColorMap(fd, BitPixel, ColorMap)) {
@@ -171,6 +180,9 @@
                }
        }
        for (;;) {
+               int top, left;
+               int width, height;
+
                if (! ReadOK(fd,&c,1)) {
                        return 0;
                }
@@ -182,7 +194,7 @@
                        if (! ReadOK(fd,&c,1)) {
                                return 0;
                        }
-                       DoExtension(fd, c, &Transparent);
+                       DoExtension(fd, c, &Transparent, &ZeroDataBlock);
                        continue;
                }
 
@@ -199,29 +211,33 @@
                useGlobalColormap = ! BitSet(buf[8], LOCALCOLORMAP);
 
                bitPixel = 1<<((buf[8]&0x07)+1);
-
-               if (!useGlobalColormap) {
-                       if (ReadColorMap(fd, bitPixel, localColorMap)) {
-                               return 0;
+               left = LM_to_uint(buf[0], buf[1]);
+               top = LM_to_uint(buf[2], buf[3]);
+               width = LM_to_uint(buf[4], buf[5]);
+               height = LM_to_uint(buf[6], buf[7]);
+
+               if (left + width > screen_width || top + height > 
screen_height) {
+                       if (VERBOSE) {
+                               printf("Frame is not confined to screen 
dimension.\n");
                        }
+                       return 0;
                }
 
-               if (!(im = gdImageCreate(imw, imh))) {
+               if (!(im = gdImageCreate(width, height))) {
                        return 0;
                }
-
                im->interlace = BitSet(buf[8], INTERLACE);
                if (! useGlobalColormap) {
-                       ReadImage(im, fd, imw, imh, localColorMap,
-                                       BitSet(buf[8], INTERLACE));
-                       /*1.4//imageCount != imageNumber); */
+                       if (ReadColorMap(fd, bitPixel, localColorMap)) { 
+                               return 0;
+                       }
+                       ReadImage(im, fd, width, height, localColorMap, 
+                                       BitSet(buf[8], INTERLACE), 
&ZeroDataBlock);
                } else {
-                       ReadImage(im, fd, imw, imh,
-                                       ColorMap,
-                                       BitSet(buf[8], INTERLACE));
-                       /*1.4//imageCount != imageNumber); */
+                       ReadImage(im, fd, width, height,
+                                               ColorMap, 
+                                               BitSet(buf[8], INTERLACE), 
&ZeroDataBlock);
                }
-
                if (Transparent != (-1)) {
                        gdImageColorTransparent(im, Transparent);
                }
@@ -233,12 +249,10 @@
        if (!im) {
                return 0;
        }
-
        if (!im->colorsTotal) {
                gdImageDestroy(im);
                return 0;
        }
-
        /* Check for open colors at the end, so
           we can reduce colorsTotal and ultimately
           BitsPerPixel */
@@ -273,34 +287,37 @@
 }
 /* }}} */
 
-static int DoExtension(gdIOCtx *fd, int label, int *Transparent) /* {{{ */
+static int
+DoExtension(gdIOCtx *fd, int label, int *Transparent, int *ZeroDataBlockP)
 {
        unsigned char buf[256];
 
        switch (label) {
                case 0xf9:              /* Graphic Control Extension */
                        memset(buf, 0, 4); /* initialize a few bytes in the 
case the next function fails */
-                       (void) GetDataBlock(fd, (unsigned char*) buf);
+               (void) GetDataBlock(fd, (unsigned char*) buf, ZeroDataBlockP);
+#if 0
                        Gif89.disposal    = (buf[0] >> 2) & 0x7;
                        Gif89.inputFlag   = (buf[0] >> 1) & 0x1;
                        Gif89.delayTime   = LM_to_uint(buf[1],buf[2]);
+#endif
                        if ((buf[0] & 0x1) != 0)
                                *Transparent = buf[3];
 
-                       while (GetDataBlock(fd, (unsigned char*) buf) > 0)
-                               ;
+                       while (GetDataBlock(fd, (unsigned char*) buf, 
ZeroDataBlockP) > 0);
                        return FALSE;
                default:
                        break;
        }
-       while (GetDataBlock(fd, (unsigned char*) buf) > 0)
+       while (GetDataBlock(fd, (unsigned char*) buf, ZeroDataBlockP) > 0)
                ;
 
        return FALSE;
 }
 /* }}} */
 
-static int GetDataBlock_(gdIOCtx *fd, unsigned char *buf) /* {{{ */
+static int
+GetDataBlock_(gdIOCtx *fd, unsigned char *buf, int *ZeroDataBlockP)
 {
        unsigned char   count;
 
@@ -308,7 +325,7 @@
                return -1;
        }
 
-       ZeroDataBlock = count == 0;
+       *ZeroDataBlockP = count == 0;
 
        if ((count != 0) && (! ReadOK(fd, buf, count))) {
                return -1;
@@ -318,14 +335,15 @@
 }
 /* }}} */
 
-static int GetDataBlock(gdIOCtx *fd, unsigned char *buf) /* {{{ */
+static int
+GetDataBlock(gdIOCtx *fd, unsigned char *buf, int *ZeroDataBlockP)
 {
        int rv;
        int i;
-       char *tmp = NULL;
 
-       rv = GetDataBlock_(fd,buf);
+       rv = GetDataBlock_(fd,buf, ZeroDataBlockP);
        if (VERBOSE) {
+               char *tmp = NULL;
                if (rv > 0) {
                        tmp = safe_emalloc(3 * rv, sizeof(char), 1);
                        for (i=0;i<rv;i++) {
@@ -341,7 +359,8 @@
 }
 /* }}} */
 
-static int GetCode_(gdIOCtx *fd, CODE_STATIC_DATA *scd, int code_size, int 
flag) /* {{{ */
+static int
+GetCode_(gdIOCtx *fd, CODE_STATIC_DATA *scd, int code_size, int flag, int 
*ZeroDataBlockP)
 {
        int           i, j, ret;
        unsigned char count;
@@ -364,7 +383,7 @@
                scd->buf[0] = scd->buf[scd->last_byte-2];
                scd->buf[1] = scd->buf[scd->last_byte-1];
 
-               if ((count = GetDataBlock(fd, &scd->buf[2])) <= 0)
+               if ((count = GetDataBlock(fd, &scd->buf[2], ZeroDataBlockP)) <= 
0)
                        scd->done = TRUE;
 
                scd->last_byte = 2 + count;
@@ -380,17 +399,19 @@
        return ret;
 }
 
-static int GetCode(gdIOCtx *fd, CODE_STATIC_DATA *scd, int code_size, int 
flag) /* {{{ */
+static int
+GetCode(gdIOCtx *fd, CODE_STATIC_DATA *scd, int code_size, int flag, int 
*ZeroDataBlockP)
 {
        int rv;
 
-       rv = GetCode_(fd, scd, code_size, flag);
-       if (VERBOSE) php_gd_error_ex(E_NOTICE, "[GetCode(,%d,%d) returning 
%d]",code_size,flag,rv);
+ rv = GetCode_(fd, scd, code_size,flag, ZeroDataBlockP);
+ if (VERBOSE) printf("[GetCode(,%d,%d) returning %d]\n",code_size,flag,rv);
        return(rv);
 }
 /* }}} */
 
-static int LWZReadByte_(gdIOCtx *fd, LZW_STATIC_DATA *sd, int flag, int 
input_code_size) /* {{{ */
+static int
+LWZReadByte_(gdIOCtx *fd, LZW_STATIC_DATA *sd, char flag, int input_code_size, 
int *ZeroDataBlockP)
 {
        int code, incode, i;
 
@@ -402,7 +423,7 @@
                sd->max_code_size = 2*sd->clear_code;
                sd->max_code = sd->clear_code+2;
 
-               GetCode(fd, &sd->scd, 0, TRUE);
+               GetCode(fd, &sd->scd, 0, TRUE, ZeroDataBlockP);
 
                sd->fresh = TRUE;
 
@@ -420,7 +441,7 @@
                sd->fresh = FALSE;
                do {
                        sd->firstcode = sd->oldcode =
-                               GetCode(fd, &sd->scd, sd->code_size, FALSE);
+                       GetCode(fd, &sd->scd, sd->code_size, FALSE, 
ZeroDataBlockP);
                } while (sd->firstcode == sd->clear_code);
                return sd->firstcode;
        }
@@ -428,7 +449,7 @@
        if (sd->sp > sd->stack)
                return *--sd->sp;
 
-       while ((code = GetCode(fd, &sd->scd, sd->code_size, FALSE)) >= 0) {
+               while ((code = GetCode(fd, &sd->scd, sd->code_size, FALSE, 
ZeroDataBlockP)) >= 0) {
                if (code == sd->clear_code) {
                        for (i = 0; i < sd->clear_code; ++i) {
                                sd->table[0][i] = 0;
@@ -441,16 +462,16 @@
                        sd->max_code = sd->clear_code+2;
                        sd->sp = sd->stack;
                        sd->firstcode = sd->oldcode =
-                               GetCode(fd, &sd->scd, sd->code_size, FALSE);
+                                                               GetCode(fd, 
&sd->scd, sd->code_size, FALSE, ZeroDataBlockP);
                        return sd->firstcode;
                } else if (code == sd->end_code) {
                        int             count;
                        unsigned char   buf[260];
 
-                       if (ZeroDataBlock)
+                       if (*ZeroDataBlockP)
                                return -2;
 
-                       while ((count = GetDataBlock(fd, buf)) > 0)
+                       while ((count = GetDataBlock(fd, buf, ZeroDataBlockP)) 
> 0)
                                ;
 
                        if (count != 0)
@@ -503,17 +524,19 @@
 }
 /* }}} */
 
-static int LWZReadByte(gdIOCtx *fd, LZW_STATIC_DATA *sd, int flag, int 
input_code_size) /* {{{ */
+static int
+LWZReadByte(gdIOCtx *fd, LZW_STATIC_DATA *sd, char flag, int input_code_size, 
int *ZeroDataBlockP)
 {
        int rv;
 
-       rv = LWZReadByte_(fd, sd, flag, input_code_size);
-       if (VERBOSE) php_gd_error_ex(E_NOTICE, "[LWZReadByte(,%d,%d) returning 
%d]",flag,input_code_size,rv);
+ rv = LWZReadByte_(fd, sd, flag, input_code_size, ZeroDataBlockP);
+ if (VERBOSE) printf("[LWZReadByte(,%d,%d) returning 
%d]\n",flag,input_code_size,rv);
        return(rv);
 }
 /* }}} */
 
-static void ReadImage(gdImagePtr im, gdIOCtx *fd, int len, int height, 
unsigned char (*cmap)[256], int interlace) /* {{{ */ /*1.4//, int ignore) */
+static void
+ReadImage(gdImagePtr im, gdIOCtx *fd, int len, int height, unsigned char 
(*cmap)[256], int interlace, int *ZeroDataBlockP) /*1.4//, int ignore) */
 {
        unsigned char   c;
        int             v;
@@ -542,7 +565,7 @@
        }
        /* Many (perhaps most) of these colors will remain marked open. */
        im->colorsTotal = gdMaxColors;
-       if (LWZReadByte(fd, &sd, TRUE, c) < 0) {
+       if (LWZReadByte(fd, &sd, TRUE, c, ZeroDataBlockP) < 0) {
                return;
        }
 
@@ -556,7 +579,7 @@
        /*        return; */
        /*} */
 
-       while ((v = LWZReadByte(fd, &sd, FALSE, c)) >= 0 ) {
+       while ((v = LWZReadByte(fd, &sd, FALSE, c, ZeroDataBlockP)) >= 0 ) {
                /* This how we recognize which colors are actually used. */
                if (im->open[v]) {
                        im->open[v] = 0;
@@ -598,7 +621,7 @@
        }
 
 fini:
-       if (LWZReadByte(fd, &sd, FALSE, c)>=0) {
+       if (LWZReadByte(fd, &sd, FALSE, c, ZeroDataBlockP) >=0) {
                /* Ignore extra */
        }
 }
http://cvs.php.net/viewvc.cgi/php-src/ext/gd/tests/bug37360.phpt?r1=1.1.2.2&r2=1.1.2.3&diff_format=u
Index: php-src/ext/gd/tests/bug37360.phpt
diff -u php-src/ext/gd/tests/bug37360.phpt:1.1.2.2 
php-src/ext/gd/tests/bug37360.phpt:1.1.2.3
--- php-src/ext/gd/tests/bug37360.phpt:1.1.2.2  Mon May  8 11:50:47 2006
+++ php-src/ext/gd/tests/bug37360.phpt  Wed Apr  4 01:34:50 2007
@@ -11,4 +11,5 @@
 var_dump($im);
 ?>
 --EXPECTF--
-resource(%d) of type (gd)
+Warning: imagecreatefromgif(): '%s' is not a valid GIF file in %s on line %d
+bool(false)

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to