Skip to content

Commit 2a070dc

Browse files
committed
add test, fix exception kind
1 parent f341646 commit 2a070dc

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

ext/gd/gd.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3689,21 +3689,21 @@ PHP_FUNCTION(imageaffine)
36893689
case IS_LONG:
36903690
affine[i] = Z_LVAL_P(zval_affine_elem);
36913691
if (ZEND_LONG_EXCEEDS_INT(affine[i])) {
3692-
zend_argument_type_error(2, "element %i must be between %d and %d", i, INT_MIN, INT_MAX);
3692+
zend_argument_value_error(2, "element %i must be between %d and %d", i, INT_MIN, INT_MAX);
36933693
RETURN_THROWS();
36943694
}
36953695
break;
36963696
case IS_DOUBLE:
36973697
affine[i] = Z_DVAL_P(zval_affine_elem);
36983698
if (ZEND_LONG_EXCEEDS_INT(affine[i])) {
3699-
zend_argument_type_error(2, "element %i must be between %d and %d", i, INT_MIN, INT_MAX);
3699+
zend_argument_value_error(2, "element %i must be between %d and %d", i, INT_MIN, INT_MAX);
37003700
RETURN_THROWS();
37013701
}
37023702
break;
37033703
case IS_STRING:
37043704
affine[i] = zval_get_double(zval_affine_elem);
37053705
if (ZEND_LONG_EXCEEDS_INT(affine[i])) {
3706-
zend_argument_type_error(2, "element %i must be between %d and %d", i, INT_MIN, INT_MAX);
3706+
zend_argument_value_error(2, "element %i must be between %d and %d", i, INT_MIN, INT_MAX);
37073707
RETURN_THROWS();
37083708
}
37093709
break;

ext/gd/tests/gh16322.phpt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
GH-16322 (imageaffine overflow/underflow on affine matrix)
3+
--EXTENSIONS--
4+
gd
5+
--INI--
6+
memory_limit=-1
7+
--SKIPIF--
8+
<?php if (PHP_INT_SIZE != 8) die('skip this test is for 64bit platforms only'); ?>
9+
--FILE--
10+
<?php
11+
$matrix = [PHP_INT_MAX, 1, 1, 1, 1, 1];
12+
$src = imagecreatetruecolor(8, 8);
13+
14+
try {
15+
imageaffine($src, $matrix);
16+
} catch (\ValueError $e) {
17+
echo $e->getMessage() . PHP_EOL;
18+
}
19+
$matrix[0] = 1;
20+
$matrix[3] = PHP_INT_MIN;
21+
try {
22+
imageaffine($src, $matrix);
23+
} catch (\ValueError $e) {
24+
echo $e->getMessage();
25+
}
26+
?>
27+
--EXPECTF--
28+
imageaffine(): Argument #2 ($affine) element 0 must be between %s and %d
29+
imageaffine(): Argument #2 ($affine) element 3 must be between %s and %d

0 commit comments

Comments
 (0)