Skip to content

Commit 94e65d3

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: Fix GH-20551: imagegammacorrect out of range gamma value.
2 parents 3abdef2 + 4d71d8a commit 94e65d3

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

ext/gd/gd.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2453,11 +2453,21 @@ PHP_FUNCTION(imagegammacorrect)
24532453
RETURN_THROWS();
24542454
}
24552455

2456+
if (!zend_finite(input)) {
2457+
zend_argument_value_error(2, "must be finite");
2458+
RETURN_THROWS();
2459+
}
2460+
24562461
if (output <= 0.0) {
24572462
zend_argument_value_error(3, "must be greater than 0");
24582463
RETURN_THROWS();
24592464
}
24602465

2466+
if (!zend_finite(output)) {
2467+
zend_argument_value_error(3, "must be finite");
2468+
RETURN_THROWS();
2469+
}
2470+
24612471
gamma = input / output;
24622472

24632473
im = php_gd_libgdimageptr_from_zval_p(IM);

ext/gd/tests/gh20551.phpt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
GH-20551: (imagegammacorrect out of range input/output value)
3+
--EXTENSIONS--
4+
gd
5+
--FILE--
6+
<?php
7+
$im = imagecreate(64, 32);
8+
9+
$gammas = [
10+
[NAN, 1.0],
11+
[-NAN, 1.0],
12+
[INF, 1.0],
13+
[-INF, 1.0],
14+
[1.0, NAN],
15+
[1.0, -NAN],
16+
[1.0, INF],
17+
[1.0, -INF],
18+
];
19+
20+
foreach ($gammas as $gamma) {
21+
try {
22+
imagegammacorrect($im, $gamma[0], $gamma[1]);
23+
} catch (\ValueError $e) {
24+
echo $e->getMessage(), PHP_EOL;
25+
}
26+
}
27+
?>
28+
--EXPECT--
29+
imagegammacorrect(): Argument #2 ($input_gamma) must be finite
30+
imagegammacorrect(): Argument #2 ($input_gamma) must be finite
31+
imagegammacorrect(): Argument #2 ($input_gamma) must be finite
32+
imagegammacorrect(): Argument #2 ($input_gamma) must be greater than 0
33+
imagegammacorrect(): Argument #3 ($output_gamma) must be finite
34+
imagegammacorrect(): Argument #3 ($output_gamma) must be finite
35+
imagegammacorrect(): Argument #3 ($output_gamma) must be finite
36+
imagegammacorrect(): Argument #3 ($output_gamma) must be greater than 0

0 commit comments

Comments
 (0)