Skip to content

Commit

Permalink
mb_check_encoding($str, '7bit') rejects strings with bytes over 0x7F
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alexdowad committed Feb 22, 2022
1 parent 7ea3b19 commit 8a8533d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ext/mbstring/libmbfl/filters/mbfilter_7bit.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const struct mbfl_convert_vtbl vtbl_7bit_8bit = {

int mbfl_filt_conv_7bit_any(int c, mbfl_convert_filter *filter)
{
return (*filter->output_function)(c, filter->data);
return (*filter->output_function)(c < 0x80 ? c : MBFL_BAD_INPUT, filter->data);
}


Expand Down
4 changes: 3 additions & 1 deletion ext/mbstring/tests/other_encodings.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ mb_substitute_character(0x25);
var_dump(mb_convert_encoding("ABC", "7bit", "ASCII"));
var_dump(mb_convert_encoding("\x80", "7bit", "ASCII"));
var_dump(mb_convert_encoding("ABC", "8bit", "7bit"));
var_dump(mb_check_encoding(chr(255), '7bit'));
echo "7bit done\n";

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

// UCS-2
Expand All @@ -41,6 +42,7 @@ echo "UCS-4 done\n";
string(3) "ABC"
string(1) "%"
string(3) "ABC"
bool(false)
7bit done
string(1) "%"
8bit done
Expand Down

0 comments on commit 8a8533d

Please sign in to comment.