Skip to content

Commit 8a8533d

Browse files
committed
mb_check_encoding($str, '7bit') rejects strings with bytes over 0x7F
This was the old behavior of mb_check_encoding() before 3e7acf9, but yours truly broke it. If only we had more thorough tests at that time, this might not have slipped through the cracks. Thanks to divinity76 for the report.
1 parent 7ea3b19 commit 8a8533d

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

ext/mbstring/libmbfl/filters/mbfilter_7bit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const struct mbfl_convert_vtbl vtbl_7bit_8bit = {
6767

6868
int mbfl_filt_conv_7bit_any(int c, mbfl_convert_filter *filter)
6969
{
70-
return (*filter->output_function)(c, filter->data);
70+
return (*filter->output_function)(c < 0x80 ? c : MBFL_BAD_INPUT, filter->data);
7171
}
7272

7373

ext/mbstring/tests/other_encodings.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ mb_substitute_character(0x25);
1414
var_dump(mb_convert_encoding("ABC", "7bit", "ASCII"));
1515
var_dump(mb_convert_encoding("\x80", "7bit", "ASCII"));
1616
var_dump(mb_convert_encoding("ABC", "8bit", "7bit"));
17+
var_dump(mb_check_encoding(chr(255), '7bit'));
1718
echo "7bit done\n";
1819

1920
// "8bit"
20-
var_dump(mb_convert_encoding("\x01\x00", "8bit", "UTF-16BE")); // codepoints over 0xFF are illegal or '8-bit'
21+
var_dump(mb_convert_encoding("\x01\x00", "8bit", "UTF-16BE")); // codepoints over 0xFF are illegal for '8-bit'
2122
echo "8bit done\n";
2223

2324
// UCS-2
@@ -41,6 +42,7 @@ echo "UCS-4 done\n";
4142
string(3) "ABC"
4243
string(1) "%"
4344
string(3) "ABC"
45+
bool(false)
4446
7bit done
4547
string(1) "%"
4648
8bit done

0 commit comments

Comments
 (0)