Skip to content

Commit c8e13af

Browse files
committed
Fix GH-20602: imagescale() overflow with large height values.
close GH-20605
1 parent 8fe7930 commit c8e13af

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ PHP NEWS
2727
- GD:
2828
. Fixed bug GH-20511 (imagegammacorrect out of range input/output values).
2929
(David Carlier)
30+
. Fixed bug GH-20602 (imagescale overflow with large height values).
31+
(David Carlier)
3032

3133
- LibXML:
3234
. Fix some deprecations on newer libxml versions regarding input

ext/gd/gd.c

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

36913691
if (src_x && tmp_h < 0) {
3692+
if (tmp_w > (ZEND_LONG_MAX / src_y)) {
3693+
zend_argument_value_error(2, "must be less than or equal to " ZEND_LONG_FMT, (zend_long)(ZEND_LONG_MAX / src_y));
3694+
RETURN_THROWS();
3695+
}
36923696
tmp_h = tmp_w * src_y / src_x;
36933697
}
36943698
if (src_y && tmp_w < 0) {
3699+
if (tmp_h > (ZEND_LONG_MAX / src_x)) {
3700+
zend_argument_value_error(3, "must be less than or equal to " ZEND_LONG_FMT, (zend_long)(ZEND_LONG_MAX / src_x));
3701+
RETURN_THROWS();
3702+
}
36953703
tmp_w = tmp_h * src_x / src_y;
36963704
}
36973705
}

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)