From: Christoph M. Becker Date: Thu, 13 Jun 2019 15:05:47 +0000 (+0200) Subject: Throw TypeError instead of warning in case of invalid path X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b994fd81cb9be6fad5c54f33435d6e80ba0f1154;p=php 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. --- diff --git a/ext/gd/gd_ctx.c b/ext/gd/gd_ctx.c index d563eb1384..dcdf8ad803 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 0b6d1843d3..00d0a7168c 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-- 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 5793e90151..4518ecad27 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-- 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 381421d144..1a7f6da03c 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-- 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 773178541b..86d614ab60 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-- 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 6f7557d307..cce38a63df 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-- 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 68712f282f..82e45aca02 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-- 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