Skip to content

Commit

Permalink
Fix #81693: mb_check_encoding(7bit) segfaults
Browse files Browse the repository at this point in the history
`php_mb_check_encoding()` now uses conversion to `mbfl_encoding_wchar`.
Since `mbfl_encoding_7bit` has no `input_filter`, no filter can be
found.  Since we don't actually need to convert to wchar, we encode to
8bit.

Closes GH-7712.
  • Loading branch information
cmb69 committed Dec 3, 2021
1 parent 7a6fb97 commit 929d847
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions NEWS
Expand Up @@ -2,6 +2,9 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 8.1.2

- MBString:
. Fixed bug #81693 (mb_check_encoding(7bit) segfaults). (cmb)

- Reflection:
. Fixed bug #81681 (ReflectionEnum throwing exceptions). (cmb)

Expand Down
3 changes: 2 additions & 1 deletion ext/mbstring/libmbfl/mbfl/mbfl_convert.c
Expand Up @@ -307,7 +307,8 @@ const struct mbfl_convert_vtbl* mbfl_convert_filter_get_vtbl(const mbfl_encoding
from = &mbfl_encoding_8bit;
} else if (from->no_encoding == mbfl_no_encoding_base64 ||
from->no_encoding == mbfl_no_encoding_qprint ||
from->no_encoding == mbfl_no_encoding_uuencode) {
from->no_encoding == mbfl_no_encoding_uuencode ||
from->no_encoding == mbfl_no_encoding_7bit) {
to = &mbfl_encoding_8bit;
}

Expand Down
10 changes: 10 additions & 0 deletions ext/mbstring/tests/bug81693.phpt
@@ -0,0 +1,10 @@
--TEST--
Bug #81693 (mb_check_encoding(7bit) segfaults)
--EXTENSIONS--
mbstring
--FILE--
<?php
var_dump(mb_check_encoding('Hello world', '7bit'));
?>
--EXPECT--
bool(true)

0 comments on commit 929d847

Please sign in to comment.