Skip to content

Commit 18102ec

Browse files
committed
Merge branch 'PHP-8.4'
2 parents 6ff9ca1 + 3a5c87f commit 18102ec

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

ext/gd/gd.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3867,6 +3867,26 @@ PHP_FUNCTION(imagecrop)
38673867
RETURN_THROWS();
38683868
}
38693869

3870+
if ((rect.width > 0 && rect.x > INT_MAX - rect.width)) {
3871+
zend_argument_value_error(2, "overflow with \"x\" and \"width\" keys");
3872+
RETURN_THROWS();
3873+
}
3874+
3875+
if ((rect.width < 0 && rect.x < INT_MIN - rect.width)) {
3876+
zend_argument_value_error(2, "underflow with \"x\" and \"width\" keys");
3877+
RETURN_THROWS();
3878+
}
3879+
3880+
if ((rect.height > 0 && rect.y > INT_MAX - rect.height)) {
3881+
zend_argument_value_error(2, "overflow with \"y\" and \"height\" keys");
3882+
RETURN_THROWS();
3883+
}
3884+
3885+
if ((rect.height < 0 && rect.y < INT_MIN - rect.height)) {
3886+
zend_argument_value_error(2, "underflow with \"y\" and \"height\" keys");
3887+
RETURN_THROWS();
3888+
}
3889+
38703890
im_crop = gdImageCrop(im, &rect);
38713891

38723892
if (im_crop == NULL) {

ext/gd/tests/imagecrop_overflow.phpt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
--TEST--
2+
imagecrop() overflows when the combo x/width or y/height is over INT_MAX or under INT_MIN.
3+
--EXTENSIONS--
4+
gd
5+
--FILE--
6+
<?php
7+
$img = imagecreatetruecolor(10, 10);
8+
9+
$arr = ["x" => 2147483647, "y" => 2147483647, "width" => 10, "height" => 10];
10+
11+
try {
12+
imagecrop($img, $arr);
13+
} catch (\ValueError $e) {
14+
echo $e->getMessage() . PHP_EOL;
15+
}
16+
17+
$arr = ["x" => -2147483648, "y" => 0, "width" => -10, "height" => 10];
18+
19+
try {
20+
imagecrop($img, $arr);
21+
} catch (\ValueError $e) {
22+
echo $e->getMessage() . PHP_EOL;
23+
}
24+
25+
$arr = ["x" => 1, "y" => 2147483647, "width" => 10, "height" => 10];
26+
27+
try {
28+
imagecrop($img, $arr);
29+
} catch (\ValueError $e) {
30+
echo $e->getMessage() . PHP_EOL;
31+
}
32+
33+
$arr = ["x" => 1, "y" => -2147483648, "width" => 10, "height" => -10];
34+
35+
try {
36+
imagecrop($img, $arr);
37+
} catch (\ValueError $e) {
38+
echo $e->getMessage();
39+
}
40+
?>
41+
--EXPECT--
42+
imagecrop(): Argument #2 ($rectangle) overflow with "x" and "width" keys
43+
imagecrop(): Argument #2 ($rectangle) underflow with "x" and "width" keys
44+
imagecrop(): Argument #2 ($rectangle) overflow with "y" and "height" keys
45+
imagecrop(): Argument #2 ($rectangle) underflow with "y" and "height" keys

0 commit comments

Comments
 (0)