Skip to content

Commit d456189

Browse files
committed
Extraneous trailing UCS-4 bytes are treated as error
1 parent 0de4d68 commit d456189

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

ext/mbstring/libmbfl/filters/mbfilter_ucs4.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ static const char *mbfl_encoding_ucs4_aliases[] = {"ISO-10646-UCS-4", "UCS4", NU
3838
static const char *mbfl_encoding_ucs4be_aliases[] = {"byte4be", NULL};
3939
static const char *mbfl_encoding_ucs4le_aliases[] = {"byte4le", NULL};
4040

41+
static int mbfl_filt_conv_ucs4_wchar_flush(mbfl_convert_filter *filter);
42+
4143
const mbfl_encoding mbfl_encoding_ucs4 = {
4244
mbfl_no_encoding_ucs4,
4345
"UCS-4",
@@ -77,7 +79,7 @@ const struct mbfl_convert_vtbl vtbl_ucs4_wchar = {
7779
mbfl_filt_conv_common_ctor,
7880
NULL,
7981
mbfl_filt_conv_ucs4_wchar,
80-
mbfl_filt_conv_common_flush,
82+
mbfl_filt_conv_ucs4_wchar_flush,
8183
NULL,
8284
};
8385

@@ -97,7 +99,7 @@ const struct mbfl_convert_vtbl vtbl_ucs4be_wchar = {
9799
mbfl_filt_conv_common_ctor,
98100
NULL,
99101
mbfl_filt_conv_ucs4be_wchar,
100-
mbfl_filt_conv_common_flush,
102+
mbfl_filt_conv_ucs4_wchar_flush,
101103
NULL,
102104
};
103105

@@ -117,7 +119,7 @@ const struct mbfl_convert_vtbl vtbl_ucs4le_wchar = {
117119
mbfl_filt_conv_common_ctor,
118120
NULL,
119121
mbfl_filt_conv_ucs4le_wchar,
120-
mbfl_filt_conv_common_flush,
122+
mbfl_filt_conv_ucs4_wchar_flush,
121123
NULL,
122124
};
123125

@@ -281,3 +283,17 @@ int mbfl_filt_conv_wchar_ucs4le(int c, mbfl_convert_filter *filter)
281283

282284
return c;
283285
}
286+
287+
static int mbfl_filt_conv_ucs4_wchar_flush(mbfl_convert_filter *filter)
288+
{
289+
if (filter->status & 0xF) {
290+
/* Input string was truncated */
291+
CK((*filter->output_function)(filter->cache | MBFL_WCSGROUP_THROUGH, filter->data));
292+
}
293+
294+
if (filter->flush_function) {
295+
(*filter->flush_function)(filter->data);
296+
}
297+
298+
return 0;
299+
}

0 commit comments

Comments
 (0)