]> granicus.if.org Git - php/commitdiff
Warnings to errors in imageaffinematrix*()
authorMark <mrandall@digitellinc.com>
Tue, 3 Sep 2019 23:16:09 +0000 (01:16 +0200)
committerChristoph M. Becker <cmbecker69@gmx.de>
Wed, 4 Sep 2019 13:18:07 +0000 (15:18 +0200)
ext/gd/gd.c
ext/gd/tests/bug67248.phpt

index de704d08a4fd2a1b39e4a82a782747db6e890b44..027933ee64feb359a9400768be0082b98c051150 100644 (file)
@@ -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 = &rect;
        } 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;
                        }
                }
        }
index 5cae5f8c98a2de4233a4b2bc2e94e20fe30177de..58d5d55786c225ded27818c2c2e6468f7083ff10 100644 (file)
@@ -7,21 +7,19 @@ Bug #67248 (imageaffinematrixget missing check of parameters)
 ?>
 --FILE--
 <?php
+require __DIR__ . '/func.inc';
+
 for($i=0;$i<7;$i++) {
-       imageaffinematrixget($i);
+       trycatch_dump(
+        fn() => 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