Skip to content

Commit 73f9ffc

Browse files
committed
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1: Fix GH-10627: mb_convert_encoding crashes PHP on Windows ext/mbstring: fix new_value length check
2 parents 25fb7a2 + ed0c0df commit 73f9ffc

File tree

3 files changed

+47
-5
lines changed

3 files changed

+47
-5
lines changed

NEWS

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ PHP NEWS
4141
. Fixed JSON scanner and parser generation build.
4242
(Daniel Black, Jakub Zelenka)
4343

44+
- MBString:
45+
. ext/mbstring: fix new_value length check. (Max Kellermann)
46+
. Fix bug GH-10627 (mb_convert_encoding crashes PHP on Windows). (nielsdos)
47+
4448
- Opcache:
4549
. Fix incorrect page_size check. (nielsdos)
4650

@@ -83,7 +87,7 @@ PHP NEWS
8387
- Core:
8488
. Fixed bug #81744 (Password_verify() always return true with some hash).
8589
(CVE-2023-0567). (Tim Düsterhus)
86-
. Fixed bug #81746 (1-byte array overrun in common path resolve code).
90+
. Fixed bug #81746 (1-byte array overrun in common path resolve code).
8791
(CVE-2023-0568). (Niels Dossche)
8892

8993
- SAPI:

ext/mbstring/mbstring.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ static PHP_INI_MH(OnUpdate_mbstring_http_input)
761761
php_error_docref("ref.mbstring", E_DEPRECATED, "Use of mbstring.http_input is deprecated");
762762
}
763763

764-
if (!new_value || !ZSTR_VAL(new_value)) {
764+
if (!new_value || !ZSTR_LEN(new_value)) {
765765
const char *encoding = php_get_input_encoding();
766766
MBSTRG(http_input_set) = 0;
767767
_php_mb_ini_mbstring_http_input_set(encoding, strlen(encoding));
@@ -2617,15 +2617,27 @@ MBSTRING_API HashTable *php_mb_convert_encoding_recursive(HashTable *input, cons
26172617
ZEND_HASH_FOREACH_KEY_VAL(input, idx, key, entry) {
26182618
/* convert key */
26192619
if (key) {
2620-
key = php_mb_convert_encoding(ZSTR_VAL(key), ZSTR_LEN(key), to_encoding, from_encodings, num_from_encodings);
2620+
zend_string *converted_key = php_mb_convert_encoding(ZSTR_VAL(key), ZSTR_LEN(key), to_encoding, from_encodings, num_from_encodings);
2621+
if (!converted_key) {
2622+
continue;
2623+
}
2624+
key = converted_key;
26212625
}
26222626
/* convert value */
26232627
ZEND_ASSERT(entry);
26242628
try_again:
26252629
switch(Z_TYPE_P(entry)) {
2626-
case IS_STRING:
2627-
ZVAL_STR(&entry_tmp, php_mb_convert_encoding(Z_STRVAL_P(entry), Z_STRLEN_P(entry), to_encoding, from_encodings, num_from_encodings));
2630+
case IS_STRING: {
2631+
zend_string *converted_key = php_mb_convert_encoding(Z_STRVAL_P(entry), Z_STRLEN_P(entry), to_encoding, from_encodings, num_from_encodings);
2632+
if (!converted_key) {
2633+
if (key) {
2634+
zend_string_release(key);
2635+
}
2636+
continue;
2637+
}
2638+
ZVAL_STR(&entry_tmp, converted_key);
26282639
break;
2640+
}
26292641
case IS_NULL:
26302642
case IS_TRUE:
26312643
case IS_FALSE:

ext/mbstring/tests/gh10627.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
GH-10627 (mb_convert_encoding crashes PHP on Windows)
3+
--EXTENSIONS--
4+
mbstring
5+
--FILE--
6+
<?php
7+
8+
$str = 'Sökinställningar';
9+
$data = [$str, 'abc'];
10+
var_dump(mb_convert_encoding($data, 'UTF-8', 'auto'));
11+
$data = [$str => 'abc', 'abc' => 'def'];
12+
var_dump(mb_convert_encoding($data, 'UTF-8', 'auto'));
13+
14+
?>
15+
--EXPECTF--
16+
Warning: mb_convert_encoding(): Unable to detect character encoding in %s on line %d
17+
array(1) {
18+
[1]=>
19+
string(3) "abc"
20+
}
21+
22+
Warning: mb_convert_encoding(): Unable to detect character encoding in %s on line %d
23+
array(1) {
24+
["abc"]=>
25+
string(3) "def"
26+
}

0 commit comments

Comments
 (0)