ext/gd: report $size with the argument number of the function called - #23541
Open
lacatoire wants to merge 1 commit into
Open
ext/gd: report $size with the argument number of the function called#23541lacatoire wants to merge 1 commit into
lacatoire wants to merge 1 commit into
Conversation
lacatoire
force-pushed
the
fix/gd-ftbbox-size-arg-num-upstream
branch
from
September 2, 2026 12:31
5729cf3 to
dfa7818
Compare
devnexen
reviewed
Sep 2, 2026
lacatoire
force-pushed
the
fix/gd-ftbbox-size-arg-num-upstream
branch
from
September 2, 2026 13:12
dfa7818 to
5f0cd02
Compare
NickSdot
reviewed
Sep 2, 2026
Comment on lines
+15
to
+62
| foreach ([NAN, INF, PHP_INT_MAX, PHP_INT_MIN] as $size) { | ||
| try { | ||
| imageftbbox($size, 0.0, $font, 'A'); | ||
| } catch (ValueError $e) { | ||
| echo $e->getMessage(), "\n"; | ||
| } | ||
| try { | ||
| imagettfbbox($size, 0.0, $font, 'A'); | ||
| } catch (ValueError $e) { | ||
| echo $e->getMessage(), "\n"; | ||
| } | ||
| } | ||
|
|
||
| /* and argument #2 here */ | ||
| foreach ([NAN, INF] as $size) { | ||
| try { | ||
| imagefttext($image, $size, 0.0, 15, 60, 0, $font, 'A'); | ||
| } catch (ValueError $e) { | ||
| echo $e->getMessage(), "\n"; | ||
| } | ||
| try { | ||
| imagettftext($image, $size, 0.0, 15, 60, 0, $font, 'A'); | ||
| } catch (ValueError $e) { | ||
| echo $e->getMessage(), "\n"; | ||
| } | ||
| } | ||
|
|
||
| /* the type error already agreed with the signature and still does */ | ||
| try { | ||
| imageftbbox('x', 0.0, $font, 'A'); | ||
| } catch (TypeError $e) { | ||
| echo $e->getMessage(), "\n"; | ||
| } | ||
| ?> | ||
| --EXPECTF-- | ||
| imageftbbox(): Argument #1 ($size) must be finite | ||
| imagettfbbox(): Argument #1 ($size) must be finite | ||
| imageftbbox(): Argument #1 ($size) must be between %i and %d | ||
| imagettfbbox(): Argument #1 ($size) must be between %i and %d | ||
| imageftbbox(): Argument #1 ($size) must be between %i and %d | ||
| imagettfbbox(): Argument #1 ($size) must be between %i and %d | ||
| imageftbbox(): Argument #1 ($size) must be between %i and %d | ||
| imagettfbbox(): Argument #1 ($size) must be between %i and %d | ||
| imagefttext(): Argument #2 ($size) must be finite | ||
| imagettftext(): Argument #2 ($size) must be finite | ||
| imagefttext(): Argument #2 ($size) must be between %i and %d | ||
| imagettftext(): Argument #2 ($size) must be between %i and %d | ||
| imageftbbox(): Argument #1 ($size) must be of type float, string given |
Contributor
There was a problem hiding this comment.
Suggested change
| foreach ([NAN, INF, PHP_INT_MAX, PHP_INT_MIN] as $size) { | |
| try { | |
| imageftbbox($size, 0.0, $font, 'A'); | |
| } catch (ValueError $e) { | |
| echo $e->getMessage(), "\n"; | |
| } | |
| try { | |
| imagettfbbox($size, 0.0, $font, 'A'); | |
| } catch (ValueError $e) { | |
| echo $e->getMessage(), "\n"; | |
| } | |
| } | |
| /* and argument #2 here */ | |
| foreach ([NAN, INF] as $size) { | |
| try { | |
| imagefttext($image, $size, 0.0, 15, 60, 0, $font, 'A'); | |
| } catch (ValueError $e) { | |
| echo $e->getMessage(), "\n"; | |
| } | |
| try { | |
| imagettftext($image, $size, 0.0, 15, 60, 0, $font, 'A'); | |
| } catch (ValueError $e) { | |
| echo $e->getMessage(), "\n"; | |
| } | |
| } | |
| /* the type error already agreed with the signature and still does */ | |
| try { | |
| imageftbbox('x', 0.0, $font, 'A'); | |
| } catch (TypeError $e) { | |
| echo $e->getMessage(), "\n"; | |
| } | |
| ?> | |
| --EXPECTF-- | |
| imageftbbox(): Argument #1 ($size) must be finite | |
| imagettfbbox(): Argument #1 ($size) must be finite | |
| imageftbbox(): Argument #1 ($size) must be between %i and %d | |
| imagettfbbox(): Argument #1 ($size) must be between %i and %d | |
| imageftbbox(): Argument #1 ($size) must be between %i and %d | |
| imagettfbbox(): Argument #1 ($size) must be between %i and %d | |
| imageftbbox(): Argument #1 ($size) must be between %i and %d | |
| imagettfbbox(): Argument #1 ($size) must be between %i and %d | |
| imagefttext(): Argument #2 ($size) must be finite | |
| imagettftext(): Argument #2 ($size) must be finite | |
| imagefttext(): Argument #2 ($size) must be between %i and %d | |
| imagettftext(): Argument #2 ($size) must be between %i and %d | |
| imageftbbox(): Argument #1 ($size) must be of type float, string given | |
| foreach ([NAN, INF, PHP_INT_MAX, PHP_INT_MIN] as $size) { | |
| try { | |
| imageftbbox($size, 0.0, $font, 'A'); | |
| } catch (Throwable $e) { | |
| echo $e::class, ': ', $e->getMessage(), "\n"; | |
| } | |
| try { | |
| imagettfbbox($size, 0.0, $font, 'A'); | |
| } catch (Throwable $e) { | |
| echo $e::class, ': ', $e->getMessage(), "\n"; | |
| } | |
| } | |
| /* and argument #2 here */ | |
| foreach ([NAN, INF] as $size) { | |
| try { | |
| imagefttext($image, $size, 0.0, 15, 60, 0, $font, 'A'); | |
| } catch (Throwable $e) { | |
| echo $e::class, ': ', $e->getMessage(), "\n"; | |
| } | |
| try { | |
| imagettftext($image, $size, 0.0, 15, 60, 0, $font, 'A'); | |
| } catch (Throwable $e) { | |
| echo $e::class, ': ', $e->getMessage(), "\n"; | |
| } | |
| } | |
| /* the type error already agreed with the signature and still does */ | |
| try { | |
| imageftbbox('x', 0.0, $font, 'A'); | |
| } catch (Throwable $e) { | |
| echo $e::class, ': ', $e->getMessage(), "\n"; | |
| } | |
| ?> | |
| --EXPECTF-- | |
| ValueError: imageftbbox(): Argument #1 ($size) must be finite | |
| ValueError: imagettfbbox(): Argument #1 ($size) must be finite | |
| ValueError: imageftbbox(): Argument #1 ($size) must be between %i and %d | |
| ValueError: imagettfbbox(): Argument #1 ($size) must be between %i and %d | |
| ValueError: imageftbbox(): Argument #1 ($size) must be between %i and %d | |
| ValueError: imagettfbbox(): Argument #1 ($size) must be between %i and %d | |
| ValueError: imageftbbox(): Argument #1 ($size) must be between %i and %d | |
| ValueError: imagettfbbox(): Argument #1 ($size) must be between %i and %d | |
| ValueError: imagefttext(): Argument #2 ($size) must be finite | |
| ValueError: imagettftext(): Argument #2 ($size) must be finite | |
| ValueError: imagefttext(): Argument #2 ($size) must be between %i and %d | |
| ValueError: imagettftext(): Argument #2 ($size) must be between %i and %d | |
| TypeError: imageftbbox(): Argument #1 ($size) must be of type float, string given |
devnexen
requested changes
Sep 2, 2026
| // 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)((double)LONG_MIN / 64), (zend_long)((double)LONG_MAX / 64)); | ||
| zend_argument_value_error(ptsize_arg_num, "must be between " ZEND_LONG_FMT " and " ZEND_LONG_FMT, (zend_long)((double)LONG_MIN / 64), (zend_long)((double)LONG_MAX / 64)); |
Member
There was a problem hiding this comment.
--- a/ext/gd/gd.c
+++ b/ext/gd/gd.c
@@ -3423,8 +3423,8 @@ static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode)
}
// 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)((double)LONG_MIN / 64), (zend_long)((double)LONG_MAX /
+ 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();
}--- a/ext/gd/tests/gh18243.phpt
+++ b/ext/gd/tests/gh18243.phpt
@@ -25,10 +25,17 @@ try {
try {
imagettftext($im, INF, 0, 15, 60, 0, $font, "");
} catch (\ValueError $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
+
+try {
+ imagettftext($im, 144115188075855872.0, 0, 15, 60, 0, $font, "");
+} catch (\ValueError $e) {
+ echo $e::class, ': ', $e->getMessage(), PHP_EOL;
+}
?>
--EXPECTF--
ValueError: imagettftext(): Argument #2 ($size) must be between %i and %d
ValueError: imagettftext(): Argument #2 ($size) must be between %i and %d
ValueError: imagettftext(): Argument #2 ($size) must be finite
ValueError: imagettftext(): Argument #2 ($size) must be between %i and %d
+ValueError: imagettftext(): Argument #2 ($size) must be between %i and %d
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
php_imagettftext_common()backs four functions with two signatures:$sizeis argument 1 ofimageftbbox()andimagettfbbox(), and 2 ofimagefttext()andimagettftext(), which take the image first. Both size checks hardcode 2, so the bbox pair blames$angle:$anglewas0.0. The type error for the same parameter already says #1, since that one comes from the arginfo:The number is now derived from the mode the helper was called in; the drawing pair keeps 2.
The added test covers all four functions, in the order the checks run: the range test precedes the finite test, so
INFreports "must be between" whileNAN, false against both bounds, falls through to "must be finite".Only the two bbox messages change, so this targets master.