Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 35 additions & 5 deletions ext/gd/gd.c
Original file line number Diff line number Diff line change
Expand Up @@ -4138,15 +4138,35 @@ PHP_FUNCTION(imageaffinematrixget)
RETURN_THROWS();
}

if ((tmp = zend_hash_str_find(Z_ARRVAL_P(options), "x", sizeof("x") - 1)) != NULL) {
x = zval_get_double(tmp);
if ((tmp = zend_hash_str_find_deref(Z_ARRVAL_P(options), "x", sizeof("x") - 1)) != NULL) {
switch (Z_TYPE_P(tmp)) {
case IS_LONG:
case IS_DOUBLE:
case IS_STRING:
case IS_OBJECT:
x = zval_get_double(tmp);
break;
default:
zend_argument_type_error(2, "must be a float for the \"x\" key, %s given", zend_zval_value_name(tmp));
RETURN_THROWS();
}
} else {
zend_argument_value_error(2, "must have an \"x\" key");
RETURN_THROWS();
}

if ((tmp = zend_hash_str_find(Z_ARRVAL_P(options), "y", sizeof("y") - 1)) != NULL) {
y = zval_get_double(tmp);
if ((tmp = zend_hash_str_find_deref(Z_ARRVAL_P(options), "y", sizeof("y") - 1)) != NULL) {
switch (Z_TYPE_P(tmp)) {
case IS_LONG:
case IS_DOUBLE:
case IS_STRING:
case IS_OBJECT:
y = zval_get_double(tmp);
break;
default:
zend_argument_type_error(2, "must be a float for the \"y\" key, %s given", zend_zval_value_name(tmp));
RETURN_THROWS();
}
} else {
zend_argument_value_error(2, "must have a \"y\" key");
RETURN_THROWS();
Expand All @@ -4165,7 +4185,17 @@ PHP_FUNCTION(imageaffinematrixget)
case GD_AFFINE_SHEAR_VERTICAL: {
double angle;

angle = zval_get_double(options);
switch (Z_TYPE_P(options)) {
case IS_LONG:
case IS_DOUBLE:
case IS_STRING:
case IS_OBJECT:
angle = zval_get_double(options);
break;
default:
zend_argument_type_error(2, "must be of type float, %s given", zend_zval_value_name(options));
RETURN_THROWS();
}

if (type == GD_AFFINE_SHEAR_HORIZONTAL) {
res = gdAffineShearHorizontal(affine, angle);
Expand Down
46 changes: 46 additions & 0 deletions ext/gd/tests/imageaffinematrixget_errors.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
--TEST--
imageaffinematrixget
--EXTENSIONS--
gd
--FILE--
<?php
class A{}
$a = 10;
try {
imageaffinematrixget(IMG_AFFINE_ROTATE, new A());
} catch (\TypeError $e) {
echo $e->getMessage(), PHP_EOL;
}
try {
imageaffinematrixget(IMG_AFFINE_SCALE, ["x" => new A(), "y" => 1]);
} catch (\TypeError $e) {
echo $e->getMessage(), PHP_EOL;
}
try {
imageaffinematrixget(IMG_AFFINE_SCALE, ["x" => 10, "y" => new A()]);
} catch (\TypeError $e) {
echo $e->getMessage(), PHP_EOL;
}
var_dump(imageaffinematrixget(IMG_AFFINE_SCALE, ["x" => &$a, "y" => &$a]));
?>
--EXPECTF--

Warning: Object of class A could not be converted to float in %s on line %d

Warning: Object of class A could not be converted to float in %s on line %d

Warning: Object of class A could not be converted to float in %s on line %d
array(6) {
[0]=>
float(10)
[1]=>
float(0)
[2]=>
float(0)
[3]=>
float(10)
[4]=>
float(0)
[5]=>
float(0)
}
Loading