Skip to content

Commit 8f4d07b

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fix #79149: SEGV in mb_convert_encoding with non-string encodings
2 parents fe8af59 + 94c9dc4 commit 8f4d07b

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

ext/mbstring/mbstring.c

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

28802880
if ( _from_encodings) {
28812881
l = strlen(_from_encodings);
2882-
n = strlen(Z_STRVAL_P(hash_entry));
2882+
n = strlen(ZSTR_VAL(encoding_str));
28832883
_from_encodings = erealloc(_from_encodings, l+n+2);
28842884
memcpy(_from_encodings + l, ",", 1);
2885-
memcpy(_from_encodings + l + 1, Z_STRVAL_P(hash_entry), Z_STRLEN_P(hash_entry) + 1);
2885+
memcpy(_from_encodings + l + 1, ZSTR_VAL(encoding_str), ZSTR_LEN(encoding_str) + 1);
28862886
} else {
2887-
_from_encodings = estrdup(Z_STRVAL_P(hash_entry));
2887+
_from_encodings = estrdup(ZSTR_VAL(encoding_str));
28882888
}
28892889
zend_string_release(encoding_str);
28902890
} 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)