Skip to content

Commit f273204

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Extend color component range checks
2 parents 228bae7 + 092571c commit f273204

File tree

3 files changed

+66
-33
lines changed

3 files changed

+66
-33
lines changed

ext/gd/gd.c

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,8 +1101,8 @@ PHP_FUNCTION(imagelayereffect)
11011101
}
11021102
/* }}} */
11031103

1104-
#define CHECK_RGB_RANGE(component, name) \
1105-
if (component < 0 || component > 255) { \
1104+
#define CHECK_RGBA_RANGE(component, name) \
1105+
if (component < 0 || component > gd##name##Max) { \
11061106
php_error_docref(NULL, E_WARNING, #name " component is out of range"); \
11071107
RETURN_FALSE; \
11081108
}
@@ -1124,9 +1124,10 @@ PHP_FUNCTION(imagecolorallocatealpha)
11241124
RETURN_FALSE;
11251125
}
11261126

1127-
CHECK_RGB_RANGE(red, Red);
1128-
CHECK_RGB_RANGE(green, Green);
1129-
CHECK_RGB_RANGE(blue, Blue);
1127+
CHECK_RGBA_RANGE(red, Red);
1128+
CHECK_RGBA_RANGE(green, Green);
1129+
CHECK_RGBA_RANGE(blue, Blue);
1130+
CHECK_RGBA_RANGE(alpha, Alpha);
11301131

11311132
ct = gdImageColorAllocateAlpha(im, red, green, blue, alpha);
11321133
if (ct < 0) {
@@ -1152,6 +1153,11 @@ PHP_FUNCTION(imagecolorresolvealpha)
11521153
RETURN_FALSE;
11531154
}
11541155

1156+
CHECK_RGBA_RANGE(red, Red);
1157+
CHECK_RGBA_RANGE(green, Green);
1158+
CHECK_RGBA_RANGE(blue, Blue);
1159+
CHECK_RGBA_RANGE(alpha, Alpha);
1160+
11551161
RETURN_LONG(gdImageColorResolveAlpha(im, red, green, blue, alpha));
11561162
}
11571163
/* }}} */
@@ -1172,6 +1178,11 @@ PHP_FUNCTION(imagecolorclosestalpha)
11721178
RETURN_FALSE;
11731179
}
11741180

1181+
CHECK_RGBA_RANGE(red, Red);
1182+
CHECK_RGBA_RANGE(green, Green);
1183+
CHECK_RGBA_RANGE(blue, Blue);
1184+
CHECK_RGBA_RANGE(alpha, Alpha);
1185+
11751186
RETURN_LONG(gdImageColorClosestAlpha(im, red, green, blue, alpha));
11761187
}
11771188
/* }}} */
@@ -1192,6 +1203,11 @@ PHP_FUNCTION(imagecolorexactalpha)
11921203
RETURN_FALSE;
11931204
}
11941205

1206+
CHECK_RGBA_RANGE(red, Red);
1207+
CHECK_RGBA_RANGE(green, Green);
1208+
CHECK_RGBA_RANGE(blue, Blue);
1209+
CHECK_RGBA_RANGE(alpha, Alpha);
1210+
11951211
RETURN_LONG(gdImageColorExactAlpha(im, red, green, blue, alpha));
11961212
}
11971213
/* }}} */
@@ -2128,9 +2144,9 @@ PHP_FUNCTION(imagecolorallocate)
21282144
RETURN_FALSE;
21292145
}
21302146

2131-
CHECK_RGB_RANGE(red, Red);
2132-
CHECK_RGB_RANGE(green, Green);
2133-
CHECK_RGB_RANGE(blue, Blue);
2147+
CHECK_RGBA_RANGE(red, Red);
2148+
CHECK_RGBA_RANGE(green, Green);
2149+
CHECK_RGBA_RANGE(blue, Blue);
21342150

21352151
ct = gdImageColorAllocate(im, red, green, blue);
21362152
if (ct < 0) {
@@ -2215,6 +2231,10 @@ PHP_FUNCTION(imagecolorclosest)
22152231
RETURN_FALSE;
22162232
}
22172233

2234+
CHECK_RGBA_RANGE(red, Red);
2235+
CHECK_RGBA_RANGE(green, Green);
2236+
CHECK_RGBA_RANGE(blue, Blue);
2237+
22182238
RETURN_LONG(gdImageColorClosest(im, red, green, blue));
22192239
}
22202240
/* }}} */
@@ -2235,6 +2255,10 @@ PHP_FUNCTION(imagecolorclosesthwb)
22352255
RETURN_FALSE;
22362256
}
22372257

2258+
CHECK_RGBA_RANGE(red, Red);
2259+
CHECK_RGBA_RANGE(green, Green);
2260+
CHECK_RGBA_RANGE(blue, Blue);
2261+
22382262
RETURN_LONG(gdImageColorClosestHWB(im, red, green, blue));
22392263
}
22402264
/* }}} */
@@ -2289,6 +2313,10 @@ PHP_FUNCTION(imagecolorresolve)
22892313
RETURN_FALSE;
22902314
}
22912315

2316+
CHECK_RGBA_RANGE(red, Red);
2317+
CHECK_RGBA_RANGE(green, Green);
2318+
CHECK_RGBA_RANGE(blue, Blue);
2319+
22922320
RETURN_LONG(gdImageColorResolve(im, red, green, blue));
22932321
}
22942322
/* }}} */
@@ -2309,6 +2337,10 @@ PHP_FUNCTION(imagecolorexact)
23092337
RETURN_FALSE;
23102338
}
23112339

2340+
CHECK_RGBA_RANGE(red, Red);
2341+
CHECK_RGBA_RANGE(green, Green);
2342+
CHECK_RGBA_RANGE(blue, Blue);
2343+
23122344
RETURN_LONG(gdImageColorExact(im, red, green, blue));
23132345
}
23142346
/* }}} */
@@ -2330,6 +2362,11 @@ PHP_FUNCTION(imagecolorset)
23302362
RETURN_FALSE;
23312363
}
23322364

2365+
CHECK_RGBA_RANGE(red, Red);
2366+
CHECK_RGBA_RANGE(green, Green);
2367+
CHECK_RGBA_RANGE(blue, Blue);
2368+
CHECK_RGBA_RANGE(alpha, Alpha);
2369+
23332370
col = color;
23342371

23352372
if (col >= 0 && col < gdImageColorsTotal(im)) {

ext/gd/gd.stub.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,14 @@ function imagelayereffect($im, int $effect): bool {}
3333
/** @return int|false */
3434
function imagecolorallocatealpha($im, int $red, int $green, int $blue, int $alpha) {}
3535

36-
function imagecolorresolvealpha($im, int $red, int $green, int $blue, int $alpha): int {}
36+
/** @return int|false */
37+
function imagecolorresolvealpha($im, int $red, int $green, int $blue, int $alpha) {}
3738

38-
function imagecolorclosestalpha($im, int $red, int $green, int $blue, int $alpha): int {}
39+
/** @return int|false */
40+
function imagecolorclosestalpha($im, int $red, int $green, int $blue, int $alpha) {}
3941

40-
function imagecolorexactalpha($im, int $red, int $green, int $blue, int $alpha): int {}
42+
/** @return int|false */
43+
function imagecolorexactalpha($im, int $red, int $green, int $blue, int $alpha) {}
4144

4245
function imagecopyresampled($dst_im, $src_im, int $dst_x, int $dst_y, int $src_x, int $src_y, int $dst_w, int $dst_h, int $src_w, int $src_h): bool {}
4346

@@ -150,15 +153,19 @@ function imagepalettecopy($dst, $src): void {}
150153
/** @return int|false */
151154
function imagecolorat($im, int $x, int $y) {}
152155

153-
function imagecolorclosest($im, int $red, int $green, int $blue): int {}
156+
/** @return int|false */
157+
function imagecolorclosest($im, int $red, int $green, int $blue) {}
154158

155-
function imagecolorclosesthwb($im, int $red, int $green, int $blue): int {}
159+
/** @return int|false */
160+
function imagecolorclosesthwb($im, int $red, int $green, int $blue) {}
156161

157162
function imagecolordeallocate($im, int $index): bool {}
158163

159-
function imagecolorresolve($im, int $red, int $green, int $blue): int {}
164+
/** @return int|false */
165+
function imagecolorresolve($im, int $red, int $green, int $blue) {}
160166

161-
function imagecolorexact($im, int $red, int $green, int $blue): int {}
167+
/** @return int|false */
168+
function imagecolorexact($im, int $red, int $green, int $blue) {}
162169

163170
/** @return ?false */
164171
function imagecolorset($im, int $color, int $red, int $green, int $blue, int $alpha = 0) {}

ext/gd/gd_arginfo.h

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,11 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_imagecolorallocatealpha, 0, 0, 5)
8383
ZEND_ARG_TYPE_INFO(0, alpha, IS_LONG, 0)
8484
ZEND_END_ARG_INFO()
8585

86-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagecolorresolvealpha, 0, 5, IS_LONG, 0)
87-
ZEND_ARG_INFO(0, im)
88-
ZEND_ARG_TYPE_INFO(0, red, IS_LONG, 0)
89-
ZEND_ARG_TYPE_INFO(0, green, IS_LONG, 0)
90-
ZEND_ARG_TYPE_INFO(0, blue, IS_LONG, 0)
91-
ZEND_ARG_TYPE_INFO(0, alpha, IS_LONG, 0)
92-
ZEND_END_ARG_INFO()
86+
#define arginfo_imagecolorresolvealpha arginfo_imagecolorallocatealpha
9387

94-
#define arginfo_imagecolorclosestalpha arginfo_imagecolorresolvealpha
88+
#define arginfo_imagecolorclosestalpha arginfo_imagecolorallocatealpha
9589

96-
#define arginfo_imagecolorexactalpha arginfo_imagecolorresolvealpha
90+
#define arginfo_imagecolorexactalpha arginfo_imagecolorallocatealpha
9791

9892
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagecopyresampled, 0, 10, _IS_BOOL, 0)
9993
ZEND_ARG_INFO(0, dst_im)
@@ -279,23 +273,18 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_imagecolorat, 0, 0, 3)
279273
ZEND_ARG_TYPE_INFO(0, y, IS_LONG, 0)
280274
ZEND_END_ARG_INFO()
281275

282-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagecolorclosest, 0, 4, IS_LONG, 0)
283-
ZEND_ARG_INFO(0, im)
284-
ZEND_ARG_TYPE_INFO(0, red, IS_LONG, 0)
285-
ZEND_ARG_TYPE_INFO(0, green, IS_LONG, 0)
286-
ZEND_ARG_TYPE_INFO(0, blue, IS_LONG, 0)
287-
ZEND_END_ARG_INFO()
276+
#define arginfo_imagecolorclosest arginfo_imagecolorallocate
288277

289-
#define arginfo_imagecolorclosesthwb arginfo_imagecolorclosest
278+
#define arginfo_imagecolorclosesthwb arginfo_imagecolorallocate
290279

291280
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagecolordeallocate, 0, 2, _IS_BOOL, 0)
292281
ZEND_ARG_INFO(0, im)
293282
ZEND_ARG_TYPE_INFO(0, index, IS_LONG, 0)
294283
ZEND_END_ARG_INFO()
295284

296-
#define arginfo_imagecolorresolve arginfo_imagecolorclosest
285+
#define arginfo_imagecolorresolve arginfo_imagecolorallocate
297286

298-
#define arginfo_imagecolorexact arginfo_imagecolorclosest
287+
#define arginfo_imagecolorexact arginfo_imagecolorallocate
299288

300289
ZEND_BEGIN_ARG_INFO_EX(arginfo_imagecolorset, 0, 0, 5)
301290
ZEND_ARG_INFO(0, im)

0 commit comments

Comments
 (0)