From: Nikita Popov Date: Wed, 6 May 2020 20:55:03 +0000 (+0200) Subject: Fix assertion failure when failing to detect encoding X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=71f48260af4b75461a7a096908883375b157b896;p=php 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. --- diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c index f636d51b02..a529f84809 100644 --- a/ext/mbstring/mbstring.c +++ b/ext/mbstring/mbstring.c @@ -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; } } diff --git a/ext/mbstring/tests/mb_convert_encoding_failed_detection.phpt b/ext/mbstring/tests/mb_convert_encoding_failed_detection.phpt new file mode 100644 index 0000000000..961af505ec --- /dev/null +++ b/ext/mbstring/tests/mb_convert_encoding_failed_detection.phpt @@ -0,0 +1,11 @@ +--TEST-- +mb_convert_encoding() when encoding detection fails +--FILE-- + +--EXPECTF-- +Warning: mb_convert_encoding(): Unable to detect character encoding in %s on line %d +bool(false)