Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ PHP NEWS
deeply nested arrays. (Eyüp Can Akman)
. Fixed the JIT freeing the string returned by mb_encode_mimeheader() or
mb_output_handler() while it is still in use. (Ilia Alshanetsky)
. Fixed integer overflow in the string count of mb_convert_variables()
leading to a heap out-of-bounds write. (Jorg Sowa)

- Opcache:
. Fixed bug GH-24801 (JIT: SIGFPE in ir_fold MUL_OV constant folding).
Expand Down
15 changes: 10 additions & 5 deletions ext/mbstring/mbstring.c
Original file line number Diff line number Diff line change
Expand Up @@ -3761,9 +3761,9 @@ PHP_FUNCTION(mb_convert_kana)
RETVAL_STR(jp_kana_convert(str, enc, opt));
}

static unsigned int mb_recursive_count_strings(zval *var)
static uint64_t mb_recursive_count_strings(zval *var)
{
unsigned int count = 0;
uint64_t count = 0;
ZVAL_DEREF(var);

if (mb_check_stack_limit()) {
Expand Down Expand Up @@ -3796,7 +3796,7 @@ static unsigned int mb_recursive_count_strings(zval *var)
return count;
}

static bool mb_recursive_find_strings(zval *var, const unsigned char **val_list, size_t *len_list, unsigned int *count)
static bool mb_recursive_find_strings(zval *var, const unsigned char **val_list, size_t *len_list, size_t *count)
{
ZVAL_DEREF(var);

Expand Down Expand Up @@ -3968,14 +3968,19 @@ PHP_FUNCTION(mb_convert_variables)
from_encoding = *elist;
} else {
/* auto detect */
unsigned int num = 0;
uint64_t num = 0;
for (size_t n = 0; n < argc; n++) {
zval *zv = &args[n];
num += mb_recursive_count_strings(zv);
}
if (UNEXPECTED(num > SIZE_MAX / sizeof(char *))) {
efree(ZEND_VOIDP(elist));
php_error_docref(NULL, E_WARNING, "Input contains too many strings");
RETURN_FALSE;
}
const unsigned char **val_list = (const unsigned char**)ecalloc(num, sizeof(char *));
size_t *len_list = (size_t*)ecalloc(num, sizeof(size_t));
unsigned int i = 0;
size_t i = 0;
for (size_t n = 0; n < argc; n++) {
zval *zv = &args[n];
if (mb_recursive_find_strings(zv, val_list, len_list, &i)) {
Expand Down
Loading