Skip to content

Commit 94c9dc4

Browse files
committed
Fix #79149: SEGV in mb_convert_encoding with non-string encodings
We must not assume that `hash_entry` `IS_STRING`, but rather use `encoding_str` which is guaranteed to be.
1 parent d904be0 commit 94c9dc4

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ PHP NEWS
1616
. Fixed bug #79112 (IMAP extension can't find OpenSSL libraries at configure
1717
time). (Nikita)
1818

19+
- MBString:
20+
. Fixed bug #79149 (SEGV in mb_convert_encoding with non-string encodings).
21+
(cmb)
22+
1923
- MySQLnd:
2024
. Fixed bug #79084 (mysqlnd may fetch wrong column indexes with MYSQLI_BOTH).
2125
(cmb)

ext/mbstring/mbstring.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3369,12 +3369,12 @@ PHP_FUNCTION(mb_convert_encoding)
33693369

33703370
if ( _from_encodings) {
33713371
l = strlen(_from_encodings);
3372-
n = strlen(Z_STRVAL_P(hash_entry));
3372+
n = strlen(ZSTR_VAL(encoding_str));
33733373
_from_encodings = erealloc(_from_encodings, l+n+2);
33743374
memcpy(_from_encodings + l, ",", 1);
3375-
memcpy(_from_encodings + l + 1, Z_STRVAL_P(hash_entry), Z_STRLEN_P(hash_entry) + 1);
3375+
memcpy(_from_encodings + l + 1, ZSTR_VAL(encoding_str), ZSTR_LEN(encoding_str) + 1);
33763376
} else {
3377-
_from_encodings = estrdup(Z_STRVAL_P(hash_entry));
3377+
_from_encodings = estrdup(ZSTR_VAL(encoding_str));
33783378
}
33793379
zend_string_release(encoding_str);
33803380
} ZEND_HASH_FOREACH_END();

ext/mbstring/tests/bug79149.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Bug #79149 (SEGV in mb_convert_encoding with non-string encodings)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('mbstring')) die('skip mbstring extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
var_dump(mb_convert_encoding("", "UTF-8", [0]));
10+
var_dump(mb_convert_encoding('foo', 'UTF-8', array(['bar'], ['baz'])));
11+
?>
12+
--EXPECTF--
13+
Warning: mb_convert_encoding(): Illegal character encoding specified in %s on line %d
14+
string(0) ""
15+
16+
Notice: Array to string conversion in %s on line %d
17+
18+
Notice: Array to string conversion in %s on line %d
19+
20+
Warning: mb_convert_encoding(): Illegal character encoding specified in %s on line %d
21+
string(3) "foo"

0 commit comments

Comments
 (0)