summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Dowad <alexinbeijing@gmail.com>2021-01-13 21:07:41 +0200
committerAlex Dowad <alexinbeijing@gmail.com>2021-01-14 22:34:16 +0200
commit4299e2de4207841e93d19813eabeb196a436ecc9 (patch)
tree5fdf896e4cc71383106d367832ebf8a66cd967be
parentb67e358e75fc55ec802215fac0ca5a8e21b1f307 (diff)
downloadphp-git-4299e2de4207841e93d19813eabeb196a436ecc9.tar.gz
JIS7/JIS8 encoding: treat truncated multibyte characters as error
-rw-r--r--ext/mbstring/libmbfl/filters/mbfilter_jis.c15
-rw-r--r--ext/mbstring/tests/iso2022jp_encoding.phpt11
2 files changed, 24 insertions, 2 deletions
diff --git a/ext/mbstring/libmbfl/filters/mbfilter_jis.c b/ext/mbstring/libmbfl/filters/mbfilter_jis.c
index 68f2377ab5..fe2b852a77 100644
--- a/ext/mbstring/libmbfl/filters/mbfilter_jis.c
+++ b/ext/mbstring/libmbfl/filters/mbfilter_jis.c
@@ -33,6 +33,8 @@
#include "unicode_table_cp932_ext.h"
#include "unicode_table_jis.h"
+static int mbfl_filt_conv_jis_wchar_flush(mbfl_convert_filter *filter);
+
const mbfl_encoding mbfl_encoding_jis = {
mbfl_no_encoding_jis,
"JIS",
@@ -61,7 +63,7 @@ const struct mbfl_convert_vtbl vtbl_jis_wchar = {
mbfl_filt_conv_common_ctor,
NULL,
mbfl_filt_conv_jis_wchar,
- mbfl_filt_conv_common_flush,
+ mbfl_filt_conv_jis_wchar_flush,
NULL,
};
@@ -81,7 +83,7 @@ const struct mbfl_convert_vtbl vtbl_2022jp_wchar = {
mbfl_filt_conv_common_ctor,
NULL,
mbfl_filt_conv_jis_wchar,
- mbfl_filt_conv_common_flush,
+ mbfl_filt_conv_jis_wchar_flush,
NULL,
};
@@ -264,6 +266,15 @@ retry:
return c;
}
+static int mbfl_filt_conv_jis_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/iso2022jp_encoding.phpt b/ext/mbstring/tests/iso2022jp_encoding.phpt
index 13fd6a6f07..fd1e057edf 100644
--- a/ext/mbstring/tests/iso2022jp_encoding.phpt
+++ b/ext/mbstring/tests/iso2022jp_encoding.phpt
@@ -125,6 +125,12 @@ for ($i = 0x21; $i <= 0x7E; $i++) {
}
}
+/* Try truncated JISX0208 characters */
+for ($i = 0x21; $i <= 0x7E; $i++) {
+ testInvalid("\x1B\$B" . chr($i), "\x00%", 'JIS');
+ testInvalid("\x1B\$B" . chr($i), "\x00%", 'ISO-2022-JP');
+}
+
echo "JIS X 0208 support OK\n";
/* JIS7 supports escape to switch to JIS X 0212 charset, but ISO-2022-JP does not */
@@ -144,6 +150,11 @@ for ($i = 0x21; $i <= 0x7E; $i++) {
}
}
+/* Try truncated JISX0212 characters */
+for ($i = 0x21; $i <= 0x7E; $i++) {
+ testInvalid("\x1B\$(D" . chr($i), "\x00%", 'JIS');
+}
+
echo "JIS X 0212 support OK\n";
/* All possible escape sequences */