]> granicus.if.org Git - php/commitdiff
Fix #73157: imagegd2() ignores 3rd param if 4 are given
authorChristoph M. Becker <cmbecker69@gmx.de>
Fri, 23 Sep 2016 21:23:45 +0000 (23:23 +0200)
committerChristoph M. Becker <cmbecker69@gmx.de>
Fri, 23 Sep 2016 21:42:34 +0000 (23:42 +0200)
We must initialize `q` for *more* than three parameters, too.

NEWS
ext/gd/gd.c
ext/gd/tests/bug73157.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 1bbb1f4b2b4355a1e04a1306a9b5f02655e14bc8..b9ef512bd2a195b024e598a107d5fea11e6bbff5 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -26,6 +26,7 @@ PHP                                                                        NEWS
     cmb)
   . Fixed bug #53504 (imagettfbbox gives incorrect values for bounding box).
     (Mark Plomer, cmb)
+  . Fixed bug #73157 (imagegd2() ignores 3rd param if 4 are given). (cmb)
 
 - Mbstring:
   . Fixed bug #72994 (mbc_to_code() out of bounds read). (Laruence, cmb)
index 192aed0af4d0f4370ea067cb3b91c9fcf4051b86..5f086864ca363689def6d4d05da673109ba6c995 100644 (file)
@@ -2614,11 +2614,11 @@ static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char
 
        if (argc > 1) {
                fn = file;
-               if (argc == 3) {
+               if (argc >= 3) {
                        q = quality;
-               }
-               if (argc == 4) {
-                       t = type;
+                       if (argc == 4) {
+                               t = type;
+                       }
                }
        }
 
diff --git a/ext/gd/tests/bug73157.phpt b/ext/gd/tests/bug73157.phpt
new file mode 100644 (file)
index 0000000..b03e91e
--- /dev/null
@@ -0,0 +1,22 @@
+--TEST--
+Bug #73157 (imagegd2() ignores 3rd param if 4 are given)
+--SKIPIF--
+<?php
+if (!extension_loaded('gd')) die('skip gd extension not available');
+?>
+--FILE--
+<?php
+$im = imagecreate(8, 8);
+imagecolorallocate($im, 0, 0, 0);
+
+ob_start();
+imagegd2($im, null, 256, IMG_GD2_RAW);
+$buffer = ob_get_clean();
+
+$header = unpack('@10/nchunk_size', $buffer);
+printf("chunk size: %d\n", $header['chunk_size']);
+?>
+===DONE===
+--EXPECT--
+chunk size: 256
+===DONE===