Skip to content

Commit dddd050

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: Fix GH-20602: imagescale() overflow with large height values.
2 parents 5ae1261 + 848269d commit dddd050

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

ext/gd/gd.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3931,9 +3931,17 @@ PHP_FUNCTION(imagescale)
39313931
src_y = gdImageSY(im);
39323932

39333933
if (src_x && tmp_h < 0) {
3934+
if (tmp_w > (ZEND_LONG_MAX / src_y)) {
3935+
zend_argument_value_error(2, "must be less than or equal to " ZEND_LONG_FMT, (zend_long)(ZEND_LONG_MAX / src_y));
3936+
RETURN_THROWS();
3937+
}
39343938
tmp_h = tmp_w * src_y / src_x;
39353939
}
39363940
if (src_y && tmp_w < 0) {
3941+
if (tmp_h > (ZEND_LONG_MAX / src_x)) {
3942+
zend_argument_value_error(3, "must be less than or equal to " ZEND_LONG_FMT, (zend_long)(ZEND_LONG_MAX / src_x));
3943+
RETURN_THROWS();
3944+
}
39373945
tmp_w = tmp_h * src_x / src_y;
39383946
}
39393947
}

ext/gd/tests/gh20602.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
GH-20551: (imagegammacorrect out of range input/output value)
3+
--EXTENSIONS--
4+
gd
5+
--FILE--
6+
<?php
7+
$im = imagecreatetruecolor(16, 16);
8+
9+
try {
10+
imagescale($im, PHP_INT_MAX, -1);
11+
} catch (\ValueError $e) {
12+
echo $e->getMessage(), PHP_EOL;
13+
}
14+
try {
15+
imagescale($im, -1, PHP_INT_MAX);
16+
} catch (\ValueError $e) {
17+
echo $e->getMessage(), PHP_EOL;
18+
}
19+
?>
20+
--EXPECTF--
21+
imagescale(): Argument #2 ($width) must be less than or equal to %d
22+
imagescale(): Argument #3 ($height) must be less than or equal to %d

0 commit comments

Comments
 (0)