ext/intl: IntlNumberRangeFormatter::format() crash when the formatting fails. - #23198
Closed
devnexen wants to merge 3 commits into
Closed
ext/intl: IntlNumberRangeFormatter::format() crash when the formatting fails.#23198devnexen wants to merge 3 commits into
devnexen wants to merge 3 commits into
Conversation
…g fails. When formatFormattableRange() failed, the error was set (which throws, as exceptions are force-enabled there) but execution fell through to intl_charFromString(), which returns NULL for the bogus result, and the NULL zend_string ended up in return_value as an IS_STRING zval. The engine then dereferenced it while discarding the return value. The conversion is now only attempted for a successful formatting and both failure paths return early. createFromSkeleton() had the same shape of defect without the crash: the skeleton failure path threw and then still built a LocalizedNumberRangeFormatter out of the failed skeleton, so it bails out early as well.
format() reset the global error slot and the object one separately, and both methods reset before parsing their parameters, so a TypeError also cleared the state. Use intl_errors_reset(), which covers both slots, and reset once the parameters are known to be good.
devnexen
marked this pull request as ready for review
August 10, 2026 11:45
LamentXU123
approved these changes
Aug 10, 2026
LamentXU123
left a comment
Member
There was a problem hiding this comment.
Yet another error state bug :(
NickSdot
reviewed
Aug 10, 2026
| try { | ||
| $formatter->format([], 2); | ||
| } catch (TypeError $error) { | ||
| echo $error->getMessage(), PHP_EOL; |
Contributor
There was a problem hiding this comment.
Suggested change
| echo $error->getMessage(), PHP_EOL; | |
| echo $error::class, ': ', $error->getMessage(), PHP_EOL; |
NickSdot
reviewed
Aug 10, 2026
| IntlNumberRangeFormatter::IDENTITY_FALLBACK_RANGE | ||
| ); | ||
| } catch (TypeError $error) { | ||
| echo $error->getMessage(), PHP_EOL; |
Contributor
There was a problem hiding this comment.
Suggested change
| echo $error->getMessage(), PHP_EOL; | |
| echo $error::class, ': ', $error->getMessage(), PHP_EOL; |
NickSdot
reviewed
Aug 10, 2026
|
|
||
| ?> | ||
| --EXPECT-- | ||
| IntlNumberRangeFormatter::format(): Argument #1 ($start) must be of type int|float, array given |
Contributor
There was a problem hiding this comment.
Suggested change
| IntlNumberRangeFormatter::format(): Argument #1 ($start) must be of type int|float, array given | |
| TypeError: IntlNumberRangeFormatter::format(): Argument #1 ($start) must be of type int|float, array given |
NickSdot
reviewed
Aug 10, 2026
| --EXPECT-- | ||
| IntlNumberRangeFormatter::format(): Argument #1 ($start) must be of type int|float, array given | ||
| bool(true) | ||
| IntlNumberRangeFormatter::createFromSkeleton(): Argument #1 ($skeleton) must be of type string, array given |
Contributor
There was a problem hiding this comment.
Suggested change
| IntlNumberRangeFormatter::createFromSkeleton(): Argument #1 ($skeleton) must be of type string, array given | |
| TypeError: IntlNumberRangeFormatter::createFromSkeleton(): Argument #1 ($skeleton) must be of type string, array given |
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.
No description provided.