1
0
mirror of https://github.com/php/php-src.git synced 2026-04-25 17:08:14 +02:00

Don't pass invalid JIS X 0212, JIS X 0213, and Windows-CP932 characters through

Similarly to JIS X 0208, mbstring would pass kuten codes which are not mapped
in the JIS X 0212, JIS X 0213, or CP932 character sets through silently when
converting to another Japanese encoding.
This commit is contained in:
Alex Dowad
2020-10-07 22:30:34 +02:00
parent 8ae0473324
commit 5ffcf563bd
12 changed files with 13 additions and 89 deletions
@@ -383,9 +383,8 @@ retry:
int
mbfl_filt_conv_wchar_jis_ms(int c, mbfl_convert_filter *filter)
{
int c1, s;
int s = 0;
s = 0;
if (c >= ucs_a1_jis_table_min && c < ucs_a1_jis_table_max) {
s = ucs_a1_jis_table[c - ucs_a1_jis_table_min];
} else if (c >= ucs_a2_jis_table_min && c < ucs_a2_jis_table_max) {
@@ -408,11 +407,7 @@ mbfl_filt_conv_wchar_jis_ms(int c, mbfl_convert_filter *filter)
/* do some transliteration */
if (s <= 0) {
c1 = c & ~MBFL_WCSPLANE_MASK;
if (c1 == MBFL_WCSPLANE_JIS0212) {
s = c & MBFL_WCSPLANE_MASK;
s |= 0x8080;
} else if (c == 0xa5) { /* YEN SIGN */
if (c == 0xa5) { /* YEN SIGN */
s = 0x1005c;
} else if (c == 0x203e) { /* OVER LINE */
s = 0x1007e;
@@ -210,13 +210,7 @@ mbfl_filt_conv_wchar_cp51932(int c, mbfl_convert_filter *filter)
}
if (s1 >= 0x8080) s1 = -1; /* we don't support JIS X0213 */
if (s1 <= 0) {
c1 = c & ~MBFL_WCSPLANE_MASK;
if (c1 == MBFL_WCSPLANE_WINCP932) {
s1 = c & MBFL_WCSPLANE_MASK;
if (s1 >= ((85 + 0x20) << 8)) { /* 85ku - 120ku */
s1 = -1;
}
} else if (c == 0xa5) { /* YEN SIGN */
if (c == 0xa5) { /* YEN SIGN */
s1 = 0x005c; /* YEN SIGN */
} else if (c == 0x203e) { /* OVER LINE */
s1 = 0x007e; /* FULLWIDTH MACRON */
@@ -251,14 +251,7 @@ mbfl_filt_conv_wchar_cp932(int c, mbfl_convert_filter *filter)
s2 = 1;
}
if (s1 <= 0) {
c1 = c & ~MBFL_WCSPLANE_MASK;
if (c1 == MBFL_WCSPLANE_WINCP932) {
s1 = c & MBFL_WCSPLANE_MASK;
s2 = 1;
} else if (c1 == MBFL_WCSPLANE_JIS0212) {
s1 = c & MBFL_WCSPLANE_MASK;
s1 |= 0x8080;
} else if (c == 0xa5) { /* YEN SIGN */
if (c == 0xa5) { /* YEN SIGN */
s1 = 0x005c; /* YEN SIGN */
} else if (c == 0x203e) { /* OVER LINE */
s1 = 0x007e; /* FULLWIDTH MACRON */
@@ -192,9 +192,8 @@ static int mbfl_filt_conv_eucjp_wchar_flush(mbfl_convert_filter *filter)
int
mbfl_filt_conv_wchar_eucjp(int c, mbfl_convert_filter *filter)
{
int s;
int s = 0;
s = 0;
if (c >= ucs_a1_jis_table_min && c < ucs_a1_jis_table_max) {
s = ucs_a1_jis_table[c - ucs_a1_jis_table_min];
} else if (c >= ucs_a2_jis_table_min && c < ucs_a2_jis_table_max) {
@@ -273,20 +273,7 @@ mbfl_filt_conv_wchar_eucjpwin(int c, mbfl_convert_filter *filter)
s1 = 0x2d62; /* NUMERO SIGN */
}
if (s1 <= 0) {
c1 = c & ~MBFL_WCSPLANE_MASK;
if (c1 == MBFL_WCSPLANE_WINCP932) {
s1 = c & MBFL_WCSPLANE_MASK;
if (s1 >= ((85 + 0x20) << 8)) { /* 85ku - 120ku */
s1 = -1;
}
} else if (c1 == MBFL_WCSPLANE_JIS0212) {
s1 = c & MBFL_WCSPLANE_MASK;
if (s1 >= ((83 + 0x20) << 8)) { /* 83ku - 94ku */
s1 = -1;
} else {
s1 |= 0x8080;
}
} else if (c == 0xa5) { /* YEN SIGN */
if (c == 0xa5) { /* YEN SIGN */
s1 = 0x216f; /* FULLWIDTH YEN SIGN */
} else if (c == 0x203e) { /* OVER LINE */
s1 = 0x2131; /* FULLWIDTH MACRON */
@@ -302,14 +302,7 @@ mbfl_filt_conv_wchar_2022jpms(int c, mbfl_convert_filter *filter)
s1 = (c1 << 8) | c2;
}
if (s1 <= 0) {
c1 = c & ~MBFL_WCSPLANE_MASK;
if (c1 == MBFL_WCSPLANE_WINCP932) {
s1 = c & MBFL_WCSPLANE_MASK;
s2 = 1;
} else if (c1 == MBFL_WCSPLANE_JIS0212) {
s1 = c & MBFL_WCSPLANE_MASK;
s1 |= 0x8080;
} else if (c == 0xa5) { /* YEN SIGN */
if (c == 0xa5) { /* YEN SIGN */
s1 = 0x216f; /* FULLWIDTH YEN SIGN */
} else if (c == 0x203e) { /* OVER LINE */
s1 = 0x2131; /* FULLWIDTH MACRON */
@@ -330,14 +330,7 @@ mbfl_filt_conv_wchar_2022jp_mobile(int c, mbfl_convert_filter *filter)
s1 = (c1 << 8) | c2;
}
if (s1 <= 0) {
c1 = c & ~MBFL_WCSPLANE_MASK;
if (c1 == MBFL_WCSPLANE_WINCP932) {
s1 = c & MBFL_WCSPLANE_MASK;
s2 = 1;
} else if (c1 == MBFL_WCSPLANE_JIS0212) {
s1 = c & MBFL_WCSPLANE_MASK;
s1 |= 0x8080;
} else if (c == 0xa5) { /* YEN SIGN */
if (c == 0xa5) { /* YEN SIGN */
s1 = 0x216f; /* FULLWIDTH YEN SIGN */
} else if (c == 0x203e) { /* OVER LINE */
s1 = 0x2131; /* FULLWIDTH MACRON */
+2 -7
View File
@@ -274,9 +274,8 @@ retry:
int
mbfl_filt_conv_wchar_jis(int c, mbfl_convert_filter *filter)
{
int c1, s;
int s = 0;
s = 0;
if (c >= ucs_a1_jis_table_min && c < ucs_a1_jis_table_max) {
s = ucs_a1_jis_table[c - ucs_a1_jis_table_min];
} else if (c >= ucs_a2_jis_table_min && c < ucs_a2_jis_table_max) {
@@ -287,11 +286,7 @@ mbfl_filt_conv_wchar_jis(int c, mbfl_convert_filter *filter)
s = ucs_r_jis_table[c - ucs_r_jis_table_min];
}
if (s <= 0) {
c1 = c & ~MBFL_WCSPLANE_MASK;
if (c1 == MBFL_WCSPLANE_JIS0212) {
s = c & MBFL_WCSPLANE_MASK;
s |= 0x8080;
} else if (c == 0xa5) { /* YEN SIGN */
if (c == 0xa5) { /* YEN SIGN */
s = 0x1005c;
} else if (c == 0x203e) { /* OVER LINE */
s = 0x1007e;
@@ -590,10 +590,6 @@ retry:
}
if (s1 <= 0) {
c1 = c & ~MBFL_WCSPLANE_MASK;
if (c1 == MBFL_WCSPLANE_JIS0213) {
s1 = c & MBFL_WCSPLANE_MASK;
}
if (c == 0) {
s1 = 0;
} else if (s1 <= 0) {
@@ -416,14 +416,7 @@ mbfl_filt_conv_wchar_sjis_mac(int c, mbfl_convert_filter *filter)
}
if (s1 <= 0) {
c1 = c & ~MBFL_WCSPLANE_MASK;
if (c1 == MBFL_WCSPLANE_WINCP932) {
s1 = c & MBFL_WCSPLANE_MASK;
s2 = 1;
} else if (c1 == MBFL_WCSPLANE_JIS0212) {
s1 = c & MBFL_WCSPLANE_MASK;
s1 |= 0x8080;
} else if (c == 0xa0) {
if (c == 0xa0) {
s1 = 0x00a0;
} else if (c == 0xa5) { /* YEN SIGN */
/* Unicode has codepoint 0xFFE5 for a fullwidth Yen sign;
@@ -790,14 +790,7 @@ mbfl_filt_conv_wchar_sjis_mobile(int c, mbfl_convert_filter *filter)
s2 = 1;
}
if (s1 <= 0) {
c1 = c & ~MBFL_WCSPLANE_MASK;
if (c1 == MBFL_WCSPLANE_WINCP932) {
s1 = c & MBFL_WCSPLANE_MASK;
s2 = 1;
} else if (c1 == MBFL_WCSPLANE_JIS0212) {
s1 = c & MBFL_WCSPLANE_MASK;
s1 |= 0x8080;
} else if (c == 0xa5) { /* YEN SIGN */
if (c == 0xa5) { /* YEN SIGN */
s1 = 0x216f; /* FULLWIDTH YEN SIGN */
} else if (c == 0x203e) { /* OVER LINE */
s1 = 0x2131; /* FULLWIDTH MACRON */
@@ -241,14 +241,7 @@ mbfl_filt_conv_wchar_sjis_open(int c, mbfl_convert_filter *filter)
s2 = 1;
}
if (s1 <= 0) {
c1 = c & ~MBFL_WCSPLANE_MASK;
if (c1 == MBFL_WCSPLANE_WINCP932) {
s1 = c & MBFL_WCSPLANE_MASK;
s2 = 1;
} else if (c1 == MBFL_WCSPLANE_JIS0212) {
s1 = c & MBFL_WCSPLANE_MASK;
s1 |= 0x8080;
} else if (c == 0xa5) { /* YEN SIGN */
if (c == 0xa5) { /* YEN SIGN */
s1 = 0x216f; /* FULLWIDTH YEN SIGN */
} else if (c == 0x203e) { /* OVER LINE */
s1 = 0x2131; /* FULLWIDTH MACRON */