Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ext/gd/gd.c
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,11 @@ PHP_FUNCTION(imagefilledellipse)
RETURN_THROWS();
}

if (w < 0 || w > INT_MAX) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably can use ZEND_LONG_INT_OVFL to avoid compiler warnings for INT_MAX if zend_long==int.

zend_argument_value_error(4, "must be between 0 and %d", INT_MAX);
RETURN_THROWS();
}

im = php_gd_libgdimageptr_from_zval_p(IM);

gdImageFilledEllipse(im, cx, cy, w, h, color);
Expand Down
27 changes: 27 additions & 0 deletions ext/gd/tests/gh19578.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--TEST--
GH-19578: imagefilledellipse underflow on width argument
--EXTENSIONS--
gd
--SKIPIF--
<?php
if (PHP_INT_SIZE != 8) die('skip this test is for 64bit platforms only');
?>
--FILE--
<?php
$src = imagecreatetruecolor(255, 255);

try {
imagefilledellipse($src, 0, 0, PHP_INT_MAX, 254, 0);
} catch (\ValueError $e) {
echo $e->getMessage(), PHP_EOL;
}

try {
imagefilledellipse($src, 0, 0, -16, 254, 0);
} catch (\ValueError $e) {
echo $e->getMessage();
}
?>
--EXPECTF--
imagefilledellipse(): Argument #4 ($width) must be between 0 and %d
imagefilledellipse(): Argument #4 ($width) must be between 0 and %d
20 changes: 20 additions & 0 deletions ext/gd/tests/gh19578_32bits.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
GH-19578: imagefilledellipse underflow on width argument
--EXTENSIONS--
gd
--SKIPIF--
<?php
if (PHP_INT_SIZE != 4) die('skip this test is for 32bit platforms only');
?>
--FILE--
<?php
$src = imagecreatetruecolor(255, 255);

try {
imagefilledellipse($src, 0, 0, -16, 254, 0);
} catch (\ValueError $e) {
echo $e->getMessage();
}
?>
--EXPECTF--
imagefilledellipse(): Argument #4 ($width) must be between 0 and %d
Loading