]> granicus.if.org Git - php/commitdiff
- libgd #101, imagecreatefromgd can crash if gdImageCreate fails
authorMattias Bengtsson <mattias@php.net>
Thu, 9 Aug 2007 14:21:38 +0000 (14:21 +0000)
committerMattias Bengtsson <mattias@php.net>
Thu, 9 Aug 2007 14:21:38 +0000 (14:21 +0000)
ext/gd/libgd/gd_gd.c
ext/gd/tests/libgd00101.gd [new file with mode: 0644]
ext/gd/tests/libgd00101.phpt [new file with mode: 0644]

index 2d259cdd514e3d3c2bce96be6ecc94f1bc9d0266..55587d43e851f742e54ee362feb59a7221343fa0 100644 (file)
@@ -122,6 +122,9 @@ static gdImagePtr _gdCreateFromFile (gdIOCtx * in, int *sx, int *sy)
        } else {
                im = gdImageCreate(*sx, *sy);
        }
+       if(!im) {
+               goto fail1;
+       }
        if (!_gdGetColors(in, im, gd2xFlag)) {
                goto fail2;
        }
diff --git a/ext/gd/tests/libgd00101.gd b/ext/gd/tests/libgd00101.gd
new file mode 100644 (file)
index 0000000..5516ce0
--- /dev/null
@@ -0,0 +1 @@
+ÿýÿý
\ No newline at end of file
diff --git a/ext/gd/tests/libgd00101.phpt b/ext/gd/tests/libgd00101.phpt
new file mode 100644 (file)
index 0000000..1c6623d
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--
+libgd #101 (imagecreatefromgd can crash if gdImageCreate fails)
+--SKIPIF--
+<?php
+       if (!extension_loaded('gd')) die("skip gd extension not available\n");
+       if (!GD_BUNDLED) die("skip requires bundled GD library\n");
+?>
+--FILE--
+<?php
+$im = imagecreatefromgd(dirname(__FILE__) . '/libgd00101.gd');
+var_dump($im);
+?>
+--EXPECTF--
+Warning: imagecreatefromgd(): gd warning: product of memory allocation multiplication would exceed INT_MAX, failing operation gracefully
+ in %slibgd00101.php on line %d
+
+Warning: imagecreatefromgd(): '%slibgd00101.gd' is not a valid GD file in %slibgd00101.php on line %d
+bool(false)