diff --git a/ext/mbstring/libmbfl/filters/mbfilter_7bit.c b/ext/mbstring/libmbfl/filters/mbfilter_7bit.c index bdf0cc78d97..dbf89931284 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_7bit.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_7bit.c @@ -78,5 +78,5 @@ int mbfl_filt_conv_any_7bit(int c, mbfl_convert_filter *filter) } else { mbfl_filt_conv_illegal_output(c, filter); } - return c; + return 0; } diff --git a/ext/mbstring/libmbfl/filters/mbfilter_base64.c b/ext/mbstring/libmbfl/filters/mbfilter_base64.c index 9e5548b4941..04161c94ab3 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_base64.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_base64.c @@ -110,7 +110,7 @@ int mbfl_filt_conv_base64enc(int c, mbfl_convert_filter *filter) CK((*filter->output_function)(mbfl_base64_table[n & 0x3f], filter->data)); } - return c; + return 0; } int mbfl_filt_conv_base64enc_flush(mbfl_convert_filter *filter) @@ -151,7 +151,7 @@ int mbfl_filt_conv_base64dec(int c, mbfl_convert_filter *filter) int n; if (c == 0x0d || c == 0x0a || c == 0x20 || c == 0x09 || c == 0x3d) { /* CR or LF or SPACE or HTAB or '=' */ - return c; + return 0; } n = 0; @@ -190,7 +190,7 @@ int mbfl_filt_conv_base64dec(int c, mbfl_convert_filter *filter) break; } - return c; + return 0; } int mbfl_filt_conv_base64dec_flush(mbfl_convert_filter *filter) diff --git a/ext/mbstring/libmbfl/filters/mbfilter_big5.c b/ext/mbstring/libmbfl/filters/mbfilter_big5.c index ef0cee08e13..c4f77a26fc4 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_big5.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_big5.c @@ -154,7 +154,7 @@ int mbfl_filt_conv_big5_wchar(int c, mbfl_convert_filter *filter) filter->status = 1; filter->cache = c; } else { - CK((*filter->output_function)(c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -231,12 +231,11 @@ int mbfl_filt_conv_big5_wchar(int c, mbfl_convert_filter *filter) } if (w <= 0) { - w = (c1 << 8) | c | MBFL_WCSPLANE_BIG5; + w = MBFL_BAD_INPUT; } CK((*filter->output_function)(w, filter->data)); } else { - w = (c1 << 8) | c | MBFL_WCSGROUP_THROUGH; - CK((*filter->output_function)(w, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -245,14 +244,14 @@ int mbfl_filt_conv_big5_wchar(int c, mbfl_convert_filter *filter) break; } - return c; + return 0; } static int mbfl_filt_conv_big5_wchar_flush(mbfl_convert_filter *filter) { if (filter->status == 1) { /* 2-byte character was truncated */ - CK((*filter->output_function)(filter->cache | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } if (filter->flush_function) { @@ -377,5 +376,5 @@ int mbfl_filt_conv_wchar_big5(int c, mbfl_convert_filter *filter) CK(mbfl_filt_conv_illegal_output(c, filter)); } - return c; + return 0; } diff --git a/ext/mbstring/libmbfl/filters/mbfilter_cp5022x.c b/ext/mbstring/libmbfl/filters/mbfilter_cp5022x.c index 9501c173d7f..8a103a503ab 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_cp5022x.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_cp5022x.c @@ -173,9 +173,7 @@ retry: } else if (c > 0xa0 && c < 0xe0) { /* GR kana */ CK((*filter->output_function)(0xfec0 + c, filter->data)); } else { - w = c & MBFL_WCSGROUP_MASK; - w |= MBFL_WCSGROUP_THROUGH; - CK((*filter->output_function)(w, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -201,10 +199,9 @@ retry: } else { w = 0; } + if (w <= 0) { - w = (c1 << 8) | c; - w &= MBFL_WCSPLANE_MASK; - w |= MBFL_WCSPLANE_JIS0208; + w = MBFL_BAD_INPUT; } } else { if (s >= 0 && s < jisx0212_ucs_table_size) { @@ -212,14 +209,14 @@ retry: } else { w = 0; } + if (w <= 0) { - w = (c1 << 8) | c | MBFL_WCSPLANE_JIS0212; + w = MBFL_BAD_INPUT; } } CK((*filter->output_function)(w, filter->data)); } else { - w = (c1 << 8) | c | MBFL_WCSGROUP_THROUGH; - CK((*filter->output_function)(w, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -236,7 +233,7 @@ retry: filter->status += 3; } else { filter->status &= ~0xf; - CK((*filter->output_function)(0x1b | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); goto retry; } break; @@ -254,7 +251,7 @@ retry: filter->status++; } else { filter->status &= ~0xf; - CK((*filter->output_function)(0x1b | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); CK((*filter->output_function)(0x24, filter->data)); goto retry; } @@ -273,7 +270,7 @@ retry: filter->status = 0x90; } else { filter->status &= ~0xf; - CK((*filter->output_function)(0x1b | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); CK((*filter->output_function)(0x24, filter->data)); CK((*filter->output_function)(0x28, filter->data)); goto retry; @@ -295,7 +292,7 @@ retry: filter->status = 0x20; } else { filter->status &= ~0xf; - CK((*filter->output_function)(0x1b | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); CK((*filter->output_function)(0x28, filter->data)); goto retry; } @@ -306,14 +303,14 @@ retry: break; } - return c; + return 0; } 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)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } if (filter->flush_function) { @@ -498,7 +495,7 @@ int mbfl_filt_conv_wchar_cp50221(int c, mbfl_convert_filter *filter) CK(mbfl_filt_conv_illegal_output(c, filter)); } - return c; + return 0; } /* @@ -639,7 +636,7 @@ int mbfl_filt_conv_wchar_cp50222(int c, mbfl_convert_filter *filter) CK(mbfl_filt_conv_illegal_output(c, filter)); } - return c; + return 0; } int diff --git a/ext/mbstring/libmbfl/filters/mbfilter_cp51932.c b/ext/mbstring/libmbfl/filters/mbfilter_cp51932.c index 5d1d08998cf..9bfb75fee8c 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_cp51932.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_cp51932.c @@ -108,7 +108,7 @@ mbfl_filt_conv_cp51932_wchar(int c, mbfl_convert_filter *filter) } else if (c == 0x8e) { /* kana first char */ filter->status = 2; } else { - CK((*filter->output_function)(c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -145,12 +145,11 @@ mbfl_filt_conv_cp51932_wchar(int c, mbfl_convert_filter *filter) } } if (w <= 0) { - w = ((c1 & 0x7f) << 8) | (c & 0x7f) | MBFL_WCSPLANE_WINCP932; + w = MBFL_BAD_INPUT; } CK((*filter->output_function)(w, filter->data)); } else { - w = (c1 << 8) | c | MBFL_WCSGROUP_THROUGH; - CK((*filter->output_function)(w, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -160,8 +159,7 @@ mbfl_filt_conv_cp51932_wchar(int c, mbfl_convert_filter *filter) w = 0xfec0 + c; CK((*filter->output_function)(w, filter->data)); } else { - w = 0x8e00 | c | MBFL_WCSGROUP_THROUGH; - CK((*filter->output_function)(w, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -170,14 +168,14 @@ mbfl_filt_conv_cp51932_wchar(int c, mbfl_convert_filter *filter) break; } - return c; + return 0; } static int mbfl_filt_conv_cp51932_wchar_flush(mbfl_convert_filter *filter) { if (filter->status) { /* Input string was truncated */ - (*filter->output_function)(filter->cache | MBFL_WCSGROUP_THROUGH, filter->data); + (*filter->output_function)(MBFL_BAD_INPUT, filter->data); } if (filter->flush_function) { @@ -267,5 +265,5 @@ mbfl_filt_conv_wchar_cp51932(int c, mbfl_convert_filter *filter) CK(mbfl_filt_conv_illegal_output(c, filter)); } - return c; + return 0; } diff --git a/ext/mbstring/libmbfl/filters/mbfilter_cp932.c b/ext/mbstring/libmbfl/filters/mbfilter_cp932.c index 9286114788c..10559b593be 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_cp932.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_cp932.c @@ -151,7 +151,7 @@ mbfl_filt_conv_cp932_wchar(int c, mbfl_convert_filter *filter) filter->status = 1; filter->cache = c; } else { - CK((*filter->output_function)(c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -192,13 +192,14 @@ mbfl_filt_conv_cp932_wchar(int c, mbfl_convert_filter *filter) w = s - (94*94) + 0xe000; } } + if (w <= 0) { - w = (s1 << 8) | s2 | MBFL_WCSPLANE_WINCP932; + w = MBFL_BAD_INPUT; } + CK((*filter->output_function)(w, filter->data)); } else { - w = (c1 << 8) | c | MBFL_WCSGROUP_THROUGH; - CK((*filter->output_function)(w, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -207,13 +208,13 @@ mbfl_filt_conv_cp932_wchar(int c, mbfl_convert_filter *filter) break; } - return c; + return 0; } static int mbfl_filt_conv_cp932_wchar_flush(mbfl_convert_filter *filter) { if (filter->status) { - (*filter->output_function)(filter->cache | MBFL_WCSGROUP_THROUGH, filter->data); + (*filter->output_function)(MBFL_BAD_INPUT, filter->data); } if (filter->flush_function) { @@ -307,5 +308,5 @@ mbfl_filt_conv_wchar_cp932(int c, mbfl_convert_filter *filter) CK(mbfl_filt_conv_illegal_output(c, filter)); } - return c; + return 0; } diff --git a/ext/mbstring/libmbfl/filters/mbfilter_cp936.c b/ext/mbstring/libmbfl/filters/mbfilter_cp936.c index c8649f97629..c53bfe42a7b 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_cp936.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_cp936.c @@ -145,20 +145,14 @@ int mbfl_filt_conv_cp936_wchar(int c, mbfl_convert_filter *filter) w = (c1 - 0x81)*192 + (c - 0x40); if (w >= 0 && w < cp936_ucs_table_size) { w = cp936_ucs_table[w]; + if (!w) + w = MBFL_BAD_INPUT; } else { - w = 0; - } - if (w <= 0) { - w = (c1 << 8) | c; - w &= MBFL_WCSPLANE_MASK; - w |= MBFL_WCSPLANE_WINCP936; + w = MBFL_BAD_INPUT; } CK((*filter->output_function)(w, filter->data)); } else { - w = (c1 << 8) | c; - w &= MBFL_WCSGROUP_MASK; - w |= MBFL_WCSGROUP_THROUGH; - CK((*filter->output_function)(w, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } } break; @@ -168,14 +162,14 @@ int mbfl_filt_conv_cp936_wchar(int c, mbfl_convert_filter *filter) break; } - return c; + return 0; } static int mbfl_filt_conv_cp936_wchar_flush(mbfl_convert_filter *filter) { if (filter->status) { /* 2-byte character was truncated */ - CK((*filter->output_function)(filter->cache | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } if (filter->flush_function) { @@ -257,17 +251,15 @@ int mbfl_filt_conv_wchar_cp936(int c, mbfl_convert_filter *filter) s = ucs_hff_s_cp936_table[c-0xffe0]; } } + if (s <= 0) { - c1 = c & ~MBFL_WCSPLANE_MASK; - if (c1 == MBFL_WCSPLANE_WINCP936) { - s = c & MBFL_WCSPLANE_MASK; - } if (c == 0) { s = 0; } else if (s <= 0) { s = -1; } } + if (s >= 0) { if (s <= 0x80 || s == 0xff) { /* latin */ CK((*filter->output_function)(s, filter->data)); @@ -279,5 +271,5 @@ int mbfl_filt_conv_wchar_cp936(int c, mbfl_convert_filter *filter) CK(mbfl_filt_conv_illegal_output(c, filter)); } - return c; + return 0; } diff --git a/ext/mbstring/libmbfl/filters/mbfilter_euc_cn.c b/ext/mbstring/libmbfl/filters/mbfilter_euc_cn.c index 5680290cb9c..ecde251b119 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_euc_cn.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_euc_cn.c @@ -100,7 +100,7 @@ int mbfl_filt_conv_euccn_wchar(int c, mbfl_convert_filter *filter) filter->status = 1; filter->cache = c; } else { - CK((*filter->output_function)(c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -122,12 +122,14 @@ int mbfl_filt_conv_euccn_wchar(int c, mbfl_convert_filter *filter) } else { w = 0; } + if (w <= 0) { - w = (c1 << 8) | c | MBFL_WCSPLANE_GB2312; + w = MBFL_BAD_INPUT; } + CK((*filter->output_function)(w, filter->data)); } else { - CK((*filter->output_function)((c1 << 8) | c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -136,7 +138,7 @@ int mbfl_filt_conv_euccn_wchar(int c, mbfl_convert_filter *filter) break; } - return c; + return 0; } int mbfl_filt_conv_wchar_euccn(int c, mbfl_convert_filter *filter) @@ -201,14 +203,14 @@ int mbfl_filt_conv_wchar_euccn(int c, mbfl_convert_filter *filter) CK(mbfl_filt_conv_illegal_output(c, filter)); } - return c; + return 0; } static int mbfl_filt_conv_euccn_wchar_flush(mbfl_convert_filter *filter) { if (filter->status == 1) { /* 2-byte character was truncated */ - CK((*filter->output_function)(filter->cache | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } if (filter->flush_function) { diff --git a/ext/mbstring/libmbfl/filters/mbfilter_euc_jp.c b/ext/mbstring/libmbfl/filters/mbfilter_euc_jp.c index e3e7dfc931a..c963716d432 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_euc_jp.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_euc_jp.c @@ -109,7 +109,7 @@ mbfl_filt_conv_eucjp_wchar(int c, mbfl_convert_filter *filter) } else if (c == 0x8f) { /* X 0212 first char */ filter->status = 3; } else { - CK((*filter->output_function)(c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -120,14 +120,15 @@ mbfl_filt_conv_eucjp_wchar(int c, mbfl_convert_filter *filter) s = (c1 - 0xa1)*94 + c - 0xa1; if (s >= 0 && s < jisx0208_ucs_table_size) { w = jisx0208_ucs_table[s]; + if (!w) + w = MBFL_BAD_INPUT; + } else { + w = MBFL_BAD_INPUT; } - if (w <= 0) { - w = ((c1 & 0x7f) << 8) | (c & 0x7f) | MBFL_WCSPLANE_JIS0208; - } + CK((*filter->output_function)(w, filter->data)); } else { - w = (c1 << 8) | c | MBFL_WCSGROUP_THROUGH; - CK((*filter->output_function)(w, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -137,8 +138,7 @@ mbfl_filt_conv_eucjp_wchar(int c, mbfl_convert_filter *filter) w = 0xfec0 + c; CK((*filter->output_function)(w, filter->data)); } else { - w = 0x8e00 | c | MBFL_WCSGROUP_THROUGH; - CK((*filter->output_function)(w, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -154,14 +154,15 @@ mbfl_filt_conv_eucjp_wchar(int c, mbfl_convert_filter *filter) s = (c1 - 0xa1)*94 + c - 0xa1; if (s >= 0 && s < jisx0212_ucs_table_size) { w = jisx0212_ucs_table[s]; + if (!w) + w = MBFL_BAD_INPUT; + } else { + w = MBFL_BAD_INPUT; } - if (w <= 0) { - w = ((c1 & 0x7f) << 8) | (c & 0x7f) | MBFL_WCSPLANE_JIS0212; - } + CK((*filter->output_function)(w, filter->data)); } else { - w = (c1 << 8) | c | 0x8f0000 | MBFL_WCSGROUP_THROUGH; - CK((*filter->output_function)(w, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -170,13 +171,13 @@ mbfl_filt_conv_eucjp_wchar(int c, mbfl_convert_filter *filter) break; } - return c; + return 0; } static int mbfl_filt_conv_eucjp_wchar_flush(mbfl_convert_filter *filter) { if (filter->status) { - (*filter->output_function)(filter->cache | MBFL_WCSGROUP_THROUGH, filter->data); + (*filter->output_function)(MBFL_BAD_INPUT, filter->data); } if (filter->flush_function) { @@ -244,5 +245,5 @@ mbfl_filt_conv_wchar_eucjp(int c, mbfl_convert_filter *filter) CK(mbfl_filt_conv_illegal_output(c, filter)); } - return c; + return 0; } diff --git a/ext/mbstring/libmbfl/filters/mbfilter_euc_jp_win.c b/ext/mbstring/libmbfl/filters/mbfilter_euc_jp_win.c index af604ac7fce..02ee1b1c59a 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_euc_jp_win.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_euc_jp_win.c @@ -106,7 +106,7 @@ int mbfl_filt_conv_eucjpwin_wchar(int c, mbfl_convert_filter *filter) } else if (c == 0x8f) { /* X 0212 first char */ filter->status = 3; } else { - CK((*filter->output_function)(c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -145,12 +145,11 @@ int mbfl_filt_conv_eucjpwin_wchar(int c, mbfl_convert_filter *filter) } if (w <= 0) { - w = ((c1 & 0x7f) << 8) | (c & 0x7f) | MBFL_WCSPLANE_WINCP932; + w = MBFL_BAD_INPUT; } CK((*filter->output_function)(w, filter->data)); } else { - w = (c1 << 8) | c | MBFL_WCSGROUP_THROUGH; - CK((*filter->output_function)(w, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -160,8 +159,7 @@ int mbfl_filt_conv_eucjpwin_wchar(int c, mbfl_convert_filter *filter) w = 0xfec0 + c; CK((*filter->output_function)(w, filter->data)); } else { - w = 0x8e00 | c | MBFL_WCSGROUP_THROUGH; - CK((*filter->output_function)(w, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -205,12 +203,11 @@ int mbfl_filt_conv_eucjpwin_wchar(int c, mbfl_convert_filter *filter) } if (w <= 0) { - w = ((c1 & 0x7f) << 8) | (c & 0x7f) | MBFL_WCSPLANE_JIS0212; + w = MBFL_BAD_INPUT; } CK((*filter->output_function)(w, filter->data)); } else { - w = (c1 << 8) | c | 0x8f0000 | MBFL_WCSGROUP_THROUGH; - CK((*filter->output_function)(w, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -219,13 +216,13 @@ int mbfl_filt_conv_eucjpwin_wchar(int c, mbfl_convert_filter *filter) break; } - return c; + return 0; } static int mbfl_filt_conv_eucjpwin_wchar_flush(mbfl_convert_filter *filter) { if (filter->status) { - (*filter->output_function)(filter->cache | MBFL_WCSGROUP_THROUGH, filter->data); + (*filter->output_function)(MBFL_BAD_INPUT, filter->data); } if (filter->flush_function) { @@ -339,5 +336,5 @@ int mbfl_filt_conv_wchar_eucjpwin(int c, mbfl_convert_filter *filter) CK(mbfl_filt_conv_illegal_output(c, filter)); } - return c; + return 0; } diff --git a/ext/mbstring/libmbfl/filters/mbfilter_euc_kr.c b/ext/mbstring/libmbfl/filters/mbfilter_euc_kr.c index a40897f7bb0..a824909f05c 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_euc_kr.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_euc_kr.c @@ -99,7 +99,7 @@ int mbfl_filt_conv_euckr_wchar(int c, mbfl_convert_filter *filter) filter->status = 1; filter->cache = c; } else { - CK((*filter->output_function)(c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -130,11 +130,11 @@ int mbfl_filt_conv_euckr_wchar(int c, mbfl_convert_filter *filter) } if (w <= 0) { - w = (c1 << 8) | c | MBFL_WCSPLANE_KSC5601; + w = MBFL_BAD_INPUT; } CK((*filter->output_function)(w, filter->data)); } else { - CK((*filter->output_function)((c1 << 8) | c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -143,7 +143,7 @@ int mbfl_filt_conv_euckr_wchar(int c, mbfl_convert_filter *filter) break; } - return c; + return 0; } int mbfl_filt_conv_wchar_euckr(int c, mbfl_convert_filter *filter) @@ -190,14 +190,14 @@ int mbfl_filt_conv_wchar_euckr(int c, mbfl_convert_filter *filter) CK(mbfl_filt_conv_illegal_output(c, filter)); } - return c; + return 0; } static int mbfl_filt_conv_euckr_wchar_flush(mbfl_convert_filter *filter) { if (filter->status == 1) { /* 2-byte character was truncated */ - CK((*filter->output_function)(filter->cache | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } if (filter->flush_function) { diff --git a/ext/mbstring/libmbfl/filters/mbfilter_euc_tw.c b/ext/mbstring/libmbfl/filters/mbfilter_euc_tw.c index 0c202ddb178..187ac8ad9d5 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_euc_tw.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_euc_tw.c @@ -103,7 +103,7 @@ int mbfl_filt_conv_euctw_wchar(int c, mbfl_convert_filter *filter) } else if (c == 0x8E) { /* 4-byte character, first byte */ filter->status = 2; } else { - CK((*filter->output_function)(c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -117,14 +117,15 @@ int mbfl_filt_conv_euctw_wchar(int c, mbfl_convert_filter *filter) } else { w = 0; } + if (w <= 0) { - w = (c1 << 8) | c | MBFL_WCSPLANE_CNS11643; + w = MBFL_BAD_INPUT; } + CK((*filter->output_function)(w, filter->data)); } else { filter->status = filter->cache = 0; - w = (c1 << 8) | c | MBFL_WCSGROUP_THROUGH; - CK((*filter->output_function)(w, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -134,8 +135,7 @@ int mbfl_filt_conv_euctw_wchar(int c, mbfl_convert_filter *filter) filter->cache = c - 0xA1; } else { filter->status = filter->cache = 0; - w = 0x8E00 | c | MBFL_WCSGROUP_THROUGH; - CK((*filter->output_function)(w, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -148,8 +148,7 @@ int mbfl_filt_conv_euctw_wchar(int c, mbfl_convert_filter *filter) filter->cache = (c1 << 8) + c - 0xA1; } else { filter->status = filter->cache = 0; - w = 0x8E0000 | ((c1 + 0xA1) << 8) | c | MBFL_WCSGROUP_THROUGH; - CK((*filter->output_function)(w, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -173,14 +172,15 @@ int mbfl_filt_conv_euctw_wchar(int c, mbfl_convert_filter *filter) w = cns11643_14_ucs_table[s]; } } + if (w <= 0) { - w = ((c1 & 0x7F) << 8) | (c & 0x7F) | MBFL_WCSPLANE_CNS11643; + w = MBFL_BAD_INPUT; } + CK((*filter->output_function)(w, filter->data)); } else { filter->status = filter->cache = 0; - w = ((c1 + 0xA1A1) << 8) | c | MBFL_WCSGROUP_THROUGH; - CK((*filter->output_function)(w, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -189,7 +189,7 @@ int mbfl_filt_conv_euctw_wchar(int c, mbfl_convert_filter *filter) break; } - return c; + return 0; } int mbfl_filt_conv_wchar_euctw(int c, mbfl_convert_filter *filter) @@ -236,14 +236,14 @@ int mbfl_filt_conv_wchar_euctw(int c, mbfl_convert_filter *filter) } else { CK(mbfl_filt_conv_illegal_output(c, filter)); } - return c; + return 0; } static int mbfl_filt_conv_euctw_wchar_flush(mbfl_convert_filter *filter) { if (filter->status) { /* 2-byte or 4-byte character was truncated */ - CK((*filter->output_function)(filter->cache | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } if (filter->flush_function) { diff --git a/ext/mbstring/libmbfl/filters/mbfilter_gb18030.c b/ext/mbstring/libmbfl/filters/mbfilter_gb18030.c index 7c26929687b..5ab2bc15af6 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_gb18030.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_gb18030.c @@ -119,7 +119,7 @@ int mbfl_filt_conv_gb18030_wchar(int c, mbfl_convert_filter *filter) filter->status = 1; filter->cache = c; } else { - CK((*filter->output_function)(c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -131,12 +131,12 @@ int mbfl_filt_conv_gb18030_wchar(int c, mbfl_convert_filter *filter) /* 4 byte range: Unicode BMP */ filter->status = 2; filter->cache = (c1 << 8) | c; - return c; + return 0; } else if (c1 >= 0x90 && c1 <= 0xe3 && c >= 0x30 && c <= 0x39) { /* 4 byte range: Unicode 16 planes */ filter->status = 2; filter->cache = (c1 << 8) | c; - return c; + return 0; } else if (((c1 >= 0xaa && c1 <= 0xaf) || (c1 >= 0xf8 && c1 <= 0xfe)) && (c >= 0xa1 && c <= 0xfe)) { /* UDA part 1,2: U+E000-U+E4C5 */ w = 94*(c1 >= 0xf8 ? c1 - 0xf2 : c1 - 0xaa) + (c - 0xa1) + 0xe000; @@ -171,16 +171,14 @@ int mbfl_filt_conv_gb18030_wchar(int c, mbfl_convert_filter *filter) w = (c1 - 0x81)*192 + (c - 0x40); if (w >= 0 && w < cp936_ucs_table_size) { w = cp936_ucs_table[w]; + if (!w) + w = MBFL_BAD_INPUT; } else { - w = 0; - } - if (w <= 0) { - w = (c1 << 8) | c | MBFL_WCSPLANE_GB18030; + w = MBFL_BAD_INPUT; } CK((*filter->output_function)(w, filter->data)); } else { - w = (c1 << 8) | c | MBFL_WCSGROUP_THROUGH; - CK((*filter->output_function)(w, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } } break; @@ -193,8 +191,7 @@ int mbfl_filt_conv_gb18030_wchar(int c, mbfl_convert_filter *filter) filter->cache = (c1 << 16) | (c2 << 8) | c; filter->status = 3; } else { - w = (c1 << 16) | (c2 << 8) | c | MBFL_WCSGROUP_THROUGH; - CK((*filter->output_function)(w, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -207,37 +204,26 @@ int mbfl_filt_conv_gb18030_wchar(int c, mbfl_convert_filter *filter) if (c1 >= 0x90 && c1 <= 0xe3) { w = ((((c1 - 0x90)*10 + (c2 - 0x30))*126 + (c3 - 0x81)))*10 + (c - 0x30) + 0x10000; if (w > 0x10FFFF) { - w = ((c1 & 0x7F) << 24) | (c2 << 16) | (c3 << 8) | c; - CK((*filter->output_function)(w | MBFL_WCSGROUP_THROUGH, filter->data)); - return c; + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); + return 0; } } else { /* Unicode BMP */ w = (((c1 - 0x81)*10 + (c2 - 0x30))*126 + (c3 - 0x81))*10 + (c - 0x30); if (w >= 0 && w <= 39419) { k = mbfl_bisec_srch(w, mbfl_gb2uni_tbl, mbfl_gb_uni_max); if (k < 0) { - /* error */ - w = ((c1 & 0x7F) << 24) | (c2 << 16) | (c3 << 8) | c; - w &= MBFL_WCSGROUP_MASK; - w |= MBFL_WCSGROUP_THROUGH; - CK((*filter->output_function)(w, filter->data)); - return c; + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); + return 0; } w += mbfl_gb_uni_ofst[k]; } else { - w = ((c1 & 0x7F) << 24) | (c2 << 16) | (c3 << 8) | c; - w &= MBFL_WCSGROUP_MASK; - w |= MBFL_WCSGROUP_THROUGH; - CK((*filter->output_function)(w, filter->data)); - return c; + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); + return 0; } } CK((*filter->output_function)(w, filter->data)); } else { - w = ((c1 & 0x7F) << 24) | (c2 << 16) | (c3 << 8) | c; - w &= MBFL_WCSGROUP_MASK; - w |= MBFL_WCSGROUP_THROUGH; - CK((*filter->output_function)(w, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -246,14 +232,14 @@ int mbfl_filt_conv_gb18030_wchar(int c, mbfl_convert_filter *filter) break; } - return c; + return 0; } static int mbfl_filt_conv_gb18030_wchar_flush(mbfl_convert_filter *filter) { if (filter->status) { /* multi-byte character was truncated */ - CK((*filter->output_function)(filter->cache | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } if (filter->flush_function) { @@ -408,5 +394,5 @@ int mbfl_filt_conv_wchar_gb18030(int c, mbfl_convert_filter *filter) CK(mbfl_filt_conv_illegal_output(c, filter)); } - return c; + return 0; } diff --git a/ext/mbstring/libmbfl/filters/mbfilter_htmlent.c b/ext/mbstring/libmbfl/filters/mbfilter_htmlent.c index 95a08171036..3a7e879ceaa 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_htmlent.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_htmlent.c @@ -133,7 +133,7 @@ int mbfl_filt_conv_html_enc(int c, mbfl_convert_filter *filter) last: CK((*filter->output_function)(';', filter->data)); } - return c; + return 0; } int mbfl_filt_conv_html_enc_flush(mbfl_convert_filter *filter) @@ -276,7 +276,7 @@ int mbfl_filt_conv_html_dec(int c, mbfl_convert_filter *filter) } } } - return c; + return 0; } int mbfl_filt_conv_html_dec_flush(mbfl_convert_filter *filter) diff --git a/ext/mbstring/libmbfl/filters/mbfilter_hz.c b/ext/mbstring/libmbfl/filters/mbfilter_hz.c index 4baabea5990..14edf64a7bb 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_hz.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_hz.c @@ -85,7 +85,7 @@ int mbfl_filt_conv_hz_wchar(int c, mbfl_convert_filter *filter) } else if (filter->status == 0 && c >= 0 && c < 0x80) { /* latin, CTLs */ CK((*filter->output_function)(c, filter->data)); } else { - CK((*filter->output_function)(c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -110,13 +110,14 @@ int mbfl_filt_conv_hz_wchar(int c, mbfl_convert_filter *filter) } else { w = 0; } + if (w <= 0) { - w = (c1 << 8) | c | MBFL_WCSPLANE_GB2312; + w = MBFL_BAD_INPUT; } + CK((*filter->output_function)(w, filter->data)); } else { - w = (c1 << 8) | c | MBFL_WCSGROUP_THROUGH; - CK((*filter->output_function)(w, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -134,7 +135,7 @@ int mbfl_filt_conv_hz_wchar(int c, mbfl_convert_filter *filter) } else { /* Invalid character after ~ */ filter->status -= 2; - CK((*filter->output_function)(c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -143,14 +144,14 @@ int mbfl_filt_conv_hz_wchar(int c, mbfl_convert_filter *filter) break; } - return c; + return 0; } static int mbfl_filt_conv_hz_wchar_flush(mbfl_convert_filter *filter) { if (filter->status == 0x11) { /* 2-byte character was truncated */ - CK((*filter->output_function)(filter->cache | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } if (filter->flush_function) { @@ -239,7 +240,7 @@ int mbfl_filt_conv_wchar_hz(int c, mbfl_convert_filter *filter) CK(mbfl_filt_conv_illegal_output(c, filter)); } - return c; + return 0; } int mbfl_filt_conv_any_hz_flush(mbfl_convert_filter *filter) diff --git a/ext/mbstring/libmbfl/filters/mbfilter_iso2022_jp_ms.c b/ext/mbstring/libmbfl/filters/mbfilter_iso2022_jp_ms.c index 7d3a27d4eef..cc7cd90a1d5 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_iso2022_jp_ms.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_iso2022_jp_ms.c @@ -100,7 +100,7 @@ int mbfl_filt_conv_2022jpms_wchar(int c, mbfl_convert_filter *filter) } else if (c > 0xA0 && c < 0xE0) { /* Kana */ CK((*filter->output_function)(0xFEC0 + c, filter->data)); } else { - CK((*filter->output_function)(c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -141,18 +141,18 @@ int mbfl_filt_conv_2022jpms_wchar(int c, mbfl_convert_filter *filter) } if (w <= 0) { - w = (c1 << 8) | c | MBFL_WCSPLANE_JIS0208; + w = MBFL_BAD_INPUT; } } else { if (c1 > 0x20 && c1 < 0x35) { w = 0xE000 + ((c1 - 0x21) * 94) + c - 0x21; } else { - w = (((c1 - 0x21) + 0x7f) << 8) | c | MBFL_WCSPLANE_JIS0208; + w = MBFL_BAD_INPUT; } } CK((*filter->output_function)(w, filter->data)); } else { - CK((*filter->output_function)((c1 << 8) | c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -164,7 +164,7 @@ int mbfl_filt_conv_2022jpms_wchar(int c, mbfl_convert_filter *filter) filter->status += 3; } else { filter->status &= ~0xF; - CK((*filter->output_function)(0x1B00 | c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -176,7 +176,7 @@ int mbfl_filt_conv_2022jpms_wchar(int c, mbfl_convert_filter *filter) filter->status++; } else { filter->status &= ~0xF; - CK((*filter->output_function)(0x1B2400 | c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -188,7 +188,7 @@ int mbfl_filt_conv_2022jpms_wchar(int c, mbfl_convert_filter *filter) filter->status = UDC; } else { filter->status &= ~0xF; - CK((*filter->output_function)(0x1B242800 | c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -200,28 +200,18 @@ int mbfl_filt_conv_2022jpms_wchar(int c, mbfl_convert_filter *filter) filter->status = JISX0201_KANA; } else { filter->status &= ~0xF; - CK((*filter->output_function)(0x1B2800 | c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } } - return c; + return 0; } static int mbfl_filt_conv_2022jpms_wchar_flush(mbfl_convert_filter *filter) { if (filter->status & 0xF) { - if ((filter->status & 0xF) == 2) { - (*filter->output_function)(0x1B | MBFL_WCSGROUP_THROUGH, filter->data); - } else if ((filter->status & 0xF) == 3) { - (*filter->output_function)(0x1B24 | MBFL_WCSGROUP_THROUGH, filter->data); - } else if ((filter->status & 0xF) == 4) { - (*filter->output_function)(0x1B2428 | MBFL_WCSGROUP_THROUGH, filter->data); - } else if ((filter->status & 0xF) == 5) { - (*filter->output_function)(0x1B28 | MBFL_WCSGROUP_THROUGH, filter->data); - } else { - (*filter->output_function)(filter->cache | MBFL_WCSGROUP_THROUGH, filter->data); - } + (*filter->output_function)(MBFL_BAD_INPUT, filter->data); } if (filter->flush_function) { @@ -351,7 +341,7 @@ int mbfl_filt_conv_wchar_2022jpms(int c, mbfl_convert_filter *filter) CK(mbfl_filt_conv_illegal_output(c, filter)); } - return c; + return 0; } int mbfl_filt_conv_any_2022jpms_flush(mbfl_convert_filter *filter) diff --git a/ext/mbstring/libmbfl/filters/mbfilter_iso2022_kr.c b/ext/mbstring/libmbfl/filters/mbfilter_iso2022_kr.c index 3c08e97896b..ba1177a2ea9 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_iso2022_kr.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_iso2022_kr.c @@ -94,7 +94,7 @@ int mbfl_filt_conv_2022kr_wchar(int c, mbfl_convert_filter *filter) /* latin, CTLs */ CK((*filter->output_function)(c, filter->data)); } else { - CK((*filter->output_function)(c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -129,12 +129,11 @@ int mbfl_filt_conv_2022kr_wchar(int c, mbfl_convert_filter *filter) } if (w <= 0) { - w = (c1 << 8) | c | MBFL_WCSPLANE_KSC5601; + w = MBFL_BAD_INPUT; } CK((*filter->output_function)(w, filter->data)); } else { - w = (c1 << 8) | c | MBFL_WCSGROUP_THROUGH; - CK((*filter->output_function)(w, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -143,7 +142,7 @@ int mbfl_filt_conv_2022kr_wchar(int c, mbfl_convert_filter *filter) filter->status++; } else { filter->status = 0; - CK((*filter->output_function)(0x1b | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -152,14 +151,14 @@ int mbfl_filt_conv_2022kr_wchar(int c, mbfl_convert_filter *filter) filter->status++; } else { filter->status = 0; - CK((*filter->output_function)(0x1b24 | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; case 4: /* ESC $ ) */ filter->status = 0; if (c != 'C') { - CK((*filter->output_function)(0x1b2429 | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -168,22 +167,14 @@ int mbfl_filt_conv_2022kr_wchar(int c, mbfl_convert_filter *filter) break; } - return c; + return 0; } static int mbfl_filt_conv_2022kr_wchar_flush(mbfl_convert_filter *filter) { if (filter->status & 0xF) { - if (filter->status == 2) { - CK((*filter->output_function)(0x1B | MBFL_WCSGROUP_THROUGH, filter->data)); - } else if (filter->status == 3) { - CK((*filter->output_function)(0x1B24 | MBFL_WCSGROUP_THROUGH, filter->data)); - } else if (filter->status == 4) { - CK((*filter->output_function)(0x1B2429 | MBFL_WCSGROUP_THROUGH, filter->data)); - } else { - /* 2-byte character was truncated */ - CK((*filter->output_function)(filter->cache | MBFL_WCSGROUP_THROUGH, filter->data)); - } + /* 2-byte character was truncated */ + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } if (filter->flush_function) { @@ -260,7 +251,7 @@ int mbfl_filt_conv_wchar_2022kr(int c, mbfl_convert_filter *filter) CK(mbfl_filt_conv_illegal_output(c, filter)); } - return c; + return 0; } static int mbfl_filt_conv_any_2022kr_flush(mbfl_convert_filter *filter) diff --git a/ext/mbstring/libmbfl/filters/mbfilter_iso2022jp_mobile.c b/ext/mbstring/libmbfl/filters/mbfilter_iso2022jp_mobile.c index 74abb474590..febfd84ddc5 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_iso2022jp_mobile.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_iso2022jp_mobile.c @@ -134,7 +134,7 @@ int mbfl_filt_conv_2022jp_mobile_wchar(int c, mbfl_convert_filter *filter) } else if (c > 0xA0 && c < 0xE0) { /* Kana */ CK((*filter->output_function)(0xFEC0 + c, filter->data)); } else { - CK((*filter->output_function)(c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -181,11 +181,11 @@ int mbfl_filt_conv_2022jp_mobile_wchar(int c, mbfl_convert_filter *filter) } if (w <= 0) { - w = (c1 << 8) | c | MBFL_WCSPLANE_JIS0208; + w = MBFL_BAD_INPUT; } CK((*filter->output_function)(w, filter->data)); } else { - CK((*filter->output_function)((c1 << 8) | c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -197,7 +197,7 @@ int mbfl_filt_conv_2022jp_mobile_wchar(int c, mbfl_convert_filter *filter) filter->status += 3; } else { filter->status &= ~0xF; - CK((*filter->output_function)(0x1B00 | c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -209,7 +209,7 @@ int mbfl_filt_conv_2022jp_mobile_wchar(int c, mbfl_convert_filter *filter) filter->status++; } else { filter->status &= ~0xF; - CK((*filter->output_function)(0x1B2400 | c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -219,7 +219,7 @@ int mbfl_filt_conv_2022jp_mobile_wchar(int c, mbfl_convert_filter *filter) filter->status = JISX0208_KANJI; } else { filter->status &= ~0xF; - CK((*filter->output_function)(0x1B242800 | c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -231,23 +231,17 @@ int mbfl_filt_conv_2022jp_mobile_wchar(int c, mbfl_convert_filter *filter) filter->status = JISX0201_KANA; } else { filter->status &= ~0xF; - CK((*filter->output_function)(0x1B2800 | c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } } - return c; + return 0; } static int mbfl_filt_conv_2022jp_mobile_wchar_flush(mbfl_convert_filter *filter) { if (filter->status & 0xF) { - if ((filter->status & 0xF) == 2) { - (*filter->output_function)(0x1B | MBFL_WCSGROUP_THROUGH, filter->data); - } else if ((filter->status & 0xF) == 3) { - (*filter->output_function)(0x1B24 | MBFL_WCSGROUP_THROUGH, filter->data); - } else { - (*filter->output_function)(filter->cache | MBFL_WCSGROUP_THROUGH, filter->data); - } + (*filter->output_function)(MBFL_BAD_INPUT, filter->data); } if (filter->flush_function) { @@ -300,7 +294,7 @@ int mbfl_filt_conv_wchar_2022jp_mobile(int c, mbfl_convert_filter *filter) if (filter->status == 1 && filter->cache) { /* We are just processing one of KDDI's special emoji for a phone keypad button */ - return c; + return 0; } if ((s1 <= 0) || (s1 >= 0xa1a1 && s2 == 0)) { /* not found or X 0212 */ @@ -348,7 +342,7 @@ int mbfl_filt_conv_wchar_2022jp_mobile(int c, mbfl_convert_filter *filter) CK(mbfl_filt_conv_illegal_output(c, filter)); } - return c; + return 0; } static int mbfl_filt_conv_wchar_2022jp_mobile_flush(mbfl_convert_filter *filter) diff --git a/ext/mbstring/libmbfl/filters/mbfilter_jis.c b/ext/mbstring/libmbfl/filters/mbfilter_jis.c index 969f6b37d83..6d876bbdfad 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_jis.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_jis.c @@ -135,9 +135,7 @@ retry: } else if (c > 0xa0 && c < 0xe0) { /* GR kana */ CK((*filter->output_function)(0xfec0 + c, filter->data)); } else { - w = c & MBFL_WCSGROUP_MASK; - w |= MBFL_WCSGROUP_THROUGH; - CK((*filter->output_function)(w, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -154,8 +152,9 @@ retry: } else { w = 0; } + if (w <= 0) { - w = (c1 << 8) | c | MBFL_WCSPLANE_JIS0208; + w = MBFL_BAD_INPUT; } } else { if (s >= 0 && s < jisx0212_ucs_table_size) { @@ -163,14 +162,14 @@ retry: } else { w = 0; } + if (w <= 0) { - w = (c1 << 8) | c | MBFL_WCSPLANE_JIS0212; + w = MBFL_BAD_INPUT; } } CK((*filter->output_function)(w, filter->data)); } else { - w = (c1 << 8) | c | MBFL_WCSGROUP_THROUGH; - CK((*filter->output_function)(w, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -187,7 +186,7 @@ retry: filter->status += 3; } else { filter->status &= ~0xf; - CK((*filter->output_function)(0x1b | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); goto retry; } break; @@ -205,7 +204,7 @@ retry: filter->status++; } else { filter->status &= ~0xf; - CK((*filter->output_function)(0x1b | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); CK((*filter->output_function)(0x24, filter->data)); goto retry; } @@ -224,7 +223,7 @@ retry: filter->status = 0x90; } else { filter->status &= ~0xf; - CK((*filter->output_function)(0x1b | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); CK((*filter->output_function)(0x24, filter->data)); CK((*filter->output_function)(0x28, filter->data)); goto retry; @@ -246,7 +245,7 @@ retry: filter->status = 0x20; } else { filter->status &= ~0xf; - CK((*filter->output_function)(0x1b | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); CK((*filter->output_function)(0x28, filter->data)); goto retry; } @@ -257,14 +256,14 @@ retry: break; } - return c; + return 0; } 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)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } return 0; } @@ -359,7 +358,7 @@ mbfl_filt_conv_wchar_jis(int c, mbfl_convert_filter *filter) CK(mbfl_filt_conv_illegal_output(c, filter)); } - return c; + return 0; } @@ -438,7 +437,7 @@ mbfl_filt_conv_wchar_2022jp(int c, mbfl_convert_filter *filter) CK(mbfl_filt_conv_illegal_output(c, filter)); } - return c; + return 0; } int diff --git a/ext/mbstring/libmbfl/filters/mbfilter_qprint.c b/ext/mbstring/libmbfl/filters/mbfilter_qprint.c index 8f806def258..2c9e8234872 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_qprint.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_qprint.c @@ -139,7 +139,7 @@ int mbfl_filt_conv_qprintenc(int c, mbfl_convert_filter *filter) break; } - return c; + return 0; } int mbfl_filt_conv_qprintenc_flush(mbfl_convert_filter *filter) @@ -219,7 +219,7 @@ int mbfl_filt_conv_qprintdec(int c, mbfl_convert_filter *filter) break; } - return c; + return 0; } int mbfl_filt_conv_qprintdec_flush(mbfl_convert_filter *filter) diff --git a/ext/mbstring/libmbfl/filters/mbfilter_singlebyte.c b/ext/mbstring/libmbfl/filters/mbfilter_singlebyte.c index bdb6cb8408e..43ab8a2e487 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_singlebyte.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_singlebyte.c @@ -23,28 +23,29 @@ static int mbfl_conv_singlebyte_table(int c, mbfl_convert_filter *filter, int tb CK((*filter->output_function)(c, filter->data)); } else { int s = tbl[c - tbl_min]; - if (!s) { - s = c | MBFL_WCSGROUP_THROUGH; - } + if (!s) + s = MBFL_BAD_INPUT; CK((*filter->output_function)(s, filter->data)); } - return c; + return 0; } static int mbfl_conv_reverselookup_table(int c, mbfl_convert_filter *filter, int tbl_min, const unsigned short tbl[]) { - if (c < tbl_min) { + if (c == MBFL_BAD_INPUT) { + CK(mbfl_filt_conv_illegal_output(c, filter)); + } else if (c < tbl_min) { CK((*filter->output_function)(c, filter->data)); } else { for (int i = 0; i < 256 - tbl_min; i++) { if (c == tbl[i]) { CK((*filter->output_function)(i + tbl_min, filter->data)); - return c; + return 0; } } CK(mbfl_filt_conv_illegal_output(c, filter)); } - return c; + return 0; } /* Initialize data structures for a single-byte encoding */ @@ -99,19 +100,19 @@ static int mbfl_filt_conv_ascii_wchar(int c, mbfl_convert_filter *filter) if (c < 0x80) { CK((*filter->output_function)(c, filter->data)); } else { - CK((*filter->output_function)(c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } - return c; + return 0; } static int mbfl_filt_conv_wchar_ascii(int c, mbfl_convert_filter *filter) { - if (c < 0x80) { + if (c < 0x80 && c != MBFL_BAD_INPUT) { CK((*filter->output_function)(c, filter->data)); } else { CK(mbfl_filt_conv_illegal_output(c, filter)); } - return c; + return 0; } /* ISO-8859-X */ @@ -126,12 +127,12 @@ static int mbfl_filt_conv_8859_1_wchar(int c, mbfl_convert_filter *filter) static int mbfl_filt_conv_wchar_8859_1(int c, mbfl_convert_filter *filter) { - if (c < 0x100) { + if (c < 0x100 && c != MBFL_BAD_INPUT) { CK((*filter->output_function)(c, filter->data)); } else { CK(mbfl_filt_conv_illegal_output(c, filter)); } - return c; + return 0; } static const char *iso8859_2_aliases[] = {"ISO8859-2", "latin2", NULL}; @@ -391,16 +392,16 @@ static int mbfl_filt_conv_wchar_cp1252(int c, mbfl_convert_filter *filter) for (int n = 0; n < 32; n++) { if (c == cp1252_ucs_table[n]) { CK((*filter->output_function)(0x80 + n, filter->data)); - return c; + return 0; } } CK(mbfl_filt_conv_illegal_output(c, filter)); - } else if (c <= 0x7F || c >= 0xA0) { + } else if ((c <= 0x7F || c >= 0xA0) && c != MBFL_BAD_INPUT) { CK((*filter->output_function)(c, filter->data)); } else { CK(mbfl_filt_conv_illegal_output(c, filter)); } - return c; + return 0; } static int mbfl_filt_conv_cp1252_wchar(int c, mbfl_convert_filter *filter) @@ -409,15 +410,14 @@ static int mbfl_filt_conv_cp1252_wchar(int c, mbfl_convert_filter *filter) if (c >= 0x80 && c < 0xA0) { s = cp1252_ucs_table[c - 0x80]; - if (!s) { - s = c | MBFL_WCSGROUP_THROUGH; - } + if (!s) + s = MBFL_BAD_INPUT; } else { s = c; } CK((*filter->output_function)(s, filter->data)); - return c; + return 0; } static const char *cp1254_aliases[] = {"CP1254", "CP-1254", "WINDOWS-1254", NULL}; @@ -553,29 +553,30 @@ static int mbfl_filt_conv_armscii8_wchar(int c, mbfl_convert_filter *filter) s = c; } else { s = armscii8_ucs_table[c - 0xA0]; - if (!s) { - s = c | MBFL_WCSGROUP_THROUGH; - } + if (!s) + s = MBFL_BAD_INPUT; } CK((*filter->output_function)(s, filter->data)); - return c; + return 0; } static int mbfl_filt_conv_wchar_armscii8(int c, mbfl_convert_filter *filter) { if (c >= 0x28 && c <= 0x2F) { CK((*filter->output_function)(ucs_armscii8_table[c - 0x28], filter->data)); + } else if (c == MBFL_BAD_INPUT) { + CK(mbfl_filt_conv_illegal_output(c, filter)); } else if (c < 0xA0) { CK((*filter->output_function)(c, filter->data)); } else { for (int n = 0; n < 0x60; n++) { if (c == armscii8_ucs_table[n]) { CK((*filter->output_function)(0xA0 + n, filter->data)); - return c; + return 0; } } CK(mbfl_filt_conv_illegal_output(c, filter)); } - return c; + return 0; } diff --git a/ext/mbstring/libmbfl/filters/mbfilter_sjis.c b/ext/mbstring/libmbfl/filters/mbfilter_sjis.c index e175f8dbfbb..188f162bf87 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_sjis.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_sjis.c @@ -153,7 +153,7 @@ int mbfl_filt_conv_sjis_wchar(int c, mbfl_convert_filter *filter) filter->status = 1; filter->cache = c; } else { - CK((*filter->output_function)(c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -165,30 +165,24 @@ int mbfl_filt_conv_sjis_wchar(int c, mbfl_convert_filter *filter) w = (s1 - 0x21)*94 + s2 - 0x21; if (w >= 0 && w < jisx0208_ucs_table_size) { w = jisx0208_ucs_table[w]; + if (!w) + w = MBFL_BAD_INPUT; } else { - w = 0; - } - if (w <= 0) { - if (s1 < 0x7F && s2 < 0x7F) { - w = (s1 << 8) | s2 | MBFL_WCSPLANE_JIS0208; - } else { - w = (c1 << 8) | c | MBFL_WCSGROUP_THROUGH; - } + w = MBFL_BAD_INPUT; } CK((*filter->output_function)(w, filter->data)); } else { - w = (c1 << 8) | c | MBFL_WCSGROUP_THROUGH; - CK((*filter->output_function)(w, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } } - return c; + return 0; } static int mbfl_filt_conv_sjis_wchar_flush(mbfl_convert_filter *filter) { if (filter->status) { - mbfl_filt_conv_illegal_output(filter->cache, filter); + (*filter->output_function)(MBFL_BAD_INPUT, filter->data); } if (filter->flush_function) { @@ -262,5 +256,5 @@ int mbfl_filt_conv_wchar_sjis(int c, mbfl_convert_filter *filter) CK(mbfl_filt_conv_illegal_output(c, filter)); } - return c; + return 0; } diff --git a/ext/mbstring/libmbfl/filters/mbfilter_sjis_2004.c b/ext/mbstring/libmbfl/filters/mbfilter_sjis_2004.c index b9c93bda543..a1d94693e8f 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_sjis_2004.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_sjis_2004.c @@ -162,7 +162,7 @@ int mbfl_filt_conv_jis2004_wchar(int c, mbfl_convert_filter *filter) } else if (c == 0x8f) { /* X 0213 plane 2 first char */ filter->status = 3; } else { - CK((*filter->output_function)(c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } } else if (filter->from->no_encoding == mbfl_no_encoding_sjis2004) { if (c > 0xa0 && c < 0xe0) { /* kana */ @@ -171,10 +171,10 @@ int mbfl_filt_conv_jis2004_wchar(int c, mbfl_convert_filter *filter) filter->status = 1; filter->cache = c; } else { - CK((*filter->output_function)(c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } } else { - CK((*filter->output_function)(c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } } break; @@ -188,14 +188,14 @@ int mbfl_filt_conv_jis2004_wchar(int c, mbfl_convert_filter *filter) s1 = c1 - 0x80; s2 = c - 0x80; } else { - CK((*filter->output_function)((c1 << 8) | c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); break; } } else if (filter->from->no_encoding == mbfl_no_encoding_sjis2004) { if (c >= 0x40 && c <= 0xfc && c != 0x7f) { SJIS_DECODE(c1, c, s1, s2); } else { - CK((*filter->output_function)((c1 << 8) | c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); break; } } else { /* ISO-2022-JP-2004 */ @@ -203,7 +203,7 @@ int mbfl_filt_conv_jis2004_wchar(int c, mbfl_convert_filter *filter) s1 = c1; s2 = c; } else { - CK((*filter->output_function)((c1 << 8) | c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); break; } } @@ -240,16 +240,11 @@ int mbfl_filt_conv_jis2004_wchar(int c, mbfl_convert_filter *filter) } if (w <= 0) { - if (s1 < 0x7f && s2 < 0x7f) { - w = (s1 << 8) | s2 | MBFL_WCSPLANE_JIS0213; - } else { - w = (c1 << 8) | c | MBFL_WCSGROUP_THROUGH; - } + w = MBFL_BAD_INPUT; } CK((*filter->output_function)(w, filter->data)); } else { - w = (c1 << 8) | c | MBFL_WCSGROUP_THROUGH; - CK((*filter->output_function)(w, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -259,8 +254,7 @@ int mbfl_filt_conv_jis2004_wchar(int c, mbfl_convert_filter *filter) w = 0xfec0 + c; CK((*filter->output_function)(w, filter->data)); } else { - w = 0x8e00 | c | MBFL_WCSGROUP_THROUGH; - CK((*filter->output_function)(w, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -270,8 +264,7 @@ int mbfl_filt_conv_jis2004_wchar(int c, mbfl_convert_filter *filter) filter->status++; } else { filter->status = 0; - w = c | 0x8f00 | MBFL_WCSGROUP_THROUGH; - CK((*filter->output_function)(w, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -285,8 +278,7 @@ int mbfl_filt_conv_jis2004_wchar(int c, mbfl_convert_filter *filter) } if (c2 < 0x21 || c2 > 0x7E) { - w = (c1 << 8) | c | MBFL_WCSGROUP_THROUGH; - CK((*filter->output_function)(w, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); break; } @@ -321,17 +313,12 @@ int mbfl_filt_conv_jis2004_wchar(int c, mbfl_convert_filter *filter) } if (w <= 0) { - w = ((c1 & 0x7f) << 8) | (c2 & 0x7f) | MBFL_WCSPLANE_JIS0213; + w = MBFL_BAD_INPUT; } CK((*filter->output_function)(w, filter->data)); } else { - if (filter->to->no_encoding == mbfl_no_encoding_eucjp2004) { - w = (c1 << 8) | c | 0x8f0000 | MBFL_WCSGROUP_THROUGH; - } else { - w = ((c1 & 0x7f) << 8) | (c2 & 0x7f) | MBFL_WCSPLANE_JIS0213; - } - CK((*filter->output_function)(w, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -344,9 +331,11 @@ int mbfl_filt_conv_jis2004_wchar(int c, mbfl_convert_filter *filter) w = jisx0208_ucs_table[s]; } } + if (w <= 0) { - w = (c1 << 8) | c | MBFL_WCSPLANE_JIS0208; + w = MBFL_BAD_INPUT; } + CK((*filter->output_function)(w, filter->data)); break; @@ -364,7 +353,7 @@ int mbfl_filt_conv_jis2004_wchar(int c, mbfl_convert_filter *filter) filter->status += 3; } else { filter->status &= ~0xf; - CK((*filter->output_function)(0x1b | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -382,7 +371,7 @@ int mbfl_filt_conv_jis2004_wchar(int c, mbfl_convert_filter *filter) filter->status++; } else { filter->status &= ~0xf; - CK((*filter->output_function)(0x1b24 | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -400,7 +389,7 @@ int mbfl_filt_conv_jis2004_wchar(int c, mbfl_convert_filter *filter) filter->status = 0xa0; } else { filter->status &= ~0xf; - CK((*filter->output_function)(0x1b2428 | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -415,7 +404,7 @@ int mbfl_filt_conv_jis2004_wchar(int c, mbfl_convert_filter *filter) filter->status = 0; } else { filter->status &= ~0xf; - CK((*filter->output_function)(0x1b28 | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -424,13 +413,13 @@ int mbfl_filt_conv_jis2004_wchar(int c, mbfl_convert_filter *filter) break; } - return c; + return 0; } int mbfl_filt_conv_jis2004_wchar_flush(mbfl_convert_filter *filter) { if (filter->status & 0xF) { - CK((*filter->output_function)(filter->cache | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } return 0; } @@ -453,7 +442,7 @@ retry: if (c == jisx0213_u2_tbl[2*k]) { filter->status++; filter->cache = k; - return c; + return 0; } } } @@ -626,7 +615,7 @@ retry: CK(mbfl_filt_conv_illegal_output(c, filter)); } - return c; + return 0; } int mbfl_filt_conv_wchar_jis2004_flush(mbfl_convert_filter *filter) diff --git a/ext/mbstring/libmbfl/filters/mbfilter_sjis_mac.c b/ext/mbstring/libmbfl/filters/mbfilter_sjis_mac.c index 592f889f9c8..35d5bee59a8 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_sjis_mac.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_sjis_mac.c @@ -150,9 +150,7 @@ mbfl_filt_conv_sjis_mac_wchar(int c, mbfl_convert_filter *filter) CK((*filter->output_function)(0x2026, filter->data)); CK((*filter->output_function)(0xf87f, filter->data)); } else { - w = c & MBFL_WCSGROUP_MASK; - w |= MBFL_WCSGROUP_THROUGH; - CK((*filter->output_function)(w, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -218,8 +216,8 @@ mbfl_filt_conv_sjis_mac_wchar(int c, mbfl_convert_filter *filter) if (s >= code_ofst_tbl[i][0] && s <= code_ofst_tbl[i][1]) { w = code_map[i][s - code_ofst_tbl[i][0]]; if (w == 0) { - CK((*filter->output_function)((c1 << 8) | c | MBFL_WCSGROUP_THROUGH, filter->data)); - return c; + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); + return 0; } s2 = 0; if (s >= 0x043e && s <= 0x0441) { @@ -247,16 +245,11 @@ mbfl_filt_conv_sjis_mac_wchar(int c, mbfl_convert_filter *filter) } if (w <= 0) { - w = (s1 << 8) | s2; - w &= MBFL_WCSPLANE_MASK; - w |= MBFL_WCSPLANE_WINCP932; + w = MBFL_BAD_INPUT; } CK((*filter->output_function)(w, filter->data)); } else { - w = (c1 << 8) | c; - w &= MBFL_WCSGROUP_MASK; - w |= MBFL_WCSGROUP_THROUGH; - CK((*filter->output_function)(w, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -265,14 +258,13 @@ mbfl_filt_conv_sjis_mac_wchar(int c, mbfl_convert_filter *filter) break; } - return c; + return 0; } static int mbfl_filt_conv_sjis_mac_wchar_flush(mbfl_convert_filter *filter) { if (filter->status == 1) { - int w = (filter->cache & MBFL_WCSGROUP_MASK) | MBFL_WCSGROUP_THROUGH; - CK((*filter->output_function)(w, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } return 0; } @@ -404,7 +396,7 @@ mbfl_filt_conv_wchar_sjis_mac(int c, mbfl_convert_filter *filter) if (c == s_form_tbl[i]) { filter->status = 1; filter->cache = c; - return c; + return 0; } } @@ -412,7 +404,7 @@ mbfl_filt_conv_wchar_sjis_mac(int c, mbfl_convert_filter *filter) /* Apple 'transcoding hint' codepoints (from private use area) */ filter->status = 2; filter->cache = c; - return c; + return 0; } } @@ -665,7 +657,7 @@ mbfl_filt_conv_wchar_sjis_mac(int c, mbfl_convert_filter *filter) filter->status = 0; break; } - return c; + return 0; } static int diff --git a/ext/mbstring/libmbfl/filters/mbfilter_sjis_mobile.c b/ext/mbstring/libmbfl/filters/mbfilter_sjis_mobile.c index b1fe243c617..41097df304a 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_sjis_mobile.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_sjis_mobile.c @@ -577,7 +577,7 @@ int mbfl_filt_conv_sjis_mobile_wchar(int c, mbfl_convert_filter *filter) filter->status = 1; filter->cache = c; } else { - CK((*filter->output_function)(c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -641,11 +641,11 @@ int mbfl_filt_conv_sjis_mobile_wchar(int c, mbfl_convert_filter *filter) } } if (w <= 0) { - w = (s1 << 8) | s2 | MBFL_WCSPLANE_WINCP932; + w = MBFL_BAD_INPUT; } CK((*filter->output_function)(w, filter->data)); } else { - CK((*filter->output_function)((c1 << 8) | c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -655,7 +655,7 @@ int mbfl_filt_conv_sjis_mobile_wchar(int c, mbfl_convert_filter *filter) filter->cache = c; filter->status++; } else { - CK((*filter->output_function)((filter->cache << 8) | c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); filter->status = filter->cache = 0; } break; @@ -666,7 +666,7 @@ int mbfl_filt_conv_sjis_mobile_wchar(int c, mbfl_convert_filter *filter) filter->cache = c; filter->status++; } else { - CK((*filter->output_function)(0x1B2400 | c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); filter->status = filter->cache = 0; } break; @@ -676,7 +676,7 @@ int mbfl_filt_conv_sjis_mobile_wchar(int c, mbfl_convert_filter *filter) c1 = filter->cache; if (c == 0xF) { /* Terminate sequence of emoji */ filter->status = filter->cache = 0; - return c; + return 0; } else { if (c1 == 'G' && c >= 0x21 && c <= 0x7a) { s1 = (0x91 - 0x21) * 94; @@ -691,9 +691,9 @@ int mbfl_filt_conv_sjis_mobile_wchar(int c, mbfl_convert_filter *filter) } else if (c1 == 'Q' && c >= 0x21 && c <= 0x5E) { s1 = (0x96 - 0x21) * 94; } else { - CK((*filter->output_function)((c1 << 8) | c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); filter->status = filter->cache = 0; - return c; + return 0; } w = mbfilter_sjis_emoji_sb2unicode(s1 + c - 0x21, &snd); @@ -703,19 +703,19 @@ int mbfl_filt_conv_sjis_mobile_wchar(int c, mbfl_convert_filter *filter) } CK((*filter->output_function)(w, filter->data)); } else { - CK((*filter->output_function)((c1 << 8) | c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); filter->status = filter->cache = 0; } } } - return c; + return 0; } static int mbfl_filt_conv_sjis_wchar_flush(mbfl_convert_filter *filter) { if (filter->status && filter->status != 4) { - mbfl_filt_conv_illegal_output(filter->cache, filter); + (*filter->output_function)(MBFL_BAD_INPUT, filter->data); } if (filter->flush_function) { @@ -807,7 +807,7 @@ int mbfl_filt_conv_wchar_sjis_mobile(int c, mbfl_convert_filter *filter) } if (filter->status) { - return c; + return 0; } if (s1 >= 0) { @@ -824,7 +824,7 @@ int mbfl_filt_conv_wchar_sjis_mobile(int c, mbfl_convert_filter *filter) CK(mbfl_filt_conv_illegal_output(c, filter)); } - return c; + return 0; } int mbfl_filt_conv_sjis_mobile_flush(mbfl_convert_filter *filter) diff --git a/ext/mbstring/libmbfl/filters/mbfilter_ucs2.c b/ext/mbstring/libmbfl/filters/mbfilter_ucs2.c index efe8cc2d4ac..388a901fe66 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_ucs2.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_ucs2.c @@ -154,7 +154,7 @@ int mbfl_filt_conv_ucs2_wchar(int c, mbfl_convert_filter *filter) } } } - return c; + return 0; } int mbfl_filt_conv_ucs2be_wchar(int c, mbfl_convert_filter *filter) @@ -166,7 +166,7 @@ int mbfl_filt_conv_ucs2be_wchar(int c, mbfl_convert_filter *filter) filter->status = 0; CK((*filter->output_function)((c & 0xFF) | filter->cache, filter->data)); } - return c; + return 0; } int mbfl_filt_conv_wchar_ucs2be(int c, mbfl_convert_filter *filter) @@ -177,7 +177,7 @@ int mbfl_filt_conv_wchar_ucs2be(int c, mbfl_convert_filter *filter) } else { CK(mbfl_filt_conv_illegal_output(c, filter)); } - return c; + return 0; } int mbfl_filt_conv_ucs2le_wchar(int c, mbfl_convert_filter *filter) @@ -189,7 +189,7 @@ int mbfl_filt_conv_ucs2le_wchar(int c, mbfl_convert_filter *filter) filter->status = 0; CK((*filter->output_function)(((c & 0xFF) << 8) | filter->cache, filter->data)); } - return c; + return 0; } int mbfl_filt_conv_wchar_ucs2le(int c, mbfl_convert_filter *filter) @@ -200,14 +200,14 @@ int mbfl_filt_conv_wchar_ucs2le(int c, mbfl_convert_filter *filter) } else { CK(mbfl_filt_conv_illegal_output(c, filter)); } - return c; + return 0; } static int mbfl_filt_conv_ucs2_wchar_flush(mbfl_convert_filter *filter) { if (filter->status) { /* Input string was truncated */ - CK((*filter->output_function)(filter->cache | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } if (filter->flush_function) { diff --git a/ext/mbstring/libmbfl/filters/mbfilter_ucs4.c b/ext/mbstring/libmbfl/filters/mbfilter_ucs4.c index 8661e5830bd..6676f67c3ac 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_ucs4.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_ucs4.c @@ -192,7 +192,7 @@ int mbfl_filt_conv_ucs4_wchar(int c, mbfl_convert_filter *filter) break; } - return c; + return 0; } /* @@ -219,7 +219,7 @@ int mbfl_filt_conv_ucs4be_wchar(int c, mbfl_convert_filter *filter) n = (c & 0xff) | filter->cache; CK((*filter->output_function)(n, filter->data)); } - return c; + return 0; } /* @@ -227,7 +227,7 @@ int mbfl_filt_conv_ucs4be_wchar(int c, mbfl_convert_filter *filter) */ int mbfl_filt_conv_wchar_ucs4be(int c, mbfl_convert_filter *filter) { - if (c >= 0 && c < MBFL_WCSGROUP_UCS4MAX) { + if (c != MBFL_BAD_INPUT) { CK((*filter->output_function)((c >> 24) & 0xff, filter->data)); CK((*filter->output_function)((c >> 16) & 0xff, filter->data)); CK((*filter->output_function)((c >> 8) & 0xff, filter->data)); @@ -236,7 +236,7 @@ int mbfl_filt_conv_wchar_ucs4be(int c, mbfl_convert_filter *filter) CK(mbfl_filt_conv_illegal_output(c, filter)); } - return c; + return 0; } /* @@ -263,7 +263,7 @@ int mbfl_filt_conv_ucs4le_wchar(int c, mbfl_convert_filter *filter) n = ((c & 0xffu) << 24) | filter->cache; CK((*filter->output_function)(n, filter->data)); } - return c; + return 0; } /* @@ -271,7 +271,7 @@ int mbfl_filt_conv_ucs4le_wchar(int c, mbfl_convert_filter *filter) */ int mbfl_filt_conv_wchar_ucs4le(int c, mbfl_convert_filter *filter) { - if (c >= 0 && c < MBFL_WCSGROUP_UCS4MAX) { + if (c != MBFL_BAD_INPUT) { CK((*filter->output_function)(c & 0xff, filter->data)); CK((*filter->output_function)((c >> 8) & 0xff, filter->data)); CK((*filter->output_function)((c >> 16) & 0xff, filter->data)); @@ -280,14 +280,14 @@ int mbfl_filt_conv_wchar_ucs4le(int c, mbfl_convert_filter *filter) CK(mbfl_filt_conv_illegal_output(c, filter)); } - return c; + return 0; } static int mbfl_filt_conv_ucs4_wchar_flush(mbfl_convert_filter *filter) { if (filter->status & 0xF) { /* Input string was truncated */ - CK((*filter->output_function)(filter->cache | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } if (filter->flush_function) { diff --git a/ext/mbstring/libmbfl/filters/mbfilter_uhc.c b/ext/mbstring/libmbfl/filters/mbfilter_uhc.c index e071a503a7f..96be552729b 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_uhc.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_uhc.c @@ -102,7 +102,7 @@ int mbfl_filt_conv_uhc_wchar(int c, mbfl_convert_filter *filter) filter->status = 1; filter->cache = c; } else { - CK((*filter->output_function)(c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -128,7 +128,7 @@ int mbfl_filt_conv_uhc_wchar(int c, mbfl_convert_filter *filter) } if (w == 0) { - w = (c1 << 8) | c | MBFL_WCSPLANE_UHC; + w = MBFL_BAD_INPUT; } CK((*filter->output_function)(w, filter->data)); break; @@ -138,14 +138,14 @@ int mbfl_filt_conv_uhc_wchar(int c, mbfl_convert_filter *filter) break; } - return c; + return 0; } static int mbfl_filt_conv_uhc_wchar_flush(mbfl_convert_filter *filter) { if (filter->status == 1) { /* 2-byte character was truncated */ - CK((*filter->output_function)(filter->cache | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } if (filter->flush_function) { @@ -190,5 +190,5 @@ int mbfl_filt_conv_wchar_uhc(int c, mbfl_convert_filter *filter) CK(mbfl_filt_conv_illegal_output(c, filter)); } - return c; + return 0; } diff --git a/ext/mbstring/libmbfl/filters/mbfilter_utf16.c b/ext/mbstring/libmbfl/filters/mbfilter_utf16.c index 4f8b1fef535..71f6e1a0933 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_utf16.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_utf16.c @@ -147,10 +147,10 @@ int mbfl_filt_conv_utf16_wchar(int c, mbfl_convert_filter *filter) if (n >= 0xD800 && n <= 0xDBFF) { filter->cache = n & 0x3FF; /* Pick out 10 data bits */ filter->status = 2; - return c; + return 0; } else if (n >= 0xDC00 && n <= 0xDFFF) { /* This is wrong; second part of surrogate pair has come first */ - CK((*filter->output_function)(n | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } else if (n != 0xFEFF) { CK((*filter->output_function)(n, filter->data)); } @@ -158,7 +158,7 @@ int mbfl_filt_conv_utf16_wchar(int c, mbfl_convert_filter *filter) } } - return c; + return 0; } int mbfl_filt_conv_utf16be_wchar(int c, mbfl_convert_filter *filter) @@ -178,7 +178,7 @@ int mbfl_filt_conv_utf16be_wchar(int c, mbfl_convert_filter *filter) filter->status = 2; } else if (n >= 0xDC00 && n <= 0xDFFF) { /* This is wrong; second part of surrogate pair has come first */ - CK((*filter->output_function)(n | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); filter->status = 0; } else { CK((*filter->output_function)(n, filter->data)); @@ -195,7 +195,7 @@ int mbfl_filt_conv_utf16be_wchar(int c, mbfl_convert_filter *filter) n = ((filter->cache & 0xFF) << 8) | (c & 0xFF); if (n >= 0xD800 && n <= 0xDBFF) { /* Wrong; that's the first half of a surrogate pair, not the second */ - CK((*filter->output_function)(0xD800 | (filter->cache >> 8) | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); filter->cache = n & 0x3FF; filter->status = 2; } else if (n >= 0xDC00 && n <= 0xDFFF) { @@ -203,13 +203,13 @@ int mbfl_filt_conv_utf16be_wchar(int c, mbfl_convert_filter *filter) CK((*filter->output_function)(n, filter->data)); filter->status = 0; } else { - CK((*filter->output_function)(0xD800 | (filter->cache >> 8) | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); CK((*filter->output_function)(n, filter->data)); filter->status = 0; } } - return c; + return 0; } int mbfl_filt_conv_wchar_utf16be(int c, mbfl_convert_filter *filter) @@ -230,7 +230,7 @@ int mbfl_filt_conv_wchar_utf16be(int c, mbfl_convert_filter *filter) CK(mbfl_filt_conv_illegal_output(c, filter)); } - return c; + return 0; } int mbfl_filt_conv_utf16le_wchar(int c, mbfl_convert_filter *filter) @@ -249,11 +249,8 @@ int mbfl_filt_conv_utf16le_wchar(int c, mbfl_convert_filter *filter) filter->cache += ((c & 0x3) << 8); filter->status = 2; } else if ((c & 0xfc) == 0xdc) { - /* This is wrong; the second part of the surrogate pair has come first - * Flag it with `MBFL_WCSGROUP_THROUGH`; the following filter will handle - * the error */ - n = (filter->cache + ((c & 0xff) << 8)) | MBFL_WCSGROUP_THROUGH; - CK((*filter->output_function)(n, filter->data)); + /* This is wrong; the second part of the surrogate pair has come first */ + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); filter->status = 0; } else { CK((*filter->output_function)(filter->cache + ((c & 0xff) << 8), filter->data)); @@ -269,7 +266,9 @@ int mbfl_filt_conv_utf16le_wchar(int c, mbfl_convert_filter *filter) case 3: n = (filter->cache & 0xFF) | ((c & 0xFF) << 8); if (n >= 0xD800 && n <= 0xDBFF) { - CK((*filter->output_function)(0xD800 | (filter->cache >> 10) | MBFL_WCSGROUP_THROUGH, filter->data)); + /* We previously saw the first part of a surrogate pair and were + * expecting the second part; this is another first part */ + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); filter->cache = n & 0x3FF; filter->status = 2; } else if (n >= 0xDC00 && n <= 0xDFFF) { @@ -277,14 +276,16 @@ int mbfl_filt_conv_utf16le_wchar(int c, mbfl_convert_filter *filter) CK((*filter->output_function)(n, filter->data)); filter->status = 0; } else { - CK((*filter->output_function)(0xD800 | (filter->cache >> 10) | MBFL_WCSGROUP_THROUGH, filter->data)); + /* The first part of a surrogate pair was followed by some other codepoint + * which is not part of a surrogate pair at all */ + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); CK((*filter->output_function)(n, filter->data)); filter->status = 0; } break; } - return c; + return 0; } int mbfl_filt_conv_wchar_utf16le(int c, mbfl_convert_filter *filter) @@ -305,22 +306,14 @@ int mbfl_filt_conv_wchar_utf16le(int c, mbfl_convert_filter *filter) CK(mbfl_filt_conv_illegal_output(c, filter)); } - return c; + return 0; } static int mbfl_filt_conv_utf16_wchar_flush(mbfl_convert_filter *filter) { - int status = filter->status; - int cache = filter->cache; - filter->status = filter->cache = 0; - - if (status) { + if (filter->status) { /* Input string was truncated */ - if (status == 1) { - CK((*filter->output_function)(cache | MBFL_WCSGROUP_THROUGH, filter->data)); - } else if (status == 2) { - CK((*filter->output_function)(0xD800 | cache | MBFL_WCSGROUP_THROUGH, filter->data)); - } + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } if (filter->flush_function) { diff --git a/ext/mbstring/libmbfl/filters/mbfilter_utf32.c b/ext/mbstring/libmbfl/filters/mbfilter_utf32.c index c356a824a65..ec9945e13ef 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_utf32.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_utf32.c @@ -134,8 +134,7 @@ static int emit_char_if_valid(int n, mbfl_convert_filter *filter) if (n >= 0 && n < MBFL_WCSPLANE_UTF32MAX && (n < 0xD800 || n > 0xDFFF)) { CK((*filter->output_function)(n, filter->data)); } else { - n = (n & MBFL_WCSGROUP_MASK) | MBFL_WCSGROUP_THROUGH; - CK((*filter->output_function)(n, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } return 0; } @@ -160,7 +159,7 @@ int mbfl_filt_conv_utf32_wchar(int c, mbfl_convert_filter *filter) } } - return c; + return 0; } int mbfl_filt_conv_utf32be_wchar(int c, mbfl_convert_filter *filter) @@ -173,7 +172,7 @@ int mbfl_filt_conv_utf32be_wchar(int c, mbfl_convert_filter *filter) filter->cache = filter->status = 0; CK(emit_char_if_valid(n, filter)); } - return c; + return 0; } int mbfl_filt_conv_wchar_utf32be(int c, mbfl_convert_filter *filter) @@ -187,7 +186,7 @@ int mbfl_filt_conv_wchar_utf32be(int c, mbfl_convert_filter *filter) CK(mbfl_filt_conv_illegal_output(c, filter)); } - return c; + return 0; } int mbfl_filt_conv_utf32le_wchar(int c, mbfl_convert_filter *filter) @@ -200,7 +199,7 @@ int mbfl_filt_conv_utf32le_wchar(int c, mbfl_convert_filter *filter) filter->cache = filter->status = 0; CK(emit_char_if_valid(n, filter)); } - return c; + return 0; } int mbfl_filt_conv_wchar_utf32le(int c, mbfl_convert_filter *filter) @@ -214,14 +213,14 @@ int mbfl_filt_conv_wchar_utf32le(int c, mbfl_convert_filter *filter) CK(mbfl_filt_conv_illegal_output(c, filter)); } - return c; + return 0; } static int mbfl_filt_conv_utf32_wchar_flush(mbfl_convert_filter *filter) { if (filter->status) { /* Input string was truncated */ - CK((*filter->output_function)(filter->cache | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } if (filter->flush_function) { diff --git a/ext/mbstring/libmbfl/filters/mbfilter_utf7.c b/ext/mbstring/libmbfl/filters/mbfilter_utf7.c index 1e7afb92572..a5446afd8ae 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_utf7.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_utf7.c @@ -107,11 +107,7 @@ int mbfl_filt_conv_utf7_wchar(int c, mbfl_convert_filter *filter) if (filter->cache) { /* Either we were expecting the 2nd half of a surrogate pair which * never came, or else the last Base64 data was not padded with zeroes */ - if (filter->cache & 0xfff0000) { - (*filter->output_function)(0xD800 | (((filter->cache - 0x400000) >> 16) & 0x3FF) | MBFL_WCSGROUP_THROUGH, filter->data); - } else { - (*filter->output_function)(filter->cache | MBFL_WCSGROUP_THROUGH, filter->data); - } + (*filter->output_function)(MBFL_BAD_INPUT, filter->data); } if (c == '-') { if (filter->status == 1) { /* "+-" -> "+" */ @@ -120,10 +116,10 @@ int mbfl_filt_conv_utf7_wchar(int c, mbfl_convert_filter *filter) } else if (c >= 0 && c < 0x80) { /* ASCII exclude '-' */ CK((*filter->output_function)(c, filter->data)); } else { /* illegal character */ - CK((*filter->output_function)(c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } filter->cache = filter->status = 0; - return c; + return 0; } } @@ -135,7 +131,7 @@ int mbfl_filt_conv_utf7_wchar(int c, mbfl_convert_filter *filter) } else if (c >= 0 && c < 0x80) { /* ASCII */ CK((*filter->output_function)(c, filter->data)); } else { /* illegal character */ - CK((*filter->output_function)(c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -157,7 +153,7 @@ int mbfl_filt_conv_utf7_wchar(int c, mbfl_convert_filter *filter) /* 1st part of surrogate pair */ if (filter->cache & 0xfff0000) { /* We were waiting for the 2nd part of a surrogate pair */ - (*filter->output_function)(0xD800 | (((filter->cache - 0x400000) >> 16) & 0x3FF) | MBFL_WCSGROUP_THROUGH, filter->data); + (*filter->output_function)(MBFL_BAD_INPUT, filter->data); } s = (((s & 0x3ff) << 16) + 0x400000) | n; filter->cache = s; @@ -170,16 +166,16 @@ int mbfl_filt_conv_utf7_wchar(int c, mbfl_convert_filter *filter) if (s >= MBFL_WCSPLANE_SUPMIN && s < MBFL_WCSPLANE_SUPMAX) { CK((*filter->output_function)(s, filter->data)); } else { /* illegal character */ - CK((*filter->output_function)(s | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } } else { - CK((*filter->output_function)(s | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); filter->cache = n; } } else { if (filter->cache & 0xfff0000) { /* We were waiting for the 2nd part of a surrogate pair */ - (*filter->output_function)(0xD800 | (((filter->cache - 0x400000) >> 16) & 0x3FF) | MBFL_WCSGROUP_THROUGH, filter->data); + (*filter->output_function)(MBFL_BAD_INPUT, filter->data); } filter->cache = n; CK((*filter->output_function)(s, filter->data)); @@ -201,7 +197,7 @@ int mbfl_filt_conv_utf7_wchar(int c, mbfl_convert_filter *filter) if (s >= 0xd800 && s < 0xdc00) { if (filter->cache & 0xfff0000) { /* We were waiting for the 2nd part of a surrogate pair */ - (*filter->output_function)(0xD800 | (((filter->cache - 0x400000) >> 16) & 0x3FF) | MBFL_WCSGROUP_THROUGH, filter->data); + (*filter->output_function)(MBFL_BAD_INPUT, filter->data); } s = (((s & 0x3ff) << 16) + 0x400000) | n; filter->cache = s; @@ -214,16 +210,16 @@ int mbfl_filt_conv_utf7_wchar(int c, mbfl_convert_filter *filter) if (s >= MBFL_WCSPLANE_SUPMIN && s < MBFL_WCSPLANE_SUPMAX) { CK((*filter->output_function)(s, filter->data)); } else { /* illegal character */ - CK((*filter->output_function)(s | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } } else { - CK((*filter->output_function)(s | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); filter->cache = n; } } else { if (filter->cache & 0xfff0000) { /* We were waiting for the 2nd part of a surrogate pair */ - (*filter->output_function)(0xD800 | (((filter->cache - 0x400000) >> 16) & 0x3FF) | MBFL_WCSGROUP_THROUGH, filter->data); + (*filter->output_function)(MBFL_BAD_INPUT, filter->data); } filter->cache = n; CK((*filter->output_function)(s, filter->data)); @@ -240,7 +236,7 @@ int mbfl_filt_conv_utf7_wchar(int c, mbfl_convert_filter *filter) if (s >= 0xd800 && s < 0xdc00) { if (filter->cache & 0xfff0000) { /* We were waiting for the 2nd part of a surrogate pair */ - (*filter->output_function)(0xD800 | (((filter->cache - 0x400000) >> 16) & 0x3FF) | MBFL_WCSGROUP_THROUGH, filter->data); + (*filter->output_function)(MBFL_BAD_INPUT, filter->data); } s = (((s & 0x3ff) << 16) + 0x400000); filter->cache = s; @@ -252,16 +248,16 @@ int mbfl_filt_conv_utf7_wchar(int c, mbfl_convert_filter *filter) if (s >= MBFL_WCSPLANE_SUPMIN && s < MBFL_WCSPLANE_SUPMAX) { CK((*filter->output_function)(s, filter->data)); } else { /* illegal character */ - CK((*filter->output_function)(s | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } } else { - CK((*filter->output_function)(s | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); filter->cache = 0; } } else { if (filter->cache & 0xfff0000) { /* We were waiting for the 2nd part of a surrogate pair */ - (*filter->output_function)(0xD800 | (((filter->cache - 0x400000) >> 16) & 0x3FF) | MBFL_WCSGROUP_THROUGH, filter->data); + (*filter->output_function)(MBFL_BAD_INPUT, filter->data); } filter->cache = 0; CK((*filter->output_function)(s, filter->data)); @@ -273,7 +269,7 @@ int mbfl_filt_conv_utf7_wchar(int c, mbfl_convert_filter *filter) break; } - return c; + return 0; } static int mbfl_filt_conv_utf7_wchar_flush(mbfl_convert_filter *filter) @@ -281,11 +277,7 @@ static int mbfl_filt_conv_utf7_wchar_flush(mbfl_convert_filter *filter) if (filter->cache) { /* Either we were expecting the 2nd half of a surrogate pair which * never came, or else the last Base64 data was not padded with zeroes */ - if (filter->cache & 0xfff0000) { - (*filter->output_function)(0xD800 | (((filter->cache - 0x400000) >> 16) & 0x3FF) | MBFL_WCSGROUP_THROUGH, filter->data); - } else { - (*filter->output_function)(filter->cache | MBFL_WCSGROUP_THROUGH, filter->data); - } + (*filter->output_function)(MBFL_BAD_INPUT, filter->data); } if (filter->flush_function) { @@ -311,10 +303,10 @@ int mbfl_filt_conv_wchar_utf7(int c, mbfl_convert_filter *filter) } else if (c >= MBFL_WCSPLANE_SUPMIN && c < MBFL_WCSPLANE_SUPMAX) { CK((*filter->filter_function)(((c >> 10) - 0x40) | 0xd800, filter)); CK((*filter->filter_function)((c & 0x3ff) | 0xdc00, filter)); - return c; + return 0; } else { CK(mbfl_filt_conv_illegal_output(c, filter)); - return c; + return 0; } switch (filter->status) { @@ -386,8 +378,7 @@ int mbfl_filt_conv_wchar_utf7(int c, mbfl_convert_filter *filter) break; } - return c; - + return 0; } int mbfl_filt_conv_wchar_utf7_flush(mbfl_convert_filter *filter) diff --git a/ext/mbstring/libmbfl/filters/mbfilter_utf7imap.c b/ext/mbstring/libmbfl/filters/mbfilter_utf7imap.c index 731f89d1551..a5b38926fc2 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_utf7imap.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_utf7imap.c @@ -140,13 +140,13 @@ int mbfl_filt_conv_utf7imap_wchar(int c, mbfl_convert_filter *filter) } else if (filter->cache) { /* Base64-encoded section ended abruptly, with partially encoded characters, * or it could be that it ended on the first half of a surrogate pair */ - CK((*filter->output_function)(filter->cache | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } } else { /* illegal character */ - CK((*filter->output_function)(c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } filter->cache = filter->status = 0; - return c; + return 0; } } @@ -158,7 +158,7 @@ int mbfl_filt_conv_utf7imap_wchar(int c, mbfl_convert_filter *filter) } else if (c >= 0x20 && c <= 0x7E) { /* ASCII */ CK((*filter->output_function)(c, filter->data)); } else { /* illegal character */ - CK((*filter->output_function)(c | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } break; @@ -186,7 +186,7 @@ int mbfl_filt_conv_utf7imap_wchar(int c, mbfl_convert_filter *filter) if (s >= MBFL_WCSPLANE_SUPMIN && s < MBFL_WCSPLANE_SUPMAX) { CK((*filter->output_function)(s, filter->data)); } else { /* illegal character */ - CK((*filter->output_function)(s | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } } else { filter->cache = n; @@ -195,7 +195,7 @@ int mbfl_filt_conv_utf7imap_wchar(int c, mbfl_convert_filter *filter) if (s < 0x20 || s > 0x7E || s == '&') { CK((*filter->output_function)(s, filter->data)); } else { - CK((*filter->output_function)(s | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } } break; @@ -222,7 +222,7 @@ int mbfl_filt_conv_utf7imap_wchar(int c, mbfl_convert_filter *filter) if (s >= MBFL_WCSPLANE_SUPMIN && s < MBFL_WCSPLANE_SUPMAX) { CK((*filter->output_function)(s, filter->data)); } else { /* illegal character */ - CK((*filter->output_function)(s | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } } else { filter->cache = n; @@ -231,7 +231,7 @@ int mbfl_filt_conv_utf7imap_wchar(int c, mbfl_convert_filter *filter) if (s < 0x20 || s > 0x7E || s == '&') { CK((*filter->output_function)(s, filter->data)); } else { - CK((*filter->output_function)(s | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } } break; @@ -253,7 +253,7 @@ int mbfl_filt_conv_utf7imap_wchar(int c, mbfl_convert_filter *filter) if (s >= MBFL_WCSPLANE_SUPMIN && s < MBFL_WCSPLANE_SUPMAX) { CK((*filter->output_function)(s, filter->data)); } else { /* illegal character */ - CK((*filter->output_function)(s | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } } else { filter->cache = 0; @@ -262,7 +262,7 @@ int mbfl_filt_conv_utf7imap_wchar(int c, mbfl_convert_filter *filter) if (s < 0x20 || s > 0x7E || s == '&') { CK((*filter->output_function)(s, filter->data)); } else { - CK((*filter->output_function)(s | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } } break; @@ -272,7 +272,7 @@ int mbfl_filt_conv_utf7imap_wchar(int c, mbfl_convert_filter *filter) break; } - return c; + return 0; } static int mbfl_filt_conv_utf7imap_wchar_flush(mbfl_convert_filter *filter) @@ -280,7 +280,7 @@ static int mbfl_filt_conv_utf7imap_wchar_flush(mbfl_convert_filter *filter) if (filter->status) { /* It is illegal for a UTF-7 IMAP string to end in a Base-64 encoded * section. It should always change back to ASCII before the end. */ - (*filter->output_function)(filter->cache | MBFL_WCSGROUP_THROUGH, filter->data); + (*filter->output_function)(MBFL_BAD_INPUT, filter->data); } if (filter->flush_function) { @@ -319,10 +319,10 @@ int mbfl_filt_conv_wchar_utf7imap(int c, mbfl_convert_filter *filter) CK((*filter->filter_function)(s, filter)); s = (c & 0x3ff) | 0xdc00; CK((*filter->filter_function)(s, filter)); - return c; + return 0; } else { CK(mbfl_filt_conv_illegal_output(c, filter)); - return c; + return 0; } switch (filter->status) { @@ -400,8 +400,7 @@ int mbfl_filt_conv_wchar_utf7imap(int c, mbfl_convert_filter *filter) break; } - return c; - + return 0; } static int mbfl_filt_conv_wchar_utf7imap_flush(mbfl_convert_filter *filter) diff --git a/ext/mbstring/libmbfl/filters/mbfilter_utf8.c b/ext/mbstring/libmbfl/filters/mbfilter_utf8.c index f6fe3fac421..524c9c079a1 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_utf8.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_utf8.c @@ -84,10 +84,10 @@ const struct mbfl_convert_vtbl vtbl_wchar_utf8 = { #define CK(statement) do { if ((statement) < 0) return (-1); } while (0) -int mbfl_filt_put_invalid_char(int c, mbfl_convert_filter *filter) +int mbfl_filt_put_invalid_char(mbfl_convert_filter *filter) { filter->status = filter->cache = 0; - CK((*filter->output_function)((c & MBFL_WCSGROUP_MASK) | MBFL_WCSGROUP_THROUGH, filter->data)); + CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); return 0; } @@ -110,7 +110,7 @@ retry: filter->status = 0x30; filter->cache = c & 0x7; } else { - CK(mbfl_filt_put_invalid_char(c, filter)); + CK(mbfl_filt_put_invalid_char(filter)); } break; case 0x10: /* 2byte code 2nd char: 0x80-0xbf */ @@ -121,25 +121,9 @@ retry: filter->status = filter->cache = 0; CK((*filter->output_function)(s, filter->data)); } else { - int status = filter->status; - filter->status = 0; + CK(mbfl_filt_put_invalid_char(filter)); if (c < 0x80 || (c >= 0xc2 && c <= 0xf4)) { - if (status == 0x10) { - CK(mbfl_filt_put_invalid_char(0xC0 | filter->cache, filter)); - } else if (status == 0x21) { - CK(mbfl_filt_put_invalid_char(0xE080 | ((filter->cache & ~0x3F) << 2) | (filter->cache & 0x3F), filter)); - } else { - CK(mbfl_filt_put_invalid_char(0xF08080 | ((filter->cache & ~0xFFF) << 4) | ((filter->cache & 0xFC0) << 2) | (filter->cache & 0x3F), filter)); - } goto retry; - } else { - if (status == 0x10) { - CK(mbfl_filt_put_invalid_char(0xC000 | (filter->cache << 8) | c, filter)); - } else if (status == 0x21) { - CK(mbfl_filt_put_invalid_char(0xE08000 | ((filter->cache & ~0x3F) << 10) | ((filter->cache & 0x3F) << 8) | c, filter)); - } else { - CK(mbfl_filt_put_invalid_char(0x808000 | ((filter->cache & 0xFC0) << 10) | ((filter->cache & 0x3F) << 8) | c, filter)); - } } } break; @@ -154,12 +138,9 @@ retry: filter->cache = s; filter->status++; } else { + CK(mbfl_filt_put_invalid_char(filter)); if (c < 0x80 || (c >= 0xc2 && c <= 0xf4)) { - CK(mbfl_filt_put_invalid_char(0xE0 | filter->cache, filter)); goto retry; - } else { - CK(mbfl_filt_put_invalid_char(0xE000 | (filter->cache << 8) | c, filter)); - filter->status = 0; } } break; @@ -174,12 +155,9 @@ retry: filter->cache = s; filter->status++; } else { + CK(mbfl_filt_put_invalid_char(filter)); if (c < 0x80 || (c >= 0xc2 && c <= 0xf4)) { - CK(mbfl_filt_put_invalid_char(0xF0 | filter->cache, filter)); goto retry; - } else { - CK(mbfl_filt_put_invalid_char(0xF000 | (filter->cache << 8) | c, filter)); - filter->status = 0; } } break; @@ -188,12 +166,9 @@ retry: filter->cache = (filter->cache<<6) | (c & 0x3f); filter->status++; } else { + CK(mbfl_filt_put_invalid_char(filter)); if (c < 0x80 || (c >= 0xc2 && c <= 0xf4)) { - CK(mbfl_filt_put_invalid_char(0xF080 | ((filter->cache & ~0x3F) << 2) | (filter->cache & 0x3F), filter)); goto retry; - } else { - CK(mbfl_filt_put_invalid_char(0xF000 | (filter->cache << 8) | c, filter)); - filter->status = 0; } } break; @@ -202,29 +177,13 @@ retry: break; } - return c; + return 0; } int mbfl_filt_conv_utf8_wchar_flush(mbfl_convert_filter *filter) { - int status = filter->status, cache = filter->cache; - - filter->status = filter->cache = 0; - - if (status) { - if (status == 0x10) { - CK(mbfl_filt_put_invalid_char(0xC0 | cache, filter)); - } else if (status == 0x20) { - CK(mbfl_filt_put_invalid_char(0xE0 | cache, filter)); - } else if (status == 0x21) { - CK(mbfl_filt_put_invalid_char(0xE080 | ((cache & ~0x3F) << 2) | (cache & 0x3F), filter)); - } else if (status == 0x30) { - CK(mbfl_filt_put_invalid_char(0xF0 | cache, filter)); - } else if (status == 0x31) { - CK(mbfl_filt_put_invalid_char(0xF080 | ((cache & ~0x3F) << 2) | (cache & 0x3F), filter)); - } else if (status == 0x32) { - CK(mbfl_filt_put_invalid_char(0xF08080 | ((cache & ~0xFFF) << 4) | ((cache & 0xFC0) << 2) | (cache & 0x3F), filter)); - } + if (filter->status) { + (*filter->output_function)(MBFL_BAD_INPUT, filter->data); } if (filter->flush_function) { @@ -256,5 +215,5 @@ int mbfl_filt_conv_wchar_utf8(int c, mbfl_convert_filter *filter) CK(mbfl_filt_conv_illegal_output(c, filter)); } - return c; + return 0; } diff --git a/ext/mbstring/libmbfl/filters/mbfilter_utf8_mobile.c b/ext/mbstring/libmbfl/filters/mbfilter_utf8_mobile.c index 1334637a866..c52459dc3ab 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_utf8_mobile.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_utf8_mobile.c @@ -166,7 +166,8 @@ const struct mbfl_convert_vtbl vtbl_wchar_utf8_sb = { }; #define CK(statement) do { if ((statement) < 0) return (-1); } while (0) -int mbfl_filt_put_invalid_char(int c, mbfl_convert_filter *filter); + +extern int mbfl_filt_put_invalid_char(mbfl_convert_filter *filter); int mbfl_filt_conv_utf8_mobile_wchar(int c, mbfl_convert_filter *filter) { @@ -187,7 +188,7 @@ retry: filter->status = 0x30; filter->cache = c & 0x7; } else { - CK(mbfl_filt_put_invalid_char(c, filter)); + CK(mbfl_filt_put_invalid_char(filter)); } break; @@ -214,7 +215,7 @@ retry: } CK((*filter->output_function)(s, filter->data)); } else { - CK(mbfl_filt_put_invalid_char(filter->cache, filter)); + CK(mbfl_filt_put_invalid_char(filter)); goto retry; } break; @@ -230,7 +231,7 @@ retry: filter->cache = s; filter->status++; } else { - CK(mbfl_filt_put_invalid_char(filter->cache, filter)); + CK(mbfl_filt_put_invalid_char(filter)); goto retry; } break; @@ -246,7 +247,7 @@ retry: filter->cache = s; filter->status++; } else { - CK(mbfl_filt_put_invalid_char(filter->cache, filter)); + CK(mbfl_filt_put_invalid_char(filter)); goto retry; } break; @@ -256,7 +257,7 @@ retry: filter->cache = (filter->cache << 6) | (c & 0x3f); filter->status++; } else { - CK(mbfl_filt_put_invalid_char(filter->cache, filter)); + CK(mbfl_filt_put_invalid_char(filter)); goto retry; } break; @@ -265,7 +266,7 @@ retry: break; } - return c; + return 0; } int mbfl_filt_conv_wchar_utf8_mobile(int c, mbfl_convert_filter *filter) @@ -281,7 +282,7 @@ int mbfl_filt_conv_wchar_utf8_mobile(int c, mbfl_convert_filter *filter) } if (filter->status) { - return c; + return 0; } if (c < 0x80) { @@ -303,5 +304,5 @@ int mbfl_filt_conv_wchar_utf8_mobile(int c, mbfl_convert_filter *filter) CK(mbfl_filt_conv_illegal_output(c, filter)); } - return c; + return 0; } diff --git a/ext/mbstring/libmbfl/filters/mbfilter_uuencode.c b/ext/mbstring/libmbfl/filters/mbfilter_uuencode.c index fab29ef9fc8..d602274db62 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_uuencode.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_uuencode.c @@ -145,5 +145,5 @@ int mbfl_filt_conv_uudec(int c, mbfl_convert_filter * filter) /* skip newline */ filter->status = uudec_state_size; } - return c; + return 0; } diff --git a/ext/mbstring/libmbfl/mbfl/mbfilter.c b/ext/mbstring/libmbfl/mbfl/mbfilter.c index 69704489fd0..9db80c8895b 100644 --- a/ext/mbstring/libmbfl/mbfl/mbfilter.c +++ b/ext/mbstring/libmbfl/mbfl/mbfilter.c @@ -292,7 +292,7 @@ static int mbfl_estimate_encoding_likelihood(int c, void *void_data) /* Receive wchars decoded from test string using candidate encoding * If the test string was invalid in the candidate encoding, we assume * it's the wrong one. */ - if (c & MBFL_WCSGROUP_THROUGH) { + if (c == MBFL_BAD_INPUT) { data->num_illegalchars++; } else if (php_unicode_is_cntrl(c) || php_unicode_is_private(c)) { /* Otherwise, count how many control characters and 'private use' @@ -303,7 +303,7 @@ static int mbfl_estimate_encoding_likelihood(int c, void *void_data) /* Punctuation is also less common than letters/digits */ data->score++; } - return c; + return 0; } mbfl_encoding_detector *mbfl_encoding_detector_new(const mbfl_encoding **elist, int elistsz, int strict) @@ -475,7 +475,7 @@ static int filter_count_output(int c, void *data) { (*(size_t *)data)++; - return c; + return 0; } size_t @@ -591,7 +591,7 @@ retry: } pc->output++; - return c; + return 0; } static const unsigned char *mbfl_find_offset_utf8( @@ -823,7 +823,7 @@ collector_substr(int c, void* data) pc->output++; - return c; + return 0; } mbfl_string * @@ -1286,7 +1286,7 @@ static int filter_count_width(int c, void* data) { (*(size_t *)data) += (is_fullwidth(c) ? 2: 1); - return c; + return 0; } size_t @@ -1359,7 +1359,8 @@ collector_strimwidth(int c, void* data) } pc->status++; (*pc->decoder->filter_function)(c, pc->decoder); - c = -1; + pc->outchar++; + return -1; } else { (*pc->decoder->filter_function)(c, pc->decoder); } @@ -1368,7 +1369,7 @@ collector_strimwidth(int c, void* data) break; } - return c; + return 0; } mbfl_string * @@ -1618,7 +1619,7 @@ mime_header_encoder_block_collector(int c, void *data) break; } - return c; + return 0; } static int @@ -1688,7 +1689,7 @@ mime_header_encoder_collector(int c, void *data) break; } - return c; + return 0; } mbfl_string * @@ -2037,7 +2038,7 @@ mime_header_decoder_collector(int c, void* data) break; } - return c; + return 0; } mbfl_string * @@ -2194,7 +2195,7 @@ collector_encode_htmlnumericentity(int c, void *data) (*pc->decoder->filter_function)(c, pc->decoder); } - return c; + return 0; } static int @@ -2370,7 +2371,7 @@ collector_decode_htmlnumericentity(int c, void *data) break; } - return c; + return 0; } static int @@ -2417,7 +2418,7 @@ collector_encode_hex_htmlnumericentity(int c, void *data) (*pc->decoder->filter_function)(c, pc->decoder); } - return c; + return 0; } int mbfl_filt_decode_htmlnumericentity_flush(mbfl_convert_filter *filter) diff --git a/ext/mbstring/libmbfl/mbfl/mbfilter_8bit.c b/ext/mbstring/libmbfl/mbfl/mbfilter_8bit.c index 4017829cf80..e348ddb69cc 100644 --- a/ext/mbstring/libmbfl/mbfl/mbfilter_8bit.c +++ b/ext/mbstring/libmbfl/mbfl/mbfilter_8bit.c @@ -85,5 +85,5 @@ static int mbfl_filt_conv_wchar_8bit(int c, mbfl_convert_filter *filter) CK(mbfl_filt_conv_illegal_output(c, filter)); } - return c; + return 0; } diff --git a/ext/mbstring/libmbfl/mbfl/mbfl_consts.h b/ext/mbstring/libmbfl/mbfl/mbfl_consts.h index bc645ab7613..1e4add39113 100644 --- a/ext/mbstring/libmbfl/mbfl/mbfl_consts.h +++ b/ext/mbstring/libmbfl/mbfl/mbfl_consts.h @@ -37,27 +37,13 @@ #define MBFL_ENCTYPE_WCS4 0x00000100 /* 4 bytes/char */ #define MBFL_ENCTYPE_GL_UNSAFE 0x00004000 -/* wchar plane, special character */ -#define MBFL_WCSPLANE_MASK 0xffff #define MBFL_WCSPLANE_UCS2MAX 0x00010000 #define MBFL_WCSPLANE_UTF32MAX 0x00110000 #define MBFL_WCSPLANE_SUPMIN 0x00010000 #define MBFL_WCSPLANE_SUPMAX 0x00200000 -#define MBFL_WCSPLANE_JIS0213 0x70e00000 /* JIS HEX : 2121h - 7E7Eh */ -#define MBFL_WCSPLANE_JIS0208 0x70e10000 /* JIS HEX : 2121h - 7E7Eh */ -#define MBFL_WCSPLANE_JIS0212 0x70e20000 /* JIS HEX : 2121h - 7E7Eh */ -#define MBFL_WCSPLANE_WINCP932 0x70e30000 /* JIS HEX : 2121h - 9898h */ -#define MBFL_WCSPLANE_KSC5601 0x70f10000 /* 2121h - 7E7Eh */ -#define MBFL_WCSPLANE_GB2312 0x70f20000 /* 2121h - 7E7Eh */ -#define MBFL_WCSPLANE_WINCP936 0x70f30000 /* 2121h - 9898h */ -#define MBFL_WCSPLANE_BIG5 0x70f40000 /* 2121h - 9898h */ -#define MBFL_WCSPLANE_CNS11643 0x70f50000 /* 2121h - 9898h */ -#define MBFL_WCSPLANE_UHC 0x70f60000 /* 8141h - fefeh */ -#define MBFL_WCSPLANE_GB18030 0x70ff0000 /* a1a1h-e3329a35h */ -#define MBFL_WCSGROUP_MASK 0xffffff -#define MBFL_WCSGROUP_UCS4MAX 0x70000000 -#define MBFL_WCSGROUP_WCHARMAX 0x78000000 -#define MBFL_WCSGROUP_THROUGH 0x78000000 /* 000000h - FFFFFFh */ + +/* Marker for an erroneous input byte (or sequence of bytes) */ +#define MBFL_BAD_INPUT (-1) #define MBFL_QPRINT_STS_MIME_HEADER 0x1000000 #define MBFL_BASE64_STS_MIME_HEADER 0x1000000 diff --git a/ext/mbstring/libmbfl/mbfl/mbfl_convert.c b/ext/mbstring/libmbfl/mbfl/mbfl_convert.c index 34a02c5042a..5bc86ba179e 100644 --- a/ext/mbstring/libmbfl/mbfl/mbfl_convert.c +++ b/ext/mbstring/libmbfl/mbfl/mbfl_convert.c @@ -262,43 +262,18 @@ int mbfl_filt_conv_illegal_output(int c, mbfl_convert_filter *filter) break; case MBFL_OUTPUTFILTER_ILLEGAL_MODE_LONG: - if (w < MBFL_WCSGROUP_UCS4MAX) { /* Unicode */ + if (w != MBFL_BAD_INPUT) { ret = mbfl_convert_filter_strcat(filter, (const unsigned char *)"U+"); - } else if (w < MBFL_WCSGROUP_WCHARMAX) { - int m = w & ~MBFL_WCSPLANE_MASK; - switch (m) { - case MBFL_WCSPLANE_JIS0208: - ret = mbfl_convert_filter_strcat(filter, (const unsigned char *)"JIS+"); + if (ret < 0) break; - case MBFL_WCSPLANE_JIS0212: - ret = mbfl_convert_filter_strcat(filter, (const unsigned char *)"JIS2+"); - break; - case MBFL_WCSPLANE_JIS0213: - ret = mbfl_convert_filter_strcat(filter, (const unsigned char *)"JIS3+"); - break; - case MBFL_WCSPLANE_WINCP932: - ret = mbfl_convert_filter_strcat(filter, (const unsigned char *)"W932+"); - break; - case MBFL_WCSPLANE_GB18030: - ret = mbfl_convert_filter_strcat(filter, (const unsigned char *)"GB+"); - break; - default: - ret = mbfl_convert_filter_strcat(filter, (const unsigned char *)"?+"); - break; - } - w &= MBFL_WCSPLANE_MASK; - } else { - ret = mbfl_convert_filter_strcat(filter, (const unsigned char *)"BAD+"); - w &= MBFL_WCSGROUP_MASK; - } - - if (ret >= 0) { ret = mbfl_filt_conv_output_hex(w, filter); + } else { + ret = (*filter->filter_function)(substchar_backup, filter); } break; case MBFL_OUTPUTFILTER_ILLEGAL_MODE_ENTITY: - if (w < MBFL_WCSGROUP_UCS4MAX) { /* unicode */ + if (w != MBFL_BAD_INPUT) { ret = mbfl_convert_filter_strcat(filter, (const unsigned char *)"&#x"); if (ret < 0) break; diff --git a/ext/mbstring/libmbfl/mbfl/mbfl_filter_output.c b/ext/mbstring/libmbfl/mbfl/mbfl_filter_output.c index ab2b2fc09e6..aab0a17daa9 100644 --- a/ext/mbstring/libmbfl/mbfl/mbfl_filter_output.c +++ b/ext/mbstring/libmbfl/mbfl/mbfl_filter_output.c @@ -39,5 +39,5 @@ int mbfl_filter_output_pipe(int c, void* data) int mbfl_filter_output_null(int c, void* data) { - return c; + return 0; } diff --git a/ext/mbstring/libmbfl/mbfl/mbfl_memory_device.c b/ext/mbstring/libmbfl/mbfl/mbfl_memory_device.c index cd064e5ee8f..7fbe4e703bb 100644 --- a/ext/mbstring/libmbfl/mbfl/mbfl_memory_device.c +++ b/ext/mbstring/libmbfl/mbfl/mbfl_memory_device.c @@ -103,7 +103,7 @@ int mbfl_memory_device_output(int c, void *data) } device->buffer[device->pos++] = (unsigned char)c; - return c; + return 0; } int mbfl_memory_device_strcat(mbfl_memory_device *device, const char *psrc) @@ -180,5 +180,5 @@ int mbfl_wchar_device_output(int c, void *data) } device->buffer[device->pos++] = c; - return c; + return 0; } diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c index 020ef6b197a..75c35e80ef4 100644 --- a/ext/mbstring/mbstring.c +++ b/ext/mbstring/mbstring.c @@ -3854,10 +3854,10 @@ PHP_FUNCTION(mb_get_info) static int mbfl_filt_check_errors(int c, void* data) { - if (c & MBFL_WCSGROUP_THROUGH) { + if (c == MBFL_BAD_INPUT) { (*((mbfl_convert_filter**)data))->num_illegalchar++; } - return c; + return 0; } MBSTRING_API int php_mb_check_encoding(const char *input, size_t length, const mbfl_encoding *encoding) @@ -3995,13 +3995,12 @@ static inline zend_long php_mb_ord(const char *str, size_t str_len, zend_string mbfl_convert_filter_feed_string(filter, (unsigned char*)str, str_len); mbfl_convert_filter_flush(filter); - if (dev.pos < 1 || filter->num_illegalchar || dev.buffer[0] >= MBFL_WCSGROUP_UCS4MAX) { - mbfl_convert_filter_delete(filter); - mbfl_wchar_device_clear(&dev); - return -1; + if (dev.pos < 1 || filter->num_illegalchar || dev.buffer[0] == MBFL_BAD_INPUT) { + cp = -1; + } else { + cp = dev.buffer[0]; } - cp = dev.buffer[0]; mbfl_convert_filter_delete(filter); mbfl_wchar_device_clear(&dev); return cp; diff --git a/ext/mbstring/tests/armscii8_encoding.phpt b/ext/mbstring/tests/armscii8_encoding.phpt index 161fd049c25..37af3820e92 100644 --- a/ext/mbstring/tests/armscii8_encoding.phpt +++ b/ext/mbstring/tests/armscii8_encoding.phpt @@ -30,8 +30,8 @@ echo "Tested UTF-16BE -> ARMSCII-8\n"; // Test "long" illegal character markers mb_substitute_character("long"); -convertInvalidString("\xA1", "BAD+A1", "ARMSCII-8", "UTF-8"); -convertInvalidString("\xFF", "BAD+FF", "ARMSCII-8", "UTF-8"); +convertInvalidString("\xA1", "%", "ARMSCII-8", "UTF-8"); +convertInvalidString("\xFF", "%", "ARMSCII-8", "UTF-8"); echo "Done!\n"; ?> diff --git a/ext/mbstring/tests/big5_encoding.phpt b/ext/mbstring/tests/big5_encoding.phpt index 2405a302b18..99bfd7e565b 100644 --- a/ext/mbstring/tests/big5_encoding.phpt +++ b/ext/mbstring/tests/big5_encoding.phpt @@ -36,9 +36,9 @@ echo "Tested UTF-16BE -> BIG5\n"; // Test "long" illegal character markers mb_substitute_character("long"); -convertInvalidString("\x80", "BAD+80", "BIG5", "UTF-8"); -convertInvalidString("\xB0\x9F", "BAD+B09F", "BIG5", "UTF-8"); -convertInvalidString("\xA3\xED", "?+A3ED", "BIG5", "UTF-8"); +convertInvalidString("\x80", "%", "BIG5", "UTF-8"); +convertInvalidString("\xB0\x9F", "%", "BIG5", "UTF-8"); +convertInvalidString("\xA3\xED", "%", "BIG5", "UTF-8"); convertInvalidString("\x76\x54", "U+7654", "UTF-16BE", "BIG5"); echo "Done!\n"; diff --git a/ext/mbstring/tests/cp1251_encoding.phpt b/ext/mbstring/tests/cp1251_encoding.phpt index df0191afbe4..e1b612b4481 100644 --- a/ext/mbstring/tests/cp1251_encoding.phpt +++ b/ext/mbstring/tests/cp1251_encoding.phpt @@ -13,7 +13,7 @@ testEncodingFromUTF16ConversionTable(__DIR__ . '/data/CP1251.txt', 'CP1251'); // Test "long" illegal character markers mb_substitute_character("long"); -convertInvalidString("\x98", "BAD+98", "CP1251", "UTF-8"); +convertInvalidString("\x98", "%", "CP1251", "UTF-8"); convertInvalidString("\x12\x34", "U+1234", "UTF-16BE", "CP1251"); echo "Done!\n"; diff --git a/ext/mbstring/tests/cp1252_encoding.phpt b/ext/mbstring/tests/cp1252_encoding.phpt index 8d2649580c0..706e02ceee6 100644 --- a/ext/mbstring/tests/cp1252_encoding.phpt +++ b/ext/mbstring/tests/cp1252_encoding.phpt @@ -13,8 +13,8 @@ testEncodingFromUTF16ConversionTable(__DIR__ . '/data/CP1252.txt', 'CP1252'); // Test "long" illegal character markers mb_substitute_character("long"); -convertInvalidString("\x81", "BAD+81", "CP1252", "UTF-8"); -convertInvalidString("\x9D", "BAD+9D", "CP1252", "UTF-8"); +convertInvalidString("\x81", "%", "CP1252", "UTF-8"); +convertInvalidString("\x9D", "%", "CP1252", "UTF-8"); echo "Done!\n"; ?> diff --git a/ext/mbstring/tests/cp1254_encoding.phpt b/ext/mbstring/tests/cp1254_encoding.phpt index efd4d868c60..7a4f7be2b18 100644 --- a/ext/mbstring/tests/cp1254_encoding.phpt +++ b/ext/mbstring/tests/cp1254_encoding.phpt @@ -13,8 +13,8 @@ testEncodingFromUTF16ConversionTable(__DIR__ . '/data/CP1254.txt', 'CP1254'); // Test "long" illegal character markers mb_substitute_character("long"); -convertInvalidString("\x81", "BAD+81", "CP1254", "UTF-8"); -convertInvalidString("\x9E", "BAD+9E", "CP1254", "UTF-8"); +convertInvalidString("\x81", "%", "CP1254", "UTF-8"); +convertInvalidString("\x9E", "%", "CP1254", "UTF-8"); echo "Done!\n"; ?> diff --git a/ext/mbstring/tests/cp5022x_encoding.phpt b/ext/mbstring/tests/cp5022x_encoding.phpt index 939dcc60627..314dcf07c0c 100644 --- a/ext/mbstring/tests/cp5022x_encoding.phpt +++ b/ext/mbstring/tests/cp5022x_encoding.phpt @@ -294,12 +294,12 @@ echo "Invalid Unicode is flagged when converting to CP5022x\n"; // Test "long" illegal character markers mb_substitute_character("long"); -convertInvalidString("\x80", "BAD+80", "CP50220", "UTF-8"); -convertInvalidString("\x80", "BAD+80", "CP50221", "UTF-8"); -convertInvalidString("\x80", "BAD+80", "CP50222", "UTF-8"); -convertInvalidString("\x1B\$B1", "BAD+31", "CP50220", "UTF-8"); -convertInvalidString("\x1B\$B1", "BAD+31", "CP50221", "UTF-8"); -convertInvalidString("\x1B\$B1", "BAD+31", "CP50222", "UTF-8"); +convertInvalidString("\x80", "%", "CP50220", "UTF-8"); +convertInvalidString("\x80", "%", "CP50221", "UTF-8"); +convertInvalidString("\x80", "%", "CP50222", "UTF-8"); +convertInvalidString("\x1B\$B1", "%", "CP50220", "UTF-8"); +convertInvalidString("\x1B\$B1", "%", "CP50221", "UTF-8"); +convertInvalidString("\x1B\$B1", "%", "CP50222", "UTF-8"); echo "Long error markers OK\n"; ?> diff --git a/ext/mbstring/tests/cp51932_encoding.phpt b/ext/mbstring/tests/cp51932_encoding.phpt index 3603702104f..83961d97588 100644 --- a/ext/mbstring/tests/cp51932_encoding.phpt +++ b/ext/mbstring/tests/cp51932_encoding.phpt @@ -111,8 +111,8 @@ echo "Unicode -> CP51932 conversion works on all invalid codepoints\n"; // Test "long" illegal character markers mb_substitute_character("long"); -convertInvalidString("\x80", "BAD+80", "CP51932", "UTF-8"); -convertInvalidString("\xFE\xFF", "BAD+FEFF", "CP51932", "UTF-8"); +convertInvalidString("\x80", "%", "CP51932", "UTF-8"); +convertInvalidString("\xFE\xFF", "%", "CP51932", "UTF-8"); echo "Done!\n"; ?> diff --git a/ext/mbstring/tests/cp932_encoding.phpt b/ext/mbstring/tests/cp932_encoding.phpt index 44e746881a1..ff7bd9cfcdc 100644 --- a/ext/mbstring/tests/cp932_encoding.phpt +++ b/ext/mbstring/tests/cp932_encoding.phpt @@ -108,10 +108,10 @@ echo "Unicode -> CP932 conversion works on all invalid codepoints\n"; // Test "long" illegal character markers mb_substitute_character("long"); -convertInvalidString("\x80", "BAD+80", "CP932", "UTF-8"); -convertInvalidString("\xEA", "BAD+EA", "CP932", "UTF-8"); -convertInvalidString("\x81\x20", "BAD+8120", "CP932", "UTF-8"); -convertInvalidString("\xEA\xA9", "W932+742B", "CP932", "UTF-8"); +convertInvalidString("\x80", "%", "CP932", "UTF-8"); +convertInvalidString("\xEA", "%", "CP932", "UTF-8"); +convertInvalidString("\x81\x20", "%", "CP932", "UTF-8"); +convertInvalidString("\xEA\xA9", "%", "CP932", "UTF-8"); echo "Done!\n"; ?> diff --git a/ext/mbstring/tests/cp936_encoding.phpt b/ext/mbstring/tests/cp936_encoding.phpt index 092219d9252..3b0d735e926 100644 --- a/ext/mbstring/tests/cp936_encoding.phpt +++ b/ext/mbstring/tests/cp936_encoding.phpt @@ -326,9 +326,9 @@ echo "Tested UTF-16BE -> CP936\n"; // Test "long" illegal character markers mb_substitute_character("long"); -convertInvalidString("\x81\x20", "BAD+8120", "CP936", "UTF-8"); -convertInvalidString("\x81\x7F", "BAD+817F", "CP936", "UTF-8"); -convertInvalidString("\xFE\xFF", "BAD+FEFF", "CP936", "UTF-8"); +convertInvalidString("\x81\x20", "%", "CP936", "UTF-8"); +convertInvalidString("\x81\x7F", "%", "CP936", "UTF-8"); +convertInvalidString("\xFE\xFF", "%", "CP936", "UTF-8"); echo "Done!\n"; ?> diff --git a/ext/mbstring/tests/cp950_encoding.phpt b/ext/mbstring/tests/cp950_encoding.phpt index 5ea28414d07..70bc1760528 100644 --- a/ext/mbstring/tests/cp950_encoding.phpt +++ b/ext/mbstring/tests/cp950_encoding.phpt @@ -78,7 +78,7 @@ echo "Tested UTF-16BE -> CP950\n"; // Test "long" illegal character markers mb_substitute_character("long"); -convertInvalidString("\x80", "BAD+80", "CP950", "UTF-8"); +convertInvalidString("\x80", "%", "CP950", "UTF-8"); convertInvalidString("\x26\x09", "U+2609", "UTF-16BE", "CP950"); echo "Done!\n"; diff --git a/ext/mbstring/tests/euc_cn_encoding.phpt b/ext/mbstring/tests/euc_cn_encoding.phpt index 8c4e4b8aa93..67a9af3f01d 100644 --- a/ext/mbstring/tests/euc_cn_encoding.phpt +++ b/ext/mbstring/tests/euc_cn_encoding.phpt @@ -13,9 +13,9 @@ testEncodingFromUTF16ConversionTable(__DIR__ . '/data/EUC-CN.txt', 'EUC-CN'); // Test "long" illegal character markers mb_substitute_character("long"); -convertInvalidString("\x80", "BAD+80", "EUC-CN", "UTF-8"); -convertInvalidString("\xA1\x50", "BAD+A150", "EUC-CN", "UTF-8"); -convertInvalidString("\xF7\xFF", "BAD+F7FF", "EUC-CN", "UTF-8"); +convertInvalidString("\x80", "%", "EUC-CN", "UTF-8"); +convertInvalidString("\xA1\x50", "%", "EUC-CN", "UTF-8"); +convertInvalidString("\xF7\xFF", "%", "EUC-CN", "UTF-8"); echo "Done!\n"; ?> diff --git a/ext/mbstring/tests/euc_kr_encoding.phpt b/ext/mbstring/tests/euc_kr_encoding.phpt index 115cff1c51e..91671523ad1 100644 --- a/ext/mbstring/tests/euc_kr_encoding.phpt +++ b/ext/mbstring/tests/euc_kr_encoding.phpt @@ -13,8 +13,8 @@ testEncodingFromUTF16ConversionTable(__DIR__ . '/data/EUC-KR.txt', 'EUC-KR'); // Test "long" illegal character markers mb_substitute_character("long"); -convertInvalidString("\x80", "BAD+80", "EUC-KR", "UTF-8"); -convertInvalidString("\xA7\xF0", "?+A7F0", "EUC-KR", "UTF-8"); +convertInvalidString("\x80", "%", "EUC-KR", "UTF-8"); +convertInvalidString("\xA7\xF0", "%", "EUC-KR", "UTF-8"); echo "Done!\n"; ?> diff --git a/ext/mbstring/tests/euc_tw_encoding.phpt b/ext/mbstring/tests/euc_tw_encoding.phpt index b54353f234e..720c279d2c4 100644 --- a/ext/mbstring/tests/euc_tw_encoding.phpt +++ b/ext/mbstring/tests/euc_tw_encoding.phpt @@ -27,14 +27,14 @@ echo "Tested UTF-16BE -> EUC-TW\n"; // Test "long" illegal character markers mb_substitute_character("long"); -convertInvalidString("\x80", "BAD+80", "EUC-TW", "UTF-8"); -convertInvalidString("\x8E\x20", "BAD+8E20", "EUC-TW", "UTF-8"); -convertInvalidString("\x8E\xA1\x20", "BAD+8EA120", "EUC-TW", "UTF-8"); -convertInvalidString("\x8E\xA1\xA1\x20", "BAD+A1A120", "EUC-TW", "UTF-8"); -convertInvalidString("\x8E\xA2\xA3\x20", "BAD+A2A320", "EUC-TW", "UTF-8"); -convertInvalidString("\x8F", "BAD+8F", "EUC-TW", "UTF-8"); -convertInvalidString("\xA1\x50", "BAD+A150", "EUC-TW", "UTF-8"); -convertInvalidString("\xFD\xCC", "?+FDCC", "EUC-TW", "UTF-8"); +convertInvalidString("\x80", "%", "EUC-TW", "UTF-8"); +convertInvalidString("\x8E\x20", "%", "EUC-TW", "UTF-8"); +convertInvalidString("\x8E\xA1\x20", "%", "EUC-TW", "UTF-8"); +convertInvalidString("\x8E\xA1\xA1\x20", "%", "EUC-TW", "UTF-8"); +convertInvalidString("\x8E\xA2\xA3\x20", "%", "EUC-TW", "UTF-8"); +convertInvalidString("\x8F", "%", "EUC-TW", "UTF-8"); +convertInvalidString("\xA1\x50", "%", "EUC-TW", "UTF-8"); +convertInvalidString("\xFD\xCC", "%", "EUC-TW", "UTF-8"); echo "Done!\n"; ?> diff --git a/ext/mbstring/tests/eucjp_2004_encoding.phpt b/ext/mbstring/tests/eucjp_2004_encoding.phpt index 5f4c8769afa..62671d10f8f 100644 --- a/ext/mbstring/tests/eucjp_2004_encoding.phpt +++ b/ext/mbstring/tests/eucjp_2004_encoding.phpt @@ -72,8 +72,8 @@ echo "Unicode -> EUC-JP-2004 conversion works on all invalid characters\n"; // Test "long" illegal character markers mb_substitute_character("long"); -convertInvalidString("\x80", "BAD+80", "EUC-JP-2004", "UTF-8"); -convertInvalidString("\xFE\xFF", "BAD+FEFF", "EUC-JP-2004", "UTF-8"); +convertInvalidString("\x80", "%", "EUC-JP-2004", "UTF-8"); +convertInvalidString("\xFE\xFF", "%", "EUC-JP-2004", "UTF-8"); echo "Done!\n"; ?> diff --git a/ext/mbstring/tests/eucjp_encoding.phpt b/ext/mbstring/tests/eucjp_encoding.phpt index 87537a93bc8..ce24ce357ff 100644 --- a/ext/mbstring/tests/eucjp_encoding.phpt +++ b/ext/mbstring/tests/eucjp_encoding.phpt @@ -79,8 +79,8 @@ echo "Unicode -> EUC-JP conversion works on all invalid characters\n"; // Test "long" illegal character markers mb_substitute_character("long"); -convertInvalidString("\x80", "BAD+80", "EUC-JP", "UTF-8"); -convertInvalidString("\xFE\xFF", "BAD+FEFF", "EUC-JP", "UTF-8"); +convertInvalidString("\x80", "%", "EUC-JP", "UTF-8"); +convertInvalidString("\xFE\xFF", "%", "EUC-JP", "UTF-8"); echo "Done!\n"; ?> diff --git a/ext/mbstring/tests/eucjp_ms_encoding.phpt b/ext/mbstring/tests/eucjp_ms_encoding.phpt index 841ada6b041..e17b28ab1e3 100644 --- a/ext/mbstring/tests/eucjp_ms_encoding.phpt +++ b/ext/mbstring/tests/eucjp_ms_encoding.phpt @@ -56,8 +56,8 @@ echo "Tested UTF-16BE -> eucJP-win\n"; // Test "long" illegal character markers mb_substitute_character("long"); -convertInvalidString("\x80", "BAD+80", "eucJP-win", "UTF-8"); -convertInvalidString("\xFE\xFF", "BAD+FEFF", "eucJP-win", "UTF-8"); +convertInvalidString("\x80", "%", "eucJP-win", "UTF-8"); +convertInvalidString("\xFE\xFF", "%", "eucJP-win", "UTF-8"); ?> --EXPECT-- diff --git a/ext/mbstring/tests/gb18030_encoding.phpt b/ext/mbstring/tests/gb18030_encoding.phpt index d7e15751ab8..be60a7e6d86 100644 --- a/ext/mbstring/tests/gb18030_encoding.phpt +++ b/ext/mbstring/tests/gb18030_encoding.phpt @@ -302,8 +302,8 @@ echo "Tested UTF-16BE -> GB18030 (1 and 2 byte characters)\n"; // Test "long" illegal character markers mb_substitute_character("long"); -convertInvalidString("\x81\x30\x81\xFF", "BAD+3081FF", "GB18030", "UTF-8"); -convertInvalidString("\xE3\x32\x9A\x36", "BAD+329A36", "GB18030", "UTF-8"); +convertInvalidString("\x81\x30\x81\xFF", "%", "GB18030", "UTF-8"); +convertInvalidString("\xE3\x32\x9A\x36", "%", "GB18030", "UTF-8"); echo "Done!\n"; ?> diff --git a/ext/mbstring/tests/hz_encoding.phpt b/ext/mbstring/tests/hz_encoding.phpt index a46852f8460..665980c9c7f 100644 --- a/ext/mbstring/tests/hz_encoding.phpt +++ b/ext/mbstring/tests/hz_encoding.phpt @@ -120,9 +120,9 @@ echo "Tested UTF-16BE -> HZ (for all GB2312 characters)\n"; // Test "long" illegal character markers mb_substitute_character("long"); -convertInvalidString("~A", "BAD+41", "HZ", "UTF-8"); -convertInvalidString("\x80", "BAD+80", "HZ", "UTF-8"); -convertInvalidString("~{\x22\x21", "?+2221", "HZ", "UTF-8"); +convertInvalidString("~A", "%", "HZ", "UTF-8"); +convertInvalidString("\x80", "%", "HZ", "UTF-8"); +convertInvalidString("~{\x22\x21", "%", "HZ", "UTF-8"); echo "Done!\n"; ?> diff --git a/ext/mbstring/tests/iso2022jp_2004_encoding.phpt b/ext/mbstring/tests/iso2022jp_2004_encoding.phpt index 24e808c566b..078881db5a9 100644 --- a/ext/mbstring/tests/iso2022jp_2004_encoding.phpt +++ b/ext/mbstring/tests/iso2022jp_2004_encoding.phpt @@ -316,9 +316,9 @@ for ($i = 0; $i < 100; $i++) { // Test "long" illegal character markers mb_substitute_character("long"); -convertInvalidString("\xE0", "BAD+E0", "ISO-2022-JP-2004", "UTF-8"); -convertInvalidString("\x1B\$(X", "BAD+1B2428", "ISO-2022-JP-2004", "UTF-8"); // Invalid escape -convertInvalidString("\x1B\$B!", "BAD+21", "ISO-2022-JP-2004", "UTF-8"); // Truncated character +convertInvalidString("\xE0", "%", "ISO-2022-JP-2004", "UTF-8"); +convertInvalidString("\x1B\$(X", "%", "ISO-2022-JP-2004", "UTF-8"); // Invalid escape +convertInvalidString("\x1B\$B!", "%", "ISO-2022-JP-2004", "UTF-8"); // Truncated character echo "All done!\n"; diff --git a/ext/mbstring/tests/iso2022jp_encoding.phpt b/ext/mbstring/tests/iso2022jp_encoding.phpt index 72ce60e6cb9..54653d1bbf7 100644 --- a/ext/mbstring/tests/iso2022jp_encoding.phpt +++ b/ext/mbstring/tests/iso2022jp_encoding.phpt @@ -201,12 +201,12 @@ echo "Other mappings from Unicode -> ISO-2022-JP are OK\n"; // Test "long" illegal character markers mb_substitute_character("long"); -convertInvalidString("\xE0", "BAD+E0", "JIS", "UTF-8"); -convertInvalidString("\xE0", "BAD+E0", "ISO-2022-JP", "UTF-8"); -convertInvalidString("\x1B\$(X", "BAD+1B\$(X", "JIS", "UTF-8"); // Invalid escape -convertInvalidString("\x1B\$(X", "BAD+1B\$(X", "ISO-2022-JP", "UTF-8"); // Invalid escape -convertInvalidString("\x1B\$B!", "BAD+21", "JIS", "UTF-8"); // Truncated character -convertInvalidString("\x1B\$B!", "BAD+21", "ISO-2022-JP", "UTF-8"); // Truncated character +convertInvalidString("\xE0", "%", "JIS", "UTF-8"); +convertInvalidString("\xE0", "%", "ISO-2022-JP", "UTF-8"); +convertInvalidString("\x1B\$(X", "%\$(X", "JIS", "UTF-8"); // Invalid escape +convertInvalidString("\x1B\$(X", "%\$(X", "ISO-2022-JP", "UTF-8"); // Invalid escape +convertInvalidString("\x1B\$B!", "%", "JIS", "UTF-8"); // Truncated character +convertInvalidString("\x1B\$B!", "%", "ISO-2022-JP", "UTF-8"); // Truncated character echo "Done!\n"; ?> diff --git a/ext/mbstring/tests/iso2022jp_kddi_encoding.phpt b/ext/mbstring/tests/iso2022jp_kddi_encoding.phpt index e27a58ea053..6a0246b7bf0 100644 --- a/ext/mbstring/tests/iso2022jp_kddi_encoding.phpt +++ b/ext/mbstring/tests/iso2022jp_kddi_encoding.phpt @@ -207,14 +207,14 @@ echo "Other mappings from Unicode -> ISO-2022-JP-KDDI OK\n"; // Test "long" illegal character markers mb_substitute_character("long"); -convertInvalidString("\xE0", "BAD+E0", "ISO-2022-JP-KDDI", "UTF-8"); +convertInvalidString("\xE0", "%", "ISO-2022-JP-KDDI", "UTF-8"); // Invalid escapes: -convertInvalidString("\x1B", "BAD+1B", "ISO-2022-JP-KDDI", "UTF-8"); -convertInvalidString("\x1B.", "BAD+1B2E", "ISO-2022-JP-KDDI", "UTF-8"); -convertInvalidString("\x1B\$", "BAD+1B24", "ISO-2022-JP-KDDI", "UTF-8"); -convertInvalidString("\x1B\$.", "BAD+1B242E", "ISO-2022-JP-KDDI", "UTF-8"); -convertInvalidString("\x1B\$(X", "BAD+242858", "ISO-2022-JP-KDDI", "UTF-8"); -convertInvalidString("\x1B\$B\x9F", "BAD+9F", "ISO-2022-JP-KDDI", "UTF-8"); // 0x9F does not start any 2-byte character +convertInvalidString("\x1B", "%", "ISO-2022-JP-KDDI", "UTF-8"); +convertInvalidString("\x1B.", "%", "ISO-2022-JP-KDDI", "UTF-8"); +convertInvalidString("\x1B\$", "%", "ISO-2022-JP-KDDI", "UTF-8"); +convertInvalidString("\x1B\$.", "%", "ISO-2022-JP-KDDI", "UTF-8"); +convertInvalidString("\x1B\$(X", "%", "ISO-2022-JP-KDDI", "UTF-8"); +convertInvalidString("\x1B\$B\x9F", "%", "ISO-2022-JP-KDDI", "UTF-8"); // 0x9F does not start any 2-byte character convertInvalidString("\xE0\x00", "U+E000", "UTF-16BE", "ISO-2022-JP-KDDI"); echo "Done!\n"; diff --git a/ext/mbstring/tests/iso2022jp_ms_encoding.phpt b/ext/mbstring/tests/iso2022jp_ms_encoding.phpt index ef384610552..21699487ec0 100644 --- a/ext/mbstring/tests/iso2022jp_ms_encoding.phpt +++ b/ext/mbstring/tests/iso2022jp_ms_encoding.phpt @@ -211,17 +211,17 @@ testValidString("\x00a\x00b\x00c\xFF\x61\x00a\x00b\x00c", "abc\x1B(I\x21\x1B(Bab // Test "long" illegal character markers mb_substitute_character("long"); -convertInvalidString("\xE0", "BAD+E0", "ISO-2022-JP-MS", "UTF-8"); +convertInvalidString("\xE0", "%", "ISO-2022-JP-MS", "UTF-8"); // Invalid escapes: -convertInvalidString("\x1B", "BAD+1B", "ISO-2022-JP-MS", "UTF-8"); -convertInvalidString("\x1B.", "BAD+1B2E", "ISO-2022-JP-MS", "UTF-8"); -convertInvalidString("\x1B\$", "BAD+1B24", "ISO-2022-JP-MS", "UTF-8"); -convertInvalidString("\x1B\$.", "BAD+1B242E", "ISO-2022-JP-MS", "UTF-8"); -convertInvalidString("\x1B(", "BAD+1B28", "ISO-2022-JP-MS", "UTF-8"); -convertInvalidString("\x1B(.", "BAD+1B282E", "ISO-2022-JP-MS", "UTF-8"); -convertInvalidString("\x1B\$(", "BAD+1B2428", "ISO-2022-JP-MS", "UTF-8"); -convertInvalidString("\x1B\$(X", "BAD+242858", "ISO-2022-JP-MS", "UTF-8"); -convertInvalidString("\x1B\$B\x9F", "BAD+9F", "ISO-2022-JP-MS", "UTF-8"); // 0x9F does not start any 2-byte character +convertInvalidString("\x1B", "%", "ISO-2022-JP-MS", "UTF-8"); +convertInvalidString("\x1B.", "%", "ISO-2022-JP-MS", "UTF-8"); +convertInvalidString("\x1B\$", "%", "ISO-2022-JP-MS", "UTF-8"); +convertInvalidString("\x1B\$.", "%", "ISO-2022-JP-MS", "UTF-8"); +convertInvalidString("\x1B(", "%", "ISO-2022-JP-MS", "UTF-8"); +convertInvalidString("\x1B(.", "%", "ISO-2022-JP-MS", "UTF-8"); +convertInvalidString("\x1B\$(", "%", "ISO-2022-JP-MS", "UTF-8"); +convertInvalidString("\x1B\$(X", "%", "ISO-2022-JP-MS", "UTF-8"); +convertInvalidString("\x1B\$B\x9F", "%", "ISO-2022-JP-MS", "UTF-8"); // 0x9F does not start any 2-byte character echo "Done!\n"; ?> diff --git a/ext/mbstring/tests/iso2022kr_encoding.phpt b/ext/mbstring/tests/iso2022kr_encoding.phpt index 34187588fa8..05f00493bcf 100644 --- a/ext/mbstring/tests/iso2022kr_encoding.phpt +++ b/ext/mbstring/tests/iso2022kr_encoding.phpt @@ -98,10 +98,10 @@ echo "Escapes behave as expected\n"; // Test "long" illegal character markers mb_substitute_character("long"); -convertInvalidString("\x1B", "BAD+1B", "ISO-2022-KR", "UTF-8"); -convertInvalidString("\x1B$", "BAD+1B24", "ISO-2022-KR", "UTF-8"); -convertInvalidString("\x1B$)", "BAD+1B2429", "ISO-2022-KR", "UTF-8"); -convertInvalidString("\x1B$)C\x0E\x7C\x84", "BAD+7C84", "ISO-2022-KR", "UTF-8"); +convertInvalidString("\x1B", "%", "ISO-2022-KR", "UTF-8"); +convertInvalidString("\x1B$", "%", "ISO-2022-KR", "UTF-8"); +convertInvalidString("\x1B$)", "%", "ISO-2022-KR", "UTF-8"); +convertInvalidString("\x1B$)C\x0E\x7C\x84", "%", "ISO-2022-KR", "UTF-8"); echo "Done!\n"; ?> diff --git a/ext/mbstring/tests/iso8859_encodings.phpt b/ext/mbstring/tests/iso8859_encodings.phpt index 9721d370e44..fac7ce8c0ea 100644 --- a/ext/mbstring/tests/iso8859_encodings.phpt +++ b/ext/mbstring/tests/iso8859_encodings.phpt @@ -18,8 +18,8 @@ for ($n = 1; $n <= 16; $n++) { // Test "long" illegal character markers mb_substitute_character("long"); -convertInvalidString("\xAE", "BAD+AE", "ISO8859-7", "UTF-8"); -convertInvalidString("\xFF", "BAD+FF", "ISO8859-8", "UTF-8"); +convertInvalidString("\xAE", "%", "ISO8859-7", "UTF-8"); +convertInvalidString("\xFF", "%", "ISO8859-8", "UTF-8"); echo "Done!\n"; ?> diff --git a/ext/mbstring/tests/other_encodings.phpt b/ext/mbstring/tests/other_encodings.phpt index cb7cbdeff08..4a62966be50 100644 --- a/ext/mbstring/tests/other_encodings.phpt +++ b/ext/mbstring/tests/other_encodings.phpt @@ -52,5 +52,5 @@ UCS-2 done 3001 3002 3003 -BAD+20300 +% UCS-4 done diff --git a/ext/mbstring/tests/sjis2004_encoding.phpt b/ext/mbstring/tests/sjis2004_encoding.phpt index 3ced8237651..eee87240cae 100644 --- a/ext/mbstring/tests/sjis2004_encoding.phpt +++ b/ext/mbstring/tests/sjis2004_encoding.phpt @@ -68,9 +68,9 @@ convertValidString("\x30\x4B\x00A", "\x82\xA9A", 'UTF-16BE', 'SJIS-2004', false) // Test "long" illegal character markers mb_substitute_character("long"); -convertInvalidString("\x80", "BAD+80", "SJIS-2004", "UTF-8"); -convertInvalidString("\x81\x20", "BAD+8120", "SJIS-2004", "UTF-8"); -convertInvalidString("\xFC\xF5", "BAD+FCF5", "SJIS-2004", "UTF-8"); +convertInvalidString("\x80", "%", "SJIS-2004", "UTF-8"); +convertInvalidString("\x81\x20", "%", "SJIS-2004", "UTF-8"); +convertInvalidString("\xFC\xF5", "%", "SJIS-2004", "UTF-8"); echo "Done!\n"; ?> diff --git a/ext/mbstring/tests/sjis_encoding.phpt b/ext/mbstring/tests/sjis_encoding.phpt index 4dbc945da85..aece04b0f22 100644 --- a/ext/mbstring/tests/sjis_encoding.phpt +++ b/ext/mbstring/tests/sjis_encoding.phpt @@ -65,9 +65,9 @@ echo "Other mappings from Unicode -> SJIS are OK\n"; // Test "long" illegal character markers mb_substitute_character("long"); -convertInvalidString("\x80", "BAD+80", "Shift-JIS", "UTF-8"); -convertInvalidString("\x81\x20", "BAD+8120", "Shift-JIS", "UTF-8"); -convertInvalidString("\xEA\xA9", "JIS+742B", "Shift-JIS", "UTF-8"); +convertInvalidString("\x80", "%", "Shift-JIS", "UTF-8"); +convertInvalidString("\x81\x20", "%", "Shift-JIS", "UTF-8"); +convertInvalidString("\xEA\xA9", "%", "Shift-JIS", "UTF-8"); echo "Done!\n"; ?> diff --git a/ext/mbstring/tests/sjis_mobile_encodings.phpt b/ext/mbstring/tests/sjis_mobile_encodings.phpt index e6999d5a44c..2e6af579ee2 100644 --- a/ext/mbstring/tests/sjis_mobile_encodings.phpt +++ b/ext/mbstring/tests/sjis_mobile_encodings.phpt @@ -280,9 +280,9 @@ function testSJISVariant($validChars, $nonInvertible, $encoding) { // Test "long" illegal character markers mb_substitute_character("long"); - convertInvalidString("\x80", "BAD+80", $encoding, "UTF-8"); - convertInvalidString("\x81\x20", "BAD+8120", $encoding, "UTF-8"); - convertInvalidString("\xEA\xA9", "W932+742B", $encoding, "UTF-8"); + convertInvalidString("\x80", "%", $encoding, "UTF-8"); + convertInvalidString("\x81\x20", "%", $encoding, "UTF-8"); + convertInvalidString("\xEA\xA9", "%", $encoding, "UTF-8"); mb_substitute_character(0x25); // '%' // Test Regional Indicator codepoint at end of string diff --git a/ext/mbstring/tests/sjismac_encoding.phpt b/ext/mbstring/tests/sjismac_encoding.phpt index 51c08463f21..1e80800928a 100644 --- a/ext/mbstring/tests/sjismac_encoding.phpt +++ b/ext/mbstring/tests/sjismac_encoding.phpt @@ -89,9 +89,9 @@ echo "Unicode -> SJIS-mac conversion works on all invalid characters\n"; // Test "long" illegal character markers mb_substitute_character("long"); -convertInvalidString("\x81", "BAD+81", "SJIS-mac", "UTF-8"); -convertInvalidString("\x81\x20", "BAD+8120", "SJIS-mac", "UTF-8"); -convertInvalidString("\xED\x9F", "W932+7A21", "SJIS-mac", "UTF-8"); +convertInvalidString("\x81", "%", "SJIS-mac", "UTF-8"); +convertInvalidString("\x81\x20", "%", "SJIS-mac", "UTF-8"); +convertInvalidString("\xED\x9F", "%", "SJIS-mac", "UTF-8"); echo "Done!\n"; ?> diff --git a/ext/mbstring/tests/ucs2_encoding.phpt b/ext/mbstring/tests/ucs2_encoding.phpt index 3a194041ade..468d813ad6e 100644 --- a/ext/mbstring/tests/ucs2_encoding.phpt +++ b/ext/mbstring/tests/ucs2_encoding.phpt @@ -5,15 +5,16 @@ mbstring --FILE-- diff --git a/ext/mbstring/tests/ucs4_encoding.phpt b/ext/mbstring/tests/ucs4_encoding.phpt index faeb4ca0316..953a3cd3fb9 100644 --- a/ext/mbstring/tests/ucs4_encoding.phpt +++ b/ext/mbstring/tests/ucs4_encoding.phpt @@ -5,19 +5,20 @@ mbstring --FILE-- diff --git a/ext/mbstring/tests/uhc_encoding.phpt b/ext/mbstring/tests/uhc_encoding.phpt index ae9120899e2..cc4d72f9f11 100644 --- a/ext/mbstring/tests/uhc_encoding.phpt +++ b/ext/mbstring/tests/uhc_encoding.phpt @@ -13,8 +13,8 @@ testEncodingFromUTF16ConversionTable(__DIR__ . '/data/CP949.txt', 'UHC'); // Test "long" illegal character markers mb_substitute_character("long"); -convertInvalidString("\x80", "BAD+80", "UHC", "UTF-8"); -convertInvalidString("\xA7\xF0", "?+A7F0", "UHC", "UTF-8"); +convertInvalidString("\x80", "%", "UHC", "UTF-8"); +convertInvalidString("\xA7\xF0", "%", "UHC", "UTF-8"); ?> --EXPECT-- Tested UHC -> UTF-16BE diff --git a/ext/mbstring/tests/utf7imap_encoding.phpt b/ext/mbstring/tests/utf7imap_encoding.phpt index 86219973167..53c7fbb66b6 100644 --- a/ext/mbstring/tests/utf7imap_encoding.phpt +++ b/ext/mbstring/tests/utf7imap_encoding.phpt @@ -194,10 +194,10 @@ echo "Identification and conversion of valid text is working... perfect!\n"; // Test "long" illegal character markers mb_substitute_character("long"); -convertInvalidString("\x10", "BAD+10", "UTF7-IMAP", "UTF-8"); -convertInvalidString("\x80", "BAD+80", "UTF7-IMAP", "UTF-8"); -convertInvalidString("abc&", "abcBAD+0", "UTF7-IMAP", "UTF-8"); // The & starts a Base-64 coded section, which is OK... but there's no data in it, so the 'bad character' is 'zero' -convertInvalidString("&**-", "BAD+2A*-", "UTF7-IMAP", "UTF-8"); // When we hit the first bad byte in a Base-64 coded section, it drops us back into the default mode, so the following characters are literal +convertInvalidString("\x10", "%", "UTF7-IMAP", "UTF-8"); +convertInvalidString("\x80", "%", "UTF7-IMAP", "UTF-8"); +convertInvalidString("abc&", "abc%", "UTF7-IMAP", "UTF-8"); // The & starts a Base-64 coded section, which is OK... but there's no data in it +convertInvalidString("&**-", "%*-", "UTF7-IMAP", "UTF-8"); // When we hit the first bad byte in a Base-64 coded section, it drops us back into the default mode, so the following characters are literal echo "Done!\n"; ?> diff --git a/ext/mbstring/tests/utf_encodings.phpt b/ext/mbstring/tests/utf_encodings.phpt index 92a9f4f1f56..a0cea5a2905 100644 --- a/ext/mbstring/tests/utf_encodings.phpt +++ b/ext/mbstring/tests/utf_encodings.phpt @@ -805,44 +805,6 @@ $invalid = array( testInvalidCodepoints($invalid, 'UTF-8'); -// Test "long" illegal character markers -mb_substitute_character("long"); -convertInvalidString("\xF4\x90\x80\x80", "BAD+F490BAD+80BAD+80", "UTF-8", "ASCII"); -convertInvalidString("\xF7\x80\x80\x80", "BAD+F7BAD+80BAD+80BAD+80", "UTF-8", "ASCII"); -convertInvalidString("\xED\xA0\x80", "BAD+EDA0BAD+80", "UTF-8", "ASCII"); -convertInvalidString("\xED\xBF\xBF", "BAD+EDBFBAD+BF", "UTF-8", "ASCII"); -// Truncated: -convertInvalidString("\xDF", "BAD+DF", "UTF-8", "ASCII"); -convertInvalidString("\xEF", "BAD+EF", "UTF-8", "ASCII"); -convertInvalidString("\xEF\xBF", "BAD+EFBF", "UTF-8", "ASCII"); -convertInvalidString("\xF0", "BAD+F0", "UTF-8", "ASCII"); -convertInvalidString("\xF0\xBF", "BAD+F0BF", "UTF-8", "ASCII"); -convertInvalidString("\xF0\xBF\xBF", "BAD+F0BFBF", "UTF-8", "ASCII"); -// Multi-byte character ends too early and goes back to ASCII: -convertInvalidString("\xDFA", "BAD+DFA", "UTF-8", "ASCII"); -convertInvalidString("\xEFA", "BAD+EFA", "UTF-8", "ASCII"); -convertInvalidString("\xEF\xBFA", "BAD+EFBFA", "UTF-8", "ASCII"); -convertInvalidString("\xF0A", "BAD+F0A", "UTF-8", "ASCII"); -convertInvalidString("\xF0\xBFA", "BAD+F0BFA", "UTF-8", "ASCII"); -convertInvalidString("\xF0\xBF\xBFA", "BAD+F0BFBFA", "UTF-8", "ASCII"); -// Multi-byte character ends too early and goes to a byte which is not ASCII, nor could -// it possibly start a valid multi-byte character -convertInvalidString("\xEF\xBF\xC0", "BAD+EFBFC0", "UTF-8", "ASCII"); -convertInvalidString("\xF0\xBF\xBF\xC0", "BAD+BFBFC0", "UTF-8", "ASCII"); - -convertInvalidString("\xDF\xDF\xBF", "BAD+DFU+7FF", "UTF-8", "ASCII"); -convertInvalidString("\xEF\xBF\xDF\xBF", "BAD+EFBFU+7FF", "UTF-8", "ASCII"); -convertInvalidString("\xF0\xBF\xBF\xDF\xBF", "BAD+F0BFBFU+7FF", "UTF-8", "ASCII"); - -convertInvalidString("\x80", "BAD+80", "UTF-8", "ASCII"); -convertInvalidString(".\x80", ".BAD+80", "UTF-8", "ASCII"); -convertInvalidString("\xDF\xBF\x80", "U+7FFBAD+80", "UTF-8", "ASCII"); - -convertInvalidString("\xC1\xBF", "BAD+C1BAD+BF", "UTF-8", "ASCII"); -convertInvalidString("\xE0\x9F\xBF", "BAD+E09FBAD+BF", "UTF-8", "ASCII"); -convertInvalidString("\xF0\x8F\xBF\xBF", "BAD+F08FBAD+BFBAD+BF", "UTF-8", "ASCII"); -mb_substitute_character(0x25); // '%' - echo "== UTF-16 ==\n"; testValidCodepoints("UTF-16"); @@ -896,29 +858,6 @@ testInvalidCodepoints($invalid, 'UTF-16LE'); testInvalidString("\x00", "\x00\x00\x00%", 'UTF-16LE', 'UTF-32BE'); testInvalidString("A\x00\x01", "\x00\x00\x00A\x00\x00\x00%", 'UTF-16LE', 'UTF-32BE'); -// Test "long" illegal character markers -mb_substitute_character("long"); -convertInvalidString("\xDC\x01\xD8\x02", "BAD+DC01BAD+D802", "UTF-16", "ASCII"); -convertInvalidString("\xDC\x01\xD8\x02", "BAD+DC01BAD+D802", "UTF-16BE", "ASCII"); -convertInvalidString("\x01\xDC\x02\xD8", "BAD+DC01BAD+D802", "UTF-16LE", "ASCII"); -convertInvalidString("\xDD\x11\xD9\x13", "BAD+DD11BAD+D913", "UTF-16BE", "ASCII"); - -convertInvalidString("\xD8\x01\x00A", "BAD+D801A", "UTF-16", "ASCII"); -convertInvalidString("\xD8\x01\x00A", "BAD+D801A", "UTF-16BE", "ASCII"); -convertInvalidString("\x01\xD8A\x00", "BAD+D801A", "UTF-16LE", "ASCII"); - -convertInvalidString("\xD8\x01", "BAD+D801", "UTF-16", "ASCII"); -convertInvalidString("\xD8\x01", "BAD+D801", "UTF-16BE", "ASCII"); -convertInvalidString("\x01\xD8", "BAD+D801", "UTF-16LE", "ASCII"); - -convertInvalidString("\x00", "BAD+0", 'UTF-16', 'ASCII'); -convertInvalidString("\x00", "BAD+0", 'UTF-16BE', 'ASCII'); -convertInvalidString("\x00", "BAD+0", 'UTF-16LE', 'ASCII'); -convertInvalidString("\x00A\x01", "ABAD+1", 'UTF-16', 'ASCII'); -convertInvalidString("\x00A\x01", "ABAD+1", 'UTF-16BE', 'ASCII'); -convertInvalidString("A\x00\x01", "ABAD+1", 'UTF-16LE', 'ASCII'); -mb_substitute_character(0x25); // '%' - // TODO: test handling of UTF-16 BOM echo "== UTF-32 ==\n"; @@ -975,24 +914,6 @@ testInvalidString("\x00\x01\x01", "\x00\x00\x00%", 'UTF-32LE', 'UTF-32BE'); testInvalidString("\x00\x01", "\x00\x00\x00%", 'UTF-32LE', 'UTF-32BE'); testInvalidString("\x00", "\x00\x00\x00%", 'UTF-32LE', 'UTF-32BE'); -mb_substitute_character("long"); -convertInvalidString("\x00\x01\x01", "BAD+101", "UTF-32", "ASCII"); -convertInvalidString("\x00\x01\x01", "BAD+101", "UTF-32BE", "ASCII"); -convertInvalidString("\x01\x01\x00", "BAD+101", "UTF-32LE", "ASCII"); - -convertInvalidString("\x01", "BAD+1", "UTF-32", "ASCII"); -convertInvalidString("\x01", "BAD+1", "UTF-32BE", "ASCII"); -convertInvalidString("\x01", "BAD+1", "UTF-32LE", "ASCII"); - -convertInvalidString("\x00\x11\x00\x00", "BAD+110000", "UTF-32", "ASCII"); -convertInvalidString("\x00\x11\x00\x00", "BAD+110000", "UTF-32BE", "ASCII"); -convertInvalidString("\x00\x00\x11\x00", "BAD+110000", "UTF-32LE", "ASCII"); - -convertInvalidString("\x00\x00\xd8\x00", "BAD+D800", "UTF-32", "ASCII"); -convertInvalidString("\x00\x00\xd8\x00", "BAD+D800", "UTF-32BE", "ASCII"); -convertInvalidString("\x00\xd8\x00\x00", "BAD+D800", "UTF-32LE", "ASCII"); -mb_substitute_character(0x25); // '%' - // TODO: test handling of UTF-32 BOM echo "== UTF-7 ==\n"; @@ -1100,28 +1021,6 @@ $encoded = encode("\x12\x34", 'UTF-16BE'); // 3 Base64 bytes, 2 bits of padding. $corrupted = substr($encoded, 0, 2) . chr(ord($encoded[2]) + 1); testInvalidString('+' . $corrupted . '-', "\x00\x00\x12\x34\x00\x00\x00%", 'UTF-7', 'UTF-32BE'); -// Test "long" illegal character markers -mb_substitute_character("long"); -convertInvalidString('+' . rawEncode("\xDC\x01\xD8\x02") . '-', "BAD+DC01BAD+D802", "UTF-7", "UTF-8"); -convertInvalidString('+' . rawEncode("\xDC\x01\xD8\x02"), "BAD+DC01BAD+D802", "UTF-7", "UTF-8"); -convertInvalidString('+' . rawEncode("\x00\x2E\xDC\x01\xD8\x02") . '-', ".BAD+DC01BAD+D802", "UTF-7", "UTF-8"); -convertInvalidString('+' . rawEncode("\x00\x2E\xDC\x01\xD8\x02"), ".BAD+DC01BAD+D802", "UTF-7", "UTF-8"); -convertInvalidString('+' . rawEncode("\x00\x2E\x00\x2E\xDC\x01\xD8\x02") . '-', "..BAD+DC01BAD+D802", "UTF-7", "UTF-8"); -convertInvalidString('+' . rawEncode("\x00\x2E\x00\x2E\xDC\x01\xD8\x02"), "..BAD+DC01BAD+D802", "UTF-7", "UTF-8"); - -convertInvalidString('+' . rawEncode("\xD8\x01\x00A") . '-', "BAD+D801A", 'UTF-7', 'UTF-8'); -convertInvalidString('+' . rawEncode("\x00\x2E\xD8\x01\x00A") . '-', ".BAD+D801A", 'UTF-7', 'UTF-8'); -convertInvalidString('+' . rawEncode("\x00\x2E\x00\x2E\xD8\x01\x00A") . '-', "..BAD+D801A", 'UTF-7', 'UTF-8'); - -convertInvalidString('+' . rawEncode("\xD8\x01\xD9\x02") . '-', "BAD+D801BAD+D902", 'UTF-7', 'UTF-8'); -convertInvalidString('+' . rawEncode("\xD8\x01\xD9\x02"), "BAD+D801BAD+D902", 'UTF-7', 'UTF-8'); -convertInvalidString('+' . rawEncode("\x00\x2E\xD8\x01\xD9\x02") . '-', ".BAD+D801BAD+D902", 'UTF-7', 'UTF-8'); -convertInvalidString('+' . rawEncode("\x00\x2E\xD8\x01\xD9\x02"), ".BAD+D801BAD+D902", 'UTF-7', 'UTF-8'); -convertInvalidString('+' . rawEncode("\x00\x2E\x00\x2E\xD8\x01\xD9\x02") . '-', "..BAD+D801BAD+D902", 'UTF-7', 'UTF-8'); -convertInvalidString('+' . rawEncode("\x00\x2E\x00\x2E\xD8\x01\xD9\x02"), "..BAD+D801BAD+D902", 'UTF-7', 'UTF-8'); - -convertInvalidString('+' . rawEncode("\x01") . '-', "BAD+100", 'UTF-7', 'UTF-8'); - echo "Done!\n"; ?>