#define LOCALCOLORMAP 0x80
#define BitSet(byte, bit) (((byte) & (bit)) == (bit))
-#define ReadOK(file,buffer,len) (gdGetBuf(buffer, len, file) != 0)
+#define ReadOK(file,buffer,len) (gdGetBuf(buffer, len, file) > 0)
#define LM_to_uint(a,b) (((b)<<8)|(a))
imw = LM_to_uint(buf[4],buf[5]);
imh = LM_to_uint(buf[6],buf[7]);
- if (!(im = gdImageCreate(imw, imh))) {
- return 0;
- }
+
+ if (!useGlobalColormap) {
+ if (ReadColorMap(fd, bitPixel, localColorMap)) {
+ return 0;
+ }
+ }
+
+ if (!(im = gdImageCreate(imw, imh))) {
+ return 0;
+ }
+
im->interlace = BitSet(buf[8], INTERLACE);
if (! useGlobalColormap) {
- if (ReadColorMap(fd, bitPixel, localColorMap)) {
- return 0;
- }
ReadImage(im, fd, imw, imh, localColorMap,
BitSet(buf[8], INTERLACE));
/*1.4//imageCount != imageNumber); */
--- /dev/null
+--TEST--
+Bug #37346 (gdimagecreatefromgif, bad colormap)
+--SKIPIF--
+<?php
+ if (!extension_loaded('gd')) die("skip gd extension not available\n");
+ if (!GD_BUNDLED) die('skip external GD libraries always fail');
+?>
+--FILE--
+<?php
+$im = imagecreatefromgif(dirname(__FILE__) . '/bug37346.gif');
+?>
+--EXPECTF--
+Warning: imagecreatefromgif(): '%sbug37346.gif' is not a valid GIF file in %sbug37346.php on line %d