Skip to content

Commit 71f4826

Browse files
committed
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.
1 parent 9d869f2 commit 71f4826

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

ext/mbstring/mbstring.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2489,9 +2489,6 @@ MBSTRING_API char *php_mb_convert_encoding(const char *input, size_t length, con
24892489
if (output_len) {
24902490
*output_len = 0;
24912491
}
2492-
if (!input) {
2493-
return NULL;
2494-
}
24952492

24962493
/* pre-conversion encoding */
24972494
ZEND_ASSERT(num_from_encodings >= 1);
@@ -2507,7 +2504,7 @@ MBSTRING_API char *php_mb_convert_encoding(const char *input, size_t length, con
25072504
&string, from_encodings, num_from_encodings, MBSTRG(strict_detection));
25082505
if (!from_encoding) {
25092506
php_error_docref(NULL, E_WARNING, "Unable to detect character encoding");
2510-
from_encoding = &mbfl_encoding_pass;
2507+
return NULL;
25112508
}
25122509
}
25132510

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
mb_convert_encoding() when encoding detection fails
3+
--FILE--
4+
<?php
5+
6+
var_dump(mb_convert_encoding("\xff", "ASCII", ["UTF-8", "UTF-16"]));
7+
8+
?>
9+
--EXPECTF--
10+
Warning: mb_convert_encoding(): Unable to detect character encoding in %s on line %d
11+
bool(false)

0 commit comments

Comments
 (0)