Don't mix strlen() and ZSTR_LEN(). If the encoding contains a
NULL byte, this will overflow the buffer.
NULL bytes will still make this behave oddly because the consuming
code will cut off the string there, but let's address that in master...
if ( _from_encodings) {
l = strlen(_from_encodings);
- n = strlen(ZSTR_VAL(encoding_str));
+ n = ZSTR_LEN(encoding_str);
_from_encodings = erealloc(_from_encodings, l+n+2);
memcpy(_from_encodings + l, ",", 1);
memcpy(_from_encodings + l + 1, ZSTR_VAL(encoding_str), ZSTR_LEN(encoding_str) + 1);
<?php
var_dump(mb_convert_encoding("", "UTF-8", [0]));
var_dump(mb_convert_encoding('foo', 'UTF-8', array(['bar'], ['baz'])));
+var_dump(mb_convert_encoding('foo', 'UTF-8', array("foo\0bar")));
?>
--EXPECTF--
Warning: mb_convert_encoding(): Illegal character encoding specified in %s on line %d
Warning: mb_convert_encoding(): Illegal character encoding specified in %s on line %d
string(3) "foo"
+
+Warning: mb_convert_encoding(): Illegal character encoding specified in %s on line %d
+string(3) "foo"