Skip to content

Commit 4a1f0eb

Browse files
marandallcmb69
authored andcommitted
Warnings to errors in imageaffinematrix*()
1 parent 06a3dd5 commit 4a1f0eb

File tree

2 files changed

+43
-43
lines changed

2 files changed

+43
-43
lines changed

ext/gd/gd.c

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3980,8 +3980,8 @@ PHP_FUNCTION(imageaffine)
39803980
}
39813981

39823982
if ((nelems = zend_hash_num_elements(Z_ARRVAL_P(z_affine))) != 6) {
3983-
php_error_docref(NULL, E_WARNING, "Affine array must have six elements");
3984-
RETURN_FALSE;
3983+
zend_throw_error(NULL, "Affine array must have six elements");
3984+
return;
39853985
}
39863986

39873987
for (i = 0; i < nelems; i++) {
@@ -3997,8 +3997,8 @@ PHP_FUNCTION(imageaffine)
39973997
affine[i] = zval_get_double(zval_affine_elem);
39983998
break;
39993999
default:
4000-
php_error_docref(NULL, E_WARNING, "Invalid type for element %i", i);
4001-
RETURN_FALSE;
4000+
zend_type_error("Invalid type for element %i", i);
4001+
return;
40024002
}
40034003
}
40044004
}
@@ -4007,29 +4007,29 @@ PHP_FUNCTION(imageaffine)
40074007
if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "x", sizeof("x") - 1)) != NULL) {
40084008
rect.x = zval_get_long(tmp);
40094009
} else {
4010-
php_error_docref(NULL, E_WARNING, "Missing x position");
4011-
RETURN_FALSE;
4010+
zend_throw_error(NULL, "Clip array is missing x position");
4011+
return;
40124012
}
40134013

40144014
if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "y", sizeof("y") - 1)) != NULL) {
40154015
rect.y = zval_get_long(tmp);
40164016
} else {
4017-
php_error_docref(NULL, E_WARNING, "Missing y position");
4018-
RETURN_FALSE;
4017+
zend_throw_error(NULL, "Clip array is missing y position");
4018+
return;
40194019
}
40204020

40214021
if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "width", sizeof("width") - 1)) != NULL) {
40224022
rect.width = zval_get_long(tmp);
40234023
} else {
4024-
php_error_docref(NULL, E_WARNING, "Missing width");
4025-
RETURN_FALSE;
4024+
zend_throw_error(NULL, "Clip array is missing width");
4025+
return;
40264026
}
40274027

40284028
if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "height", sizeof("height") - 1)) != NULL) {
40294029
rect.height = zval_get_long(tmp);
40304030
} else {
4031-
php_error_docref(NULL, E_WARNING, "Missing height");
4032-
RETURN_FALSE;
4031+
zend_throw_error(NULL, "Clip array is missing height");
4032+
return;
40334033
}
40344034
pRect = &rect;
40354035
} else {
@@ -4071,21 +4071,22 @@ PHP_FUNCTION(imageaffinematrixget)
40714071
case GD_AFFINE_SCALE: {
40724072
double x, y;
40734073
if (!options || Z_TYPE_P(options) != IS_ARRAY) {
4074-
php_error_docref(NULL, E_WARNING, "Array expected as options");
4075-
RETURN_FALSE;
4074+
zend_type_error("Array expected as options when using translate or scale");
4075+
return;
40764076
}
4077+
40774078
if ((tmp = zend_hash_str_find(Z_ARRVAL_P(options), "x", sizeof("x") - 1)) != NULL) {
40784079
x = zval_get_double(tmp);
40794080
} else {
4080-
php_error_docref(NULL, E_WARNING, "Missing x position");
4081-
RETURN_FALSE;
4081+
zend_throw_error(NULL, "Options array is missing x position");
4082+
return;
40824083
}
40834084

40844085
if ((tmp = zend_hash_str_find(Z_ARRVAL_P(options), "y", sizeof("y") - 1)) != NULL) {
40854086
y = zval_get_double(tmp);
40864087
} else {
4087-
php_error_docref(NULL, E_WARNING, "Missing y position");
4088-
RETURN_FALSE;
4088+
zend_throw_error(NULL, "Options array is missing y position");
4089+
return;
40894090
}
40904091

40914092
if (type == GD_AFFINE_TRANSLATE) {
@@ -4102,8 +4103,8 @@ PHP_FUNCTION(imageaffinematrixget)
41024103
double angle;
41034104

41044105
if (!options) {
4105-
php_error_docref(NULL, E_WARNING, "Number is expected as option");
4106-
RETURN_FALSE;
4106+
zend_type_error("Number is expected as option when using rotate or shear");
4107+
return;
41074108
}
41084109

41094110
angle = zval_get_double(options);
@@ -4119,8 +4120,8 @@ PHP_FUNCTION(imageaffinematrixget)
41194120
}
41204121

41214122
default:
4122-
php_error_docref(NULL, E_WARNING, "Invalid type for element " ZEND_LONG_FMT, type);
4123-
RETURN_FALSE;
4123+
zend_throw_error(NULL, "Invalid type for element " ZEND_LONG_FMT, type);
4124+
return;
41244125
}
41254126

41264127
if (res == GD_FALSE) {
@@ -4151,8 +4152,8 @@ PHP_FUNCTION(imageaffinematrixconcat)
41514152
}
41524153

41534154
if (((nelems = zend_hash_num_elements(Z_ARRVAL_P(z_m1))) != 6) || (nelems = zend_hash_num_elements(Z_ARRVAL_P(z_m2))) != 6) {
4154-
php_error_docref(NULL, E_WARNING, "Affine arrays must have six elements");
4155-
RETURN_FALSE;
4155+
zend_throw_error(NULL, "Affine arrays must have six elements");
4156+
return;
41564157
}
41574158

41584159
for (i = 0; i < 6; i++) {
@@ -4168,10 +4169,11 @@ PHP_FUNCTION(imageaffinematrixconcat)
41684169
m1[i] = zval_get_double(tmp);
41694170
break;
41704171
default:
4171-
php_error_docref(NULL, E_WARNING, "Invalid type for element %i", i);
4172-
RETURN_FALSE;
4172+
zend_type_error("Matrix 1 contains invalid type for element %i", i);
4173+
return;
41734174
}
41744175
}
4176+
41754177
if ((tmp = zend_hash_index_find(Z_ARRVAL_P(z_m2), i)) != NULL) {
41764178
switch (Z_TYPE_P(tmp)) {
41774179
case IS_LONG:
@@ -4184,8 +4186,8 @@ PHP_FUNCTION(imageaffinematrixconcat)
41844186
m2[i] = zval_get_double(tmp);
41854187
break;
41864188
default:
4187-
php_error_docref(NULL, E_WARNING, "Invalid type for element %i", i);
4188-
RETURN_FALSE;
4189+
zend_type_error("Matrix 2 contains invalid type for element %i", i);
4190+
return;
41894191
}
41904192
}
41914193
}

ext/gd/tests/bug67248.phpt

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,19 @@ Bug #67248 (imageaffinematrixget missing check of parameters)
77
?>
88
--FILE--
99
<?php
10+
require __DIR__ . '/func.inc';
11+
1012
for($i=0;$i<7;$i++) {
11-
imageaffinematrixget($i);
13+
trycatch_dump(
14+
fn() => imageaffinematrixget($i)
15+
);
1216
}
1317
?>
14-
--EXPECTF--
15-
Warning: imageaffinematrixget(): Array expected as options in %s on line %d
16-
17-
Warning: imageaffinematrixget(): Array expected as options in %s on line %d
18-
19-
Warning: imageaffinematrixget(): Number is expected as option in %s on line %d
20-
21-
Warning: imageaffinematrixget(): Number is expected as option in %s on line %d
22-
23-
Warning: imageaffinematrixget(): Number is expected as option in %s on line %d
24-
25-
Warning: imageaffinematrixget(): Invalid type for element 5 in %s on line %d
26-
27-
Warning: imageaffinematrixget(): Invalid type for element 6 in %s on line %d
18+
--EXPECT--
19+
!! [TypeError] Array expected as options when using translate or scale
20+
!! [TypeError] Array expected as options when using translate or scale
21+
!! [TypeError] Number is expected as option when using rotate or shear
22+
!! [TypeError] Number is expected as option when using rotate or shear
23+
!! [TypeError] Number is expected as option when using rotate or shear
24+
!! [Error] Invalid type for element 5
25+
!! [Error] Invalid type for element 6

0 commit comments

Comments
 (0)