mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Merge branch 'PHP-8.4'
This commit is contained in:
20
ext/gd/gd.c
20
ext/gd/gd.c
@@ -3867,6 +3867,26 @@ PHP_FUNCTION(imagecrop)
|
||||
RETURN_THROWS();
|
||||
}
|
||||
|
||||
if ((rect.width > 0 && rect.x > INT_MAX - rect.width)) {
|
||||
zend_argument_value_error(2, "overflow with \"x\" and \"width\" keys");
|
||||
RETURN_THROWS();
|
||||
}
|
||||
|
||||
if ((rect.width < 0 && rect.x < INT_MIN - rect.width)) {
|
||||
zend_argument_value_error(2, "underflow with \"x\" and \"width\" keys");
|
||||
RETURN_THROWS();
|
||||
}
|
||||
|
||||
if ((rect.height > 0 && rect.y > INT_MAX - rect.height)) {
|
||||
zend_argument_value_error(2, "overflow with \"y\" and \"height\" keys");
|
||||
RETURN_THROWS();
|
||||
}
|
||||
|
||||
if ((rect.height < 0 && rect.y < INT_MIN - rect.height)) {
|
||||
zend_argument_value_error(2, "underflow with \"y\" and \"height\" keys");
|
||||
RETURN_THROWS();
|
||||
}
|
||||
|
||||
im_crop = gdImageCrop(im, &rect);
|
||||
|
||||
if (im_crop == NULL) {
|
||||
|
||||
45
ext/gd/tests/imagecrop_overflow.phpt
Normal file
45
ext/gd/tests/imagecrop_overflow.phpt
Normal file
@@ -0,0 +1,45 @@
|
||||
--TEST--
|
||||
imagecrop() overflows when the combo x/width or y/height is over INT_MAX or under INT_MIN.
|
||||
--EXTENSIONS--
|
||||
gd
|
||||
--FILE--
|
||||
<?php
|
||||
$img = imagecreatetruecolor(10, 10);
|
||||
|
||||
$arr = ["x" => 2147483647, "y" => 2147483647, "width" => 10, "height" => 10];
|
||||
|
||||
try {
|
||||
imagecrop($img, $arr);
|
||||
} catch (\ValueError $e) {
|
||||
echo $e->getMessage() . PHP_EOL;
|
||||
}
|
||||
|
||||
$arr = ["x" => -2147483648, "y" => 0, "width" => -10, "height" => 10];
|
||||
|
||||
try {
|
||||
imagecrop($img, $arr);
|
||||
} catch (\ValueError $e) {
|
||||
echo $e->getMessage() . PHP_EOL;
|
||||
}
|
||||
|
||||
$arr = ["x" => 1, "y" => 2147483647, "width" => 10, "height" => 10];
|
||||
|
||||
try {
|
||||
imagecrop($img, $arr);
|
||||
} catch (\ValueError $e) {
|
||||
echo $e->getMessage() . PHP_EOL;
|
||||
}
|
||||
|
||||
$arr = ["x" => 1, "y" => -2147483648, "width" => 10, "height" => -10];
|
||||
|
||||
try {
|
||||
imagecrop($img, $arr);
|
||||
} catch (\ValueError $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
imagecrop(): Argument #2 ($rectangle) overflow with "x" and "width" keys
|
||||
imagecrop(): Argument #2 ($rectangle) underflow with "x" and "width" keys
|
||||
imagecrop(): Argument #2 ($rectangle) overflow with "y" and "height" keys
|
||||
imagecrop(): Argument #2 ($rectangle) underflow with "y" and "height" keys
|
||||
Reference in New Issue
Block a user