Skip to content

Commit 7f35ba6

Browse files
committed
Fix parameter numbers and missing alpha check for imagecolorset()
The check for the alpha parameter existed in PHP 7.4 but was lost in PHP 8.0. Fixes: 5076507
1 parent bda372f commit 7f35ba6

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

ext/gd/gd.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2212,9 +2212,10 @@ PHP_FUNCTION(imagecolorset)
22122212

22132213
im = php_gd_libgdimageptr_from_zval_p(IM);
22142214

2215-
CHECK_RGBA_RANGE(red, Red, 2);
2216-
CHECK_RGBA_RANGE(green, Green, 3);
2217-
CHECK_RGBA_RANGE(blue, Blue, 4);
2215+
CHECK_RGBA_RANGE(red, Red, 3);
2216+
CHECK_RGBA_RANGE(green, Green, 4);
2217+
CHECK_RGBA_RANGE(blue, Blue, 5);
2218+
CHECK_RGBA_RANGE(alpha, Alpha, 6);
22182219

22192220
col = color;
22202221

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
imagecolorset() parameters errors
3+
--EXTENSIONS--
4+
gd
5+
--FILE--
6+
<?php
7+
$im = imagecreate(5, 5);
8+
9+
$c = imagecolorallocatealpha($im, 3, 4, 5, 6);
10+
11+
trycatch_dump(
12+
fn() => imagecolorset($im, $c, -3, 4, 5, 6),
13+
fn() => imagecolorset($im, $c, 3, -4, 5, 6),
14+
fn() => imagecolorset($im, $c, 3, 4, -5, 6),
15+
fn() => imagecolorset($im, $c, 3, 4, 5, -6),
16+
);
17+
18+
?>
19+
--EXPECT--
20+
!! [ValueError] imagecolorset(): Argument #3 ($red) must be between 0 and 255 (inclusive)
21+
!! [ValueError] imagecolorset(): Argument #4 ($green) must be between 0 and 255 (inclusive)
22+
!! [ValueError] imagecolorset(): Argument #5 ($blue) must be between 0 and 255 (inclusive)
23+
!! [ValueError] imagecolorset(): Argument #6 ($alpha) must be between 0 and 127 (inclusive)

0 commit comments

Comments
 (0)