Skip to content

ext/intl: Use zval_get_tmp_string where possible #18966

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 28, 2025
Merged
Changes from all 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: 3 additions & 3 deletions ext/intl/listformatter/listformatter_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,17 @@ PHP_METHOD(IntlListFormatter, format)
zval *val;

ZEND_HASH_FOREACH_VAL(ht, val) {
zend_string *str_val;
zend_string *str_val, *tmp_str;

str_val = zval_get_string(val);
str_val = zval_get_tmp_string(val, &tmp_str);
Copy link
Member

Choose a reason for hiding this comment

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

Isn't there an exception check missing here if we have a non stringable object (or an error handler promoting the array to string warning) in val?

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe, but does it matter? The exception will cause the VM to discard the result anyway. The only consequence is that we'll throw the exception a bit "late".

Copy link
Member

Choose a reason for hiding this comment

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

I guess, I'm just used with us dealing with those sorts of things more proactively now, and I guess this can matter if there is a follow-up object that does some stuff with side-effects in __toString() ?

Copy link
Member Author

Choose a reason for hiding this comment

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

If it's an internal object with a acst handler, it'll go through the cast handler, if that has side effects (which please god no) then it can cause problems.
If it's an internal or userland object, with a __toString method, then it won't call __toString if EG(exception) is already set. So in this case there can be no problems.

Copy link
Member

Choose a reason for hiding this comment

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

Ah I forgot that the VM doesn't actual call follow-up methods in case of an Exception.


// Convert PHP string to UTF-16
UChar *ustr = NULL;
int32_t ustr_len = 0;
UErrorCode status = U_ZERO_ERROR;

intl_convert_utf8_to_utf16(&ustr, &ustr_len, ZSTR_VAL(str_val), ZSTR_LEN(str_val), &status);
zend_string_release(str_val);
zend_tmp_string_release(tmp_str);

if (U_FAILURE(status)) {
// We can't use goto cleanup because items and itemLengths are incompletely allocated
Expand Down