Skip to content

Commit a465689

Browse files
committedAug 16, 2022
Imitate legacy behavior when converting non-encodings using mbstring
Fuzzing revealed that something was missed here when making the new encoding conversion code match the behavior of the old code. In the next major release of PHP, support for these non-encodings will be dropped, but in the meantime, it is better to match the legacy behavior.
1 parent 88d1349 commit a465689

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed
 

‎ext/mbstring/libmbfl/mbfl/mbfl_convert.c

+6
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,12 @@ zend_string* mb_fast_convert(unsigned char *in, size_t in_len, const mbfl_encodi
353353
uint32_t wchar_buf[128];
354354
unsigned int state = 0;
355355

356+
if (to == &mbfl_encoding_base64 || to == &mbfl_encoding_qprint || to == &mbfl_encoding_7bit) {
357+
from = &mbfl_encoding_8bit;
358+
} else if (from == &mbfl_encoding_base64 || from == &mbfl_encoding_qprint || from == &mbfl_encoding_uuencode || from == &mbfl_encoding_7bit) {
359+
to = &mbfl_encoding_8bit;
360+
}
361+
356362
mb_convert_buf buf;
357363
mb_convert_buf_init(&buf, in_len, replacement_char, error_mode);
358364

‎ext/mbstring/tests/other_encodings.phpt

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ 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"));
1717
var_dump(mb_check_encoding(chr(255), '7bit'));
18+
var_dump(mb_convert_encoding("\xAC\xAC", '7bit', 'UHC'));
1819
echo "7bit done\n";
1920

2021
// "8bit"
@@ -27,6 +28,7 @@ string(3) "ABC"
2728
string(1) "%"
2829
string(3) "ABC"
2930
bool(false)
31+
string(2) "%%"
3032
7bit done
3133
string(1) "%"
3234
8bit done

0 commit comments

Comments
 (0)
Please sign in to comment.