Skip to content

Commit 30cb199

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Fix GH-20551: imagegammacorrect out of range gamma value.
2 parents 74c4510 + f88d247 commit 30cb199

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
@@ -26,6 +26,10 @@ PHP NEWS
2626
. Fixed bug GH-20483 (ASAN stack overflow with fiber.stack_size INI
2727
small value). (David Carlier)
2828

29+
- GD:
30+
. Fixed bug GH-20511 (imagegammacorrect out of range input/output values).
31+
(David Carlier)
32+
2933
- LibXML:
3034
. Fix some deprecations on newer libxml versions regarding input
3135
buffer/parser handling. (ndossche)

ext/gd/gd.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2498,11 +2498,21 @@ PHP_FUNCTION(imagegammacorrect)
24982498
RETURN_THROWS();
24992499
}
25002500

2501+
if (!zend_finite(input)) {
2502+
zend_argument_value_error(2, "must be finite");
2503+
RETURN_THROWS();
2504+
}
2505+
25012506
if (output <= 0.0) {
25022507
zend_argument_value_error(3, "must be greater than 0");
25032508
RETURN_THROWS();
25042509
}
25052510

2511+
if (!zend_finite(output)) {
2512+
zend_argument_value_error(3, "must be finite");
2513+
RETURN_THROWS();
2514+
}
2515+
25062516
gamma = input / output;
25072517

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