From: Mark Date: Tue, 3 Sep 2019 23:16:09 +0000 (+0200) Subject: Warnings to errors in imageaffinematrix*() X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4a1f0eb9d3cc1e19f74b6b454db9fbf8addedf40;p=php Warnings to errors in imageaffinematrix*() --- diff --git a/ext/gd/gd.c b/ext/gd/gd.c index de704d08a4..027933ee64 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -3980,8 +3980,8 @@ PHP_FUNCTION(imageaffine) } if ((nelems = zend_hash_num_elements(Z_ARRVAL_P(z_affine))) != 6) { - php_error_docref(NULL, E_WARNING, "Affine array must have six elements"); - RETURN_FALSE; + zend_throw_error(NULL, "Affine array must have six elements"); + return; } for (i = 0; i < nelems; i++) { @@ -3997,8 +3997,8 @@ PHP_FUNCTION(imageaffine) affine[i] = zval_get_double(zval_affine_elem); break; default: - php_error_docref(NULL, E_WARNING, "Invalid type for element %i", i); - RETURN_FALSE; + zend_type_error("Invalid type for element %i", i); + return; } } } @@ -4007,29 +4007,29 @@ PHP_FUNCTION(imageaffine) if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "x", sizeof("x") - 1)) != NULL) { rect.x = zval_get_long(tmp); } else { - php_error_docref(NULL, E_WARNING, "Missing x position"); - RETURN_FALSE; + zend_throw_error(NULL, "Clip array is missing x position"); + return; } if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "y", sizeof("y") - 1)) != NULL) { rect.y = zval_get_long(tmp); } else { - php_error_docref(NULL, E_WARNING, "Missing y position"); - RETURN_FALSE; + zend_throw_error(NULL, "Clip array is missing y position"); + return; } if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "width", sizeof("width") - 1)) != NULL) { rect.width = zval_get_long(tmp); } else { - php_error_docref(NULL, E_WARNING, "Missing width"); - RETURN_FALSE; + zend_throw_error(NULL, "Clip array is missing width"); + return; } if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "height", sizeof("height") - 1)) != NULL) { rect.height = zval_get_long(tmp); } else { - php_error_docref(NULL, E_WARNING, "Missing height"); - RETURN_FALSE; + zend_throw_error(NULL, "Clip array is missing height"); + return; } pRect = ▭ } else { @@ -4071,21 +4071,22 @@ PHP_FUNCTION(imageaffinematrixget) case GD_AFFINE_SCALE: { double x, y; if (!options || Z_TYPE_P(options) != IS_ARRAY) { - php_error_docref(NULL, E_WARNING, "Array expected as options"); - RETURN_FALSE; + zend_type_error("Array expected as options when using translate or scale"); + return; } + if ((tmp = zend_hash_str_find(Z_ARRVAL_P(options), "x", sizeof("x") - 1)) != NULL) { x = zval_get_double(tmp); } else { - php_error_docref(NULL, E_WARNING, "Missing x position"); - RETURN_FALSE; + zend_throw_error(NULL, "Options array is missing x position"); + return; } if ((tmp = zend_hash_str_find(Z_ARRVAL_P(options), "y", sizeof("y") - 1)) != NULL) { y = zval_get_double(tmp); } else { - php_error_docref(NULL, E_WARNING, "Missing y position"); - RETURN_FALSE; + zend_throw_error(NULL, "Options array is missing y position"); + return; } if (type == GD_AFFINE_TRANSLATE) { @@ -4102,8 +4103,8 @@ PHP_FUNCTION(imageaffinematrixget) double angle; if (!options) { - php_error_docref(NULL, E_WARNING, "Number is expected as option"); - RETURN_FALSE; + zend_type_error("Number is expected as option when using rotate or shear"); + return; } angle = zval_get_double(options); @@ -4119,8 +4120,8 @@ PHP_FUNCTION(imageaffinematrixget) } default: - php_error_docref(NULL, E_WARNING, "Invalid type for element " ZEND_LONG_FMT, type); - RETURN_FALSE; + zend_throw_error(NULL, "Invalid type for element " ZEND_LONG_FMT, type); + return; } if (res == GD_FALSE) { @@ -4151,8 +4152,8 @@ PHP_FUNCTION(imageaffinematrixconcat) } if (((nelems = zend_hash_num_elements(Z_ARRVAL_P(z_m1))) != 6) || (nelems = zend_hash_num_elements(Z_ARRVAL_P(z_m2))) != 6) { - php_error_docref(NULL, E_WARNING, "Affine arrays must have six elements"); - RETURN_FALSE; + zend_throw_error(NULL, "Affine arrays must have six elements"); + return; } for (i = 0; i < 6; i++) { @@ -4168,10 +4169,11 @@ PHP_FUNCTION(imageaffinematrixconcat) m1[i] = zval_get_double(tmp); break; default: - php_error_docref(NULL, E_WARNING, "Invalid type for element %i", i); - RETURN_FALSE; + zend_type_error("Matrix 1 contains invalid type for element %i", i); + return; } } + if ((tmp = zend_hash_index_find(Z_ARRVAL_P(z_m2), i)) != NULL) { switch (Z_TYPE_P(tmp)) { case IS_LONG: @@ -4184,8 +4186,8 @@ PHP_FUNCTION(imageaffinematrixconcat) m2[i] = zval_get_double(tmp); break; default: - php_error_docref(NULL, E_WARNING, "Invalid type for element %i", i); - RETURN_FALSE; + zend_type_error("Matrix 2 contains invalid type for element %i", i); + return; } } } diff --git a/ext/gd/tests/bug67248.phpt b/ext/gd/tests/bug67248.phpt index 5cae5f8c98..58d5d55786 100644 --- a/ext/gd/tests/bug67248.phpt +++ b/ext/gd/tests/bug67248.phpt @@ -7,21 +7,19 @@ Bug #67248 (imageaffinematrixget missing check of parameters) ?> --FILE-- imageaffinematrixget($i) + ); } ?> ---EXPECTF-- -Warning: imageaffinematrixget(): Array expected as options in %s on line %d - -Warning: imageaffinematrixget(): Array expected as options in %s on line %d - -Warning: imageaffinematrixget(): Number is expected as option in %s on line %d - -Warning: imageaffinematrixget(): Number is expected as option in %s on line %d - -Warning: imageaffinematrixget(): Number is expected as option in %s on line %d - -Warning: imageaffinematrixget(): Invalid type for element 5 in %s on line %d - -Warning: imageaffinematrixget(): Invalid type for element 6 in %s on line %d +--EXPECT-- +!! [TypeError] Array expected as options when using translate or scale +!! [TypeError] Array expected as options when using translate or scale +!! [TypeError] Number is expected as option when using rotate or shear +!! [TypeError] Number is expected as option when using rotate or shear +!! [TypeError] Number is expected as option when using rotate or shear +!! [Error] Invalid type for element 5 +!! [Error] Invalid type for element 6