com php-src: Throw TypeError instead of warning in case of invalid path: ext/gd/gd_ctx.c ext/gd/tests/imagebmp_nullbyte_inject ion.phpt
ext/gd/tests/imagegif_nullbyte_injection.php t ext/gd/tests/imagejpeg_nullbyte_injection.phpt ext/ gd/tests/imagepng_nullbyte_injection.phpt
ext/gd/tests/ imagewbmp_nullbyte_injection.phpt ext/gd/tests/imageweb p_nullbyte_injection.phpt

From: Date: Thu, 13 Jun 2019 20:37:50 +0000
Subject: com php-src: Throw TypeError instead of warning in case of invalid path: ext/gd/gd_ctx.c ext/gd/tests/imagebmp_nullbyte_inject ion.phpt
ext/gd/tests/imagegif_nullbyte_injection.php t ext/gd/tests/imagejpeg_nullbyte_injection.phpt ext/ gd/tests/imagepng_nullbyte_injection.phpt
ext/gd/tests/ imagewbmp_nullbyte_injection.phpt ext/gd/tests/imageweb p_nullbyte_injection.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-106773@lists.php.net to get a copy of this message
Commit: b994fd81cb9be6fad5c54f33435d6e80ba0f1154 Author: Christoph M. Becker <cmbecker69@gmx.de> Thu, 13 Jun 2019 17:05:47 +0200 Parents: 890e846d857a2b05e8f5ff8395bb13534d4c59e0 Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=b994fd81cb9be6fad5c54f33435d6e80ba0f1154 Log: Throw TypeError instead of warning in case of invalid path 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. Changed paths: M ext/gd/gd_ctx.c M ext/gd/tests/imagebmp_nullbyte_injection.phpt M ext/gd/tests/imagegif_nullbyte_injection.phpt M ext/gd/tests/imagejpeg_nullbyte_injection.phpt M ext/gd/tests/imagepng_nullbyte_injection.phpt M ext/gd/tests/imagewbmp_nullbyte_injection.phpt M ext/gd/tests/imagewebp_nullbyte_injection.phpt Diff: diff --git a/ext/gd/gd_ctx.c b/ext/gd/gd_ctx.c index d563eb1..dcdf8ad 100644 --- a/ext/gd/gd_ctx.c +++ b/ext/gd/gd_ctx.c @@ -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); diff --git a/ext/gd/tests/imagebmp_nullbyte_injection.phpt b/ext/gd/tests/imagebmp_nullbyte_injection.phpt index 0b6d184..00d0a71 100644 --- a/ext/gd/tests/imagebmp_nullbyte_injection.phpt +++ b/ext/gd/tests/imagebmp_nullbyte_injection.phpt @@ -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 diff --git a/ext/gd/tests/imagegif_nullbyte_injection.phpt b/ext/gd/tests/imagegif_nullbyte_injection.phpt index 5793e90..4518eca 100644 --- a/ext/gd/tests/imagegif_nullbyte_injection.phpt +++ b/ext/gd/tests/imagegif_nullbyte_injection.phpt @@ -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 diff --git a/ext/gd/tests/imagejpeg_nullbyte_injection.phpt b/ext/gd/tests/imagejpeg_nullbyte_injection.phpt index 381421d..1a7f6da 100644 --- a/ext/gd/tests/imagejpeg_nullbyte_injection.phpt +++ b/ext/gd/tests/imagejpeg_nullbyte_injection.phpt @@ -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 diff --git a/ext/gd/tests/imagepng_nullbyte_injection.phpt b/ext/gd/tests/imagepng_nullbyte_injection.phpt index 7731785..86d614a 100644 --- a/ext/gd/tests/imagepng_nullbyte_injection.phpt +++ b/ext/gd/tests/imagepng_nullbyte_injection.phpt @@ -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 diff --git a/ext/gd/tests/imagewbmp_nullbyte_injection.phpt b/ext/gd/tests/imagewbmp_nullbyte_injection.phpt index 6f7557d..cce38a6 100644 --- a/ext/gd/tests/imagewbmp_nullbyte_injection.phpt +++ b/ext/gd/tests/imagewbmp_nullbyte_injection.phpt @@ -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 diff --git a/ext/gd/tests/imagewebp_nullbyte_injection.phpt b/ext/gd/tests/imagewebp_nullbyte_injection.phpt index 68712f2..82e45ac 100644 --- a/ext/gd/tests/imagewebp_nullbyte_injection.phpt +++ b/ext/gd/tests/imagewebp_nullbyte_injection.phpt @@ -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

« previous php.cvs (#106773) next »