Fix assertion failure when failing to detect encoding

Looks like prior to 7.3 this just passed the original string
through. Since 7.3 it returns false. Let's stick with that
behavior.
This commit is contained in:
Nikita Popov 2020-05-06 22:55:03 +02:00
parent 9d869f24d4
commit 71f48260af
2 changed files with 12 additions and 4 deletions

View File

@ -2489,9 +2489,6 @@ MBSTRING_API char *php_mb_convert_encoding(const char *input, size_t length, con
if (output_len) {
*output_len = 0;
}
if (!input) {
return NULL;
}
/* pre-conversion encoding */
ZEND_ASSERT(num_from_encodings >= 1);
@ -2507,7 +2504,7 @@ MBSTRING_API char *php_mb_convert_encoding(const char *input, size_t length, con
&string, from_encodings, num_from_encodings, MBSTRG(strict_detection));
if (!from_encoding) {
php_error_docref(NULL, E_WARNING, "Unable to detect character encoding");
from_encoding = &mbfl_encoding_pass;
return NULL;
}
}

View File

@ -0,0 +1,11 @@
--TEST--
mb_convert_encoding() when encoding detection fails
--FILE--
<?php
var_dump(mb_convert_encoding("\xff", "ASCII", ["UTF-8", "UTF-16"]));
?>
--EXPECTF--
Warning: mb_convert_encoding(): Unable to detect character encoding in %s on line %d
bool(false)