]> granicus.if.org Git - php/commitdiff
Don't pass invalid JIS X 0212, JIS X 0213, and Windows-CP932 characters through
authorAlex Dowad <alexinbeijing@gmail.com>
Wed, 7 Oct 2020 20:30:34 +0000 (22:30 +0200)
committerAlex Dowad <alexinbeijing@gmail.com>
Wed, 25 Nov 2020 17:52:19 +0000 (19:52 +0200)
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.

12 files changed:
ext/mbstring/libmbfl/filters/mbfilter_cp5022x.c
ext/mbstring/libmbfl/filters/mbfilter_cp51932.c
ext/mbstring/libmbfl/filters/mbfilter_cp932.c
ext/mbstring/libmbfl/filters/mbfilter_euc_jp.c
ext/mbstring/libmbfl/filters/mbfilter_euc_jp_win.c
ext/mbstring/libmbfl/filters/mbfilter_iso2022_jp_ms.c
ext/mbstring/libmbfl/filters/mbfilter_iso2022jp_mobile.c
ext/mbstring/libmbfl/filters/mbfilter_jis.c
ext/mbstring/libmbfl/filters/mbfilter_sjis_2004.c
ext/mbstring/libmbfl/filters/mbfilter_sjis_mac.c
ext/mbstring/libmbfl/filters/mbfilter_sjis_mobile.c
ext/mbstring/libmbfl/filters/mbfilter_sjis_open.c

index b630d3fcb032de02bb40c5f0e62314ed9bfd91a2..3f4fb7132cb903e58fb1f0172001b48d2e6e1c94 100644 (file)
@@ -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;
index 25944a10dd5f229b562d7ed1b1546b64b8f974be..6e0746b866ebf0fbe8d5b044f5c613b10058b676 100644 (file)
@@ -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 */
index 64ccd573611417807a30ba2d70815c0740726f27..6246600de8248b4b332d68426f0bb5ebc04984de 100644 (file)
@@ -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 */
index 1589ae7966d885828b3d41fd96c8b512fe6b61c4..507a26a5b15770cecb0faf8f362e36c6c4401f71 100644 (file)
@@ -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) {
index df51be01831413ca6f10023c8be36eecd5f6d48b..569dabd92da5ff47dc5225874252058896e32530 100644 (file)
@@ -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 */
index af54a1c6051faf1c0b11aad626b1754ae689ae5f..5e0a63958b68cea3ad0f41e7e4bfae3fdc45c944 100644 (file)
@@ -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 */
index 1b4857dfe25ee432257b322177fcc143d3867172..0099fb1ebb93afe743cd9ec819063ce794329911 100644 (file)
@@ -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 */
index 8ba46a5b9ace52936493e7c840cce922aebdd80a..5e0c05c8fc0a8df7a7dabd4275578e4bacbf86e1 100644 (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;
index 02bbdccdc87334fbbcfd9289e83a766e66c775ad..1e549fdebb8f3b35db1a8d386c0cfaa4ca522c94 100644 (file)
@@ -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) {
index 6361195606d6322e00282a440516e6c7a31fd1ca..4dead25a78def79a59f2a96cee36221e2d349914 100644 (file)
@@ -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;
index 10ac7d9ce41cd307afc9d5d2adbbf19a40a75767..a434d9bf54d1efb1b7480a4346f1efe387fd7b18 100644 (file)
@@ -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 */
index ea19e6b1058d2958e005ce85455a9a5f1e913531..d1dd5efd954b23ab07eb0058a34a5350dc6d9e28 100644 (file)
@@ -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 */