diff options
author | Alex Dowad <alexinbeijing@gmail.com> | 2021-01-13 21:11:11 +0200 |
---|---|---|
committer | Alex Dowad <alexinbeijing@gmail.com> | 2021-01-15 21:55:41 +0200 |
commit | 888f5d7729878caa73908a0cc09823d611d4044b (patch) | |
tree | ba4465c7d8440b2507ddd02f05361df7b35e9590 /ext/mbstring | |
parent | 2a93a8bb8ccddc3ac2df956cfc006b72f712eb2a (diff) | |
download | php-git-888f5d7729878caa73908a0cc09823d611d4044b.tar.gz |
CP5022{0,1,2}: treat truncated multibyte characters as error
Diffstat (limited to 'ext/mbstring')
-rw-r--r-- | ext/mbstring/libmbfl/filters/mbfilter_cp5022x.c | 16 | ||||
-rw-r--r-- | ext/mbstring/tests/cp5022x_encoding.phpt | 7 |
2 files changed, 20 insertions, 3 deletions
diff --git a/ext/mbstring/libmbfl/filters/mbfilter_cp5022x.c b/ext/mbstring/libmbfl/filters/mbfilter_cp5022x.c index 7db315aa94..7b4b2630f4 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_cp5022x.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_cp5022x.c @@ -39,6 +39,7 @@ typedef struct _mbfl_filt_conv_wchar_cp50220_ctx { static void mbfl_filt_conv_wchar_cp50220_ctor(mbfl_convert_filter *filt); static void mbfl_filt_conv_wchar_cp50220_dtor(mbfl_convert_filter *filt); static void mbfl_filt_conv_wchar_cp50220_copy(mbfl_convert_filter *src, mbfl_convert_filter *dest); +static int mbfl_filt_conv_cp5022x_wchar_flush(mbfl_convert_filter *filter); const mbfl_encoding mbfl_encoding_jis_ms = { mbfl_no_encoding_jis_ms, @@ -121,7 +122,7 @@ const struct mbfl_convert_vtbl vtbl_cp50220_wchar = { mbfl_filt_conv_common_ctor, NULL, mbfl_filt_conv_jis_ms_wchar, - mbfl_filt_conv_common_flush, + mbfl_filt_conv_cp5022x_wchar_flush, NULL, }; @@ -161,7 +162,7 @@ const struct mbfl_convert_vtbl vtbl_cp50221_wchar = { mbfl_filt_conv_common_ctor, NULL, mbfl_filt_conv_jis_ms_wchar, - mbfl_filt_conv_common_flush, + mbfl_filt_conv_cp5022x_wchar_flush, NULL, }; @@ -181,7 +182,7 @@ const struct mbfl_convert_vtbl vtbl_cp50222_wchar = { mbfl_filt_conv_common_ctor, NULL, mbfl_filt_conv_jis_ms_wchar, - mbfl_filt_conv_common_flush, + mbfl_filt_conv_cp5022x_wchar_flush, NULL, }; @@ -369,6 +370,15 @@ retry: return c; } +static int mbfl_filt_conv_cp5022x_wchar_flush(mbfl_convert_filter *filter) +{ + if ((filter->status & 0xF) == 1) { + /* 2-byte (JIS X 0208 or 0212) character was truncated */ + CK((*filter->output_function)(filter->cache | MBFL_WCSGROUP_THROUGH, filter->data)); + } + return 0; +} + /* * wchar => JIS */ diff --git a/ext/mbstring/tests/cp5022x_encoding.phpt b/ext/mbstring/tests/cp5022x_encoding.phpt index 341faa1a43..33a73a5e2e 100644 --- a/ext/mbstring/tests/cp5022x_encoding.phpt +++ b/ext/mbstring/tests/cp5022x_encoding.phpt @@ -204,6 +204,13 @@ for ($i = 0x21; $i <= 0x7E; $i++) { } } +/* Try truncated 2-byte characters */ +for ($i = 0x21; $i <= 0x7E; $i++) { + testInvalid("\x1B\$B" . chr($i), "\x00%", 'CP50220'); + testInvalid("\x1B\$B" . chr($i), "\x00%", 'CP50221'); + testInvalid("\x1B\$B" . chr($i), "\x00%", 'CP50222'); +} + echo "CP932 support OK\n"; /* Unicode codepoint for halfwidth katakana -> kuten code for ordinary katakana */ |