]> granicus.if.org Git - php/commitdiff
Throw TypeError instead of warning in case of invalid path
authorChristoph M. Becker <cmbecker69@gmx.de>
Thu, 13 Jun 2019 15:05:47 +0000 (17:05 +0200)
committerChristoph M. Becker <cmbecker69@gmx.de>
Thu, 13 Jun 2019 20:37:50 +0000 (22:37 +0200)
For consistency with imagegd(), imagegd2() and imagexbm(), which throw
a TypeError if a path containing NUL bytes is given, we throw a
TypeError for the other image writer functions as well.

ext/gd/gd_ctx.c
ext/gd/tests/imagebmp_nullbyte_injection.phpt
ext/gd/tests/imagegif_nullbyte_injection.phpt
ext/gd/tests/imagejpeg_nullbyte_injection.phpt
ext/gd/tests/imagepng_nullbyte_injection.phpt
ext/gd/tests/imagewbmp_nullbyte_injection.phpt
ext/gd/tests/imagewebp_nullbyte_injection.phpt

index d563eb13841e1b73855d5e1c0808337205022085..dcdf8ad803ccc56ce7e6bdef01177463470aa520 100644 (file)
@@ -139,8 +139,8 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type,
                        close_stream = 0;
                } else if (Z_TYPE_P(to_zval) == IS_STRING) {
                        if (CHECK_ZVAL_NULL_PATH(to_zval)) {
-                               php_error_docref(NULL, E_WARNING, "Invalid 2nd parameter, filename must not contain null bytes");
-                               RETURN_FALSE;
+                               zend_type_error("Invalid 2nd parameter, filename must not contain null bytes");
+                               return;
                        }
 
                        stream = php_stream_open_wrapper(Z_STRVAL_P(to_zval), "wb", REPORT_ERRORS|IGNORE_PATH|IGNORE_URL_WIN, NULL);
index 0b6d1843d38f9a2b4e0747ef36007d50ff217789..00d0a7168c7f0f4b599b35fa4a6914d222fa99ea 100644 (file)
@@ -8,10 +8,11 @@ if (!gd_info()['BMP Support']) die('skip BMP support not available');
 --FILE--
 <?php
 $image = imagecreate(1,1);// 1px image
-var_dump(imagebmp($image, "./foo\0bar"));
+try {
+    imagebmp($image, "./foo\0bar");
+} catch (TypeError $e) {
+    echo $e->getMessage(), "\n";
+}
 ?>
-===DONE===
---EXPECTF--
-Warning: imagebmp(): Invalid 2nd parameter, filename must not contain null bytes in %s on line %d
-bool(false)
-===DONE===
+--EXPECT--
+Invalid 2nd parameter, filename must not contain null bytes
index 5793e90151aec6d68ebe7e5edb14622f30b34d79..4518ecad2737d2274e1bfaf910fa54f9f5b577a6 100644 (file)
@@ -7,8 +7,11 @@ if(!extension_loaded('gd')){ die('skip gd extension not available'); }
 --FILE--
 <?php
 $image = imagecreate(1,1);// 1px image
-var_dump(imagegif($image, "./foo\0bar"));
+try {
+    imagegif($image, "./foo\0bar");
+} catch (TypeError $e) {
+    echo $e->getMessage(), "\n";
+}
 ?>
---EXPECTF--
-Warning: imagegif(): Invalid 2nd parameter, filename must not contain null bytes in %s on line %d
-bool(false)
+--EXPECT--
+Invalid 2nd parameter, filename must not contain null bytes
index 381421d144654d6637db51040b493fafec2c32ba..1a7f6da03c0c16f420af141e593aa6f4ef2618a1 100644 (file)
@@ -11,8 +11,11 @@ if (!isset($support['JPEG Support']) || $support['JPEG Support'] === false) {
 --FILE--
 <?php
 $image = imagecreate(1,1);// 1px image
-var_dump(imagejpeg($image, "./foo\0bar"));
+try {
+    imagejpeg($image, "./foo\0bar");
+} catch (TypeError $e) {
+    echo $e->getMessage(), "\n";
+}
 ?>
---EXPECTF--
-Warning: imagejpeg(): Invalid 2nd parameter, filename must not contain null bytes in %s on line %d
-bool(false)
+--EXPECT--
+Invalid 2nd parameter, filename must not contain null bytes
index 773178541b5a3d673e928bc76fde4a2c47b71c6d..86d614ab60fe5e312852893784c307ea278e15dc 100644 (file)
@@ -11,8 +11,11 @@ if (!isset($support['PNG Support']) || $support['PNG Support'] === false) {
 --FILE--
 <?php
 $image = imagecreate(1,1);// 1px image
-var_dump(imagepng($image, "./foo\0bar"));
+try {
+    imagepng($image, "./foo\0bar");
+} catch (TypeError $e) {
+    echo $e->getMessage(), "\n";
+}
 ?>
 --EXPECTF--
-Warning: imagepng(): Invalid 2nd parameter, filename must not contain null bytes in %s on line %d
-bool(false)
+Invalid 2nd parameter, filename must not contain null bytes
index 6f7557d307aecaacefd1a73c9614b95c24376abc..cce38a63dffc7f25798aef5ba8697c97e1103d3a 100644 (file)
@@ -11,8 +11,11 @@ if (!isset($support['WBMP Support']) || $support['WBMP Support'] === false) {
 --FILE--
 <?php
 $image = imagecreate(1,1);// 1px image
-var_dump(imagewbmp($image, "./foo\0bar"));
+try {
+    imagewbmp($image, "./foo\0bar");
+} catch (TypeError $e) {
+    echo $e->getMessage(), "\n";
+}
 ?>
---EXPECTF--
-Warning: imagewbmp(): Invalid 2nd parameter, filename must not contain null bytes in %s on line %d
-bool(false)
+--EXPECT--
+Invalid 2nd parameter, filename must not contain null bytes
index 68712f282fed1c56f6304665e76c0985702656e3..82e45aca02459207e2065ca0644f66237ed48492 100644 (file)
@@ -11,8 +11,11 @@ if (!isset($support['WebP Support']) || $support['WebP Support'] === false) {
 --FILE--
 <?php
 $image = imagecreate(1,1);// 1px image
-var_dump(imagewebp($image, "./foo\0bar"));
+try {
+    imagewebp($image, "./foo\0bar");
+} catch (TypeError $e) {
+    echo $e->getMessage(), "\n";
+}
 ?>
---EXPECTF--
-Warning: imagewebp(): Invalid 2nd parameter, filename must not contain null bytes in %s on line %d
-bool(false)
+--EXPECT--
+Invalid 2nd parameter, filename must not contain null bytes