Skip to content

Commit 24bc48e

Browse files
committed
Fix GH-16814: MessageFormatter::format throws an error on invalid array element.
1 parent cbb3b93 commit 24bc48e

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

ext/intl/msgformat/msgformat_helpers.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -439,31 +439,31 @@ U_CFUNC void umsg_format_helper(MessageFormatter_object *mfo,
439439
switch (argType) {
440440
case Formattable::kString:
441441
{
442-
zend_string *str, *tmp_str;
443-
444442
string_arg:
445443
/* This implicitly converts objects
446444
* Note that our vectors will leak if object conversion fails
447445
* and PHP ends up with a fatal error and calls longjmp
448446
* as a result of that.
449447
*/
450-
str = zval_get_tmp_string(elem, &tmp_str);
448+
if (!try_convert_to_string(elem)) {
449+
EG(exception) = NULL;
450+
continue;
451+
}
451452

452453
UnicodeString *text = new UnicodeString();
453454
intl_stringFromChar(*text,
454-
ZSTR_VAL(str), ZSTR_LEN(str), &err.code);
455+
Z_STRVAL_P(elem), Z_STRLEN_P(elem), &err.code);
455456

456457
if (U_FAILURE(err.code)) {
457458
char *message;
458459
spprintf(&message, 0, "Invalid UTF-8 data in string argument: "
459-
"'%s'", ZSTR_VAL(str));
460+
"'%s'", Z_STRVAL_P(elem));
460461
intl_errors_set(&err, err.code, message, 1);
461462
efree(message);
462463
delete text;
463464
continue;
464465
}
465466
formattable.adoptString(text);
466-
zend_tmp_string_release(tmp_str);
467467
break;
468468
}
469469
case Formattable::kDouble:

0 commit comments

Comments
 (0)