Skip to content

Commit 44cbdb1

Browse files
thg2knielsdos
authored andcommitted
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 Closes GH-14477.
1 parent a3b148e commit 44cbdb1

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ PHP NEWS
6262
. Removed the deprecated inet_ntoa call support. (David Carlier)
6363
. Fixed bug #63937 (Upload speed 10 times slower with PHP). (nielsdos)
6464

65+
- GD:
66+
. Fix parameter numbers and missing alpha check for imagecolorset().
67+
(Giovanni Giacobbi)
68+
6569
- Gettext:
6670
. bind_textdomain_codeset, textdomain and d(*)gettext functions
6771
now throw an exception on empty domain. (David Carlier)

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

0 commit comments

Comments
 (0)