Skip to content

Commit f88d247

Browse files
committed
Fix GH-20551: imagegammacorrect out of range gamma value.
close GH-20552
1 parent 769f319 commit f88d247

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ PHP NEWS
2222
. Fixed bug GH-20483 (ASAN stack overflow with fiber.stack_size INI
2323
small value). (David Carlier)
2424

25+
- GD:
26+
. Fixed bug GH-20511 (imagegammacorrect out of range input/output values).
27+
(David Carlier)
28+
2529
- LibXML:
2630
. Fix some deprecations on newer libxml versions regarding input
2731
buffer/parser handling. (ndossche)

ext/gd/gd.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2286,11 +2286,21 @@ PHP_FUNCTION(imagegammacorrect)
22862286
RETURN_THROWS();
22872287
}
22882288

2289+
if (!zend_finite(input)) {
2290+
zend_argument_value_error(2, "must be finite");
2291+
RETURN_THROWS();
2292+
}
2293+
22892294
if (output <= 0.0) {
22902295
zend_argument_value_error(3, "must be greater than 0");
22912296
RETURN_THROWS();
22922297
}
22932298

2299+
if (!zend_finite(output)) {
2300+
zend_argument_value_error(3, "must be finite");
2301+
RETURN_THROWS();
2302+
}
2303+
22942304
gamma = input / output;
22952305

22962306
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)