]> granicus.if.org Git - php/commitdiff
Fix #73161: imagecreatefromgd2() may leak memory
authorChristoph M. Becker <cmbecker69@gmx.de>
Sat, 24 Sep 2016 10:36:54 +0000 (12:36 +0200)
committerChristoph M. Becker <cmbecker69@gmx.de>
Sat, 24 Sep 2016 10:36:54 +0000 (12:36 +0200)
NEWS
ext/gd/libgd/gd_gd2.c
ext/gd/tests/bug73161.gd2 [new file with mode: 0644]
ext/gd/tests/bug73161.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index a7a71846bb200544d4ad9abf91dee611bc809ef0..3863bdaa2666c6ef11c007018ad8ee4d7699f8f7 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -30,6 +30,7 @@ PHP                                                                        NEWS
   . Fixed bug #73155 (imagegd2() writes wrong chunk sizes on boundaries). (cmb)
   . Fixed bug #73159 (imagegd2(): unrecognized formats may result in corrupted
     files). (cmb)
+  . Fixed bug #73161 (imagecreatefromgd2() may leak memory). (cmb)
 
 - Mbstring:
   . Fixed bug #72994 (mbc_to_code() out of bounds read). (Laruence, cmb)
index 57d5844510f14ef413da73f53bece499d847067e..d06f328425e8188f13b7720b93f0181ecda1893a 100644 (file)
@@ -191,21 +191,21 @@ static gdImagePtr _gd2CreateFromFile (gdIOCtxPtr in, int *sx, int *sy, int *cs,
        }
        if (im == NULL) {
                GD2_DBG(php_gd_error("Could not create gdImage"));
-               goto fail1;
+               goto fail2;
        }
 
        if (!_gdGetColors(in, im, (*vers) == 2)) {
                GD2_DBG(php_gd_error("Could not read color palette"));
-               goto fail2;
+               goto fail3;
        }
        GD2_DBG(php_gd_error("Image palette completed: %d colours", im->colorsTotal));
 
        return im;
 
-fail2:
+fail3:
        gdImageDestroy(im);
-       return 0;
-
+fail2:
+       gdFree(*cidx);
 fail1:
        return 0;
 }
diff --git a/ext/gd/tests/bug73161.gd2 b/ext/gd/tests/bug73161.gd2
new file mode 100644 (file)
index 0000000..f5084e4
Binary files /dev/null and b/ext/gd/tests/bug73161.gd2 differ
diff --git a/ext/gd/tests/bug73161.phpt b/ext/gd/tests/bug73161.phpt
new file mode 100644 (file)
index 0000000..42ad718
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--
+Bug #73161 (imagecreatefromgd2() may leak memory)
+--DESCRIPTION--
+We're testing for a memory leak that might not even show up with valgrind.
+--SKIPIF--
+<?php
+if (!extension_loaded('gd')) die('skip gd extension not available');
+?>
+--FILE--
+<?php
+$im = imagecreatefromgd2(__DIR__ . DIRECTORY_SEPARATOR . 'bug73161.gd2');
+var_dump($im);
+?>
+===DONE===
+--EXPECTF--
+Warning: imagecreatefromgd2(): '%s' is not a valid GD2 file in %s on line %d
+bool(false)
+===DONE===