Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
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
6 changes: 6 additions & 0 deletions ext/gd/gd.c
Original file line number Diff line number Diff line change
Expand Up @@ -3082,6 +3082,12 @@ static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode)
im = php_gd_libgdimageptr_from_zval_p(IM);
}

// FT_F26Dot6 is a signed long alias
if (ptsize < (double)LONG_MIN / 64 || ptsize > (double)LONG_MAX / 64) {
zend_argument_value_error(2, "must be between " ZEND_LONG_FMT " and " ZEND_LONG_FMT, (zend_long)(LONG_MIN / 64), (zend_long)(LONG_MAX / 64));
RETURN_THROWS();
}

/* convert angle to radians */
angle = angle * (M_PI/180);

Expand Down
24 changes: 24 additions & 0 deletions ext/gd/tests/gh18243.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
GH-18243: imagefttext underflow/overflow on $size
--EXTENSIONS--
gd
--FILE--
<?php
$font = __DIR__.'/Rochester-Regular.otf';
$im = imagecreatetruecolor(100, 80);

try {
imagettftext($im, PHP_INT_MAX, 0, 15, 60, 0, $font, "");
} catch (\ValueError $e) {
echo $e->getMessage(), PHP_EOL;
}

try {
imagettftext($im, PHP_INT_MIN, 0, 15, 60, 0, $font, "");
} catch (\ValueError $e) {
echo $e->getMessage();
}
?>
--EXPECTF--
imagettftext(): Argument #2 ($size) must be between %i and %d
imagettftext(): Argument #2 ($size) must be between %i and %d
Loading