Skip to content

Commit 1526bab

Browse files
committed
Fix legacy conversion filter for GB18030
1 parent 6938e35 commit 1526bab

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

ext/mbstring/libmbfl/filters/mbfilter_gb18030.c

+2
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,8 @@ int mbfl_filt_conv_wchar_gb18030(int c, mbfl_convert_filter *filter)
364364

365365
if (c == 0) {
366366
s = 0;
367+
} else if (s == 0) {
368+
s = -1;
367369
}
368370

369371
if (s >= 0) {

ext/mbstring/tests/gb18030_encoding.phpt

+4
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,10 @@ echo "Tested GB18030 4-byte characters <-> UTF-16BE\n";
302302
testAllValidChars($fromUnicode, 'UTF-16BE', 'GB18030', false);
303303
echo "Tested UTF-16BE -> GB18030 (1 and 2 byte characters)\n";
304304

305+
// Regression test
306+
// This was found by a fuzzer (previously the invalid codepoint would be converted to \x00)
307+
convertInvalidString("\xAA\xB8\x2D\x38\x00\x00\x00#", "%#", "UTF-32BE", "GB18030");
308+
305309
// Test "long" illegal character markers
306310
mb_substitute_character("long");
307311
convertInvalidString("\x81\x30\x81\xFF", "%", "GB18030", "UTF-8");

0 commit comments

Comments
 (0)