Skip to content

Commit 5ffcf56

Browse files
committed
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.
1 parent 8ae0473 commit 5ffcf56

12 files changed

+13
-89
lines changed

ext/mbstring/libmbfl/filters/mbfilter_cp5022x.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,8 @@ mbfl_filt_conv_jis_ms_wchar(int c, mbfl_convert_filter *filter)
383383
int
384384
mbfl_filt_conv_wchar_jis_ms(int c, mbfl_convert_filter *filter)
385385
{
386-
int c1, s;
386+
int s = 0;
387387

388-
s = 0;
389388
if (c >= ucs_a1_jis_table_min && c < ucs_a1_jis_table_max) {
390389
s = ucs_a1_jis_table[c - ucs_a1_jis_table_min];
391390
} 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)
408407

409408
/* do some transliteration */
410409
if (s <= 0) {
411-
c1 = c & ~MBFL_WCSPLANE_MASK;
412-
if (c1 == MBFL_WCSPLANE_JIS0212) {
413-
s = c & MBFL_WCSPLANE_MASK;
414-
s |= 0x8080;
415-
} else if (c == 0xa5) { /* YEN SIGN */
410+
if (c == 0xa5) { /* YEN SIGN */
416411
s = 0x1005c;
417412
} else if (c == 0x203e) { /* OVER LINE */
418413
s = 0x1007e;

ext/mbstring/libmbfl/filters/mbfilter_cp51932.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,7 @@ mbfl_filt_conv_wchar_cp51932(int c, mbfl_convert_filter *filter)
210210
}
211211
if (s1 >= 0x8080) s1 = -1; /* we don't support JIS X0213 */
212212
if (s1 <= 0) {
213-
c1 = c & ~MBFL_WCSPLANE_MASK;
214-
if (c1 == MBFL_WCSPLANE_WINCP932) {
215-
s1 = c & MBFL_WCSPLANE_MASK;
216-
if (s1 >= ((85 + 0x20) << 8)) { /* 85ku - 120ku */
217-
s1 = -1;
218-
}
219-
} else if (c == 0xa5) { /* YEN SIGN */
213+
if (c == 0xa5) { /* YEN SIGN */
220214
s1 = 0x005c; /* YEN SIGN */
221215
} else if (c == 0x203e) { /* OVER LINE */
222216
s1 = 0x007e; /* FULLWIDTH MACRON */

ext/mbstring/libmbfl/filters/mbfilter_cp932.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -251,14 +251,7 @@ mbfl_filt_conv_wchar_cp932(int c, mbfl_convert_filter *filter)
251251
s2 = 1;
252252
}
253253
if (s1 <= 0) {
254-
c1 = c & ~MBFL_WCSPLANE_MASK;
255-
if (c1 == MBFL_WCSPLANE_WINCP932) {
256-
s1 = c & MBFL_WCSPLANE_MASK;
257-
s2 = 1;
258-
} else if (c1 == MBFL_WCSPLANE_JIS0212) {
259-
s1 = c & MBFL_WCSPLANE_MASK;
260-
s1 |= 0x8080;
261-
} else if (c == 0xa5) { /* YEN SIGN */
254+
if (c == 0xa5) { /* YEN SIGN */
262255
s1 = 0x005c; /* YEN SIGN */
263256
} else if (c == 0x203e) { /* OVER LINE */
264257
s1 = 0x007e; /* FULLWIDTH MACRON */

ext/mbstring/libmbfl/filters/mbfilter_euc_jp.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,8 @@ static int mbfl_filt_conv_eucjp_wchar_flush(mbfl_convert_filter *filter)
192192
int
193193
mbfl_filt_conv_wchar_eucjp(int c, mbfl_convert_filter *filter)
194194
{
195-
int s;
195+
int s = 0;
196196

197-
s = 0;
198197
if (c >= ucs_a1_jis_table_min && c < ucs_a1_jis_table_max) {
199198
s = ucs_a1_jis_table[c - ucs_a1_jis_table_min];
200199
} else if (c >= ucs_a2_jis_table_min && c < ucs_a2_jis_table_max) {

ext/mbstring/libmbfl/filters/mbfilter_euc_jp_win.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -273,20 +273,7 @@ mbfl_filt_conv_wchar_eucjpwin(int c, mbfl_convert_filter *filter)
273273
s1 = 0x2d62; /* NUMERO SIGN */
274274
}
275275
if (s1 <= 0) {
276-
c1 = c & ~MBFL_WCSPLANE_MASK;
277-
if (c1 == MBFL_WCSPLANE_WINCP932) {
278-
s1 = c & MBFL_WCSPLANE_MASK;
279-
if (s1 >= ((85 + 0x20) << 8)) { /* 85ku - 120ku */
280-
s1 = -1;
281-
}
282-
} else if (c1 == MBFL_WCSPLANE_JIS0212) {
283-
s1 = c & MBFL_WCSPLANE_MASK;
284-
if (s1 >= ((83 + 0x20) << 8)) { /* 83ku - 94ku */
285-
s1 = -1;
286-
} else {
287-
s1 |= 0x8080;
288-
}
289-
} else if (c == 0xa5) { /* YEN SIGN */
276+
if (c == 0xa5) { /* YEN SIGN */
290277
s1 = 0x216f; /* FULLWIDTH YEN SIGN */
291278
} else if (c == 0x203e) { /* OVER LINE */
292279
s1 = 0x2131; /* FULLWIDTH MACRON */

ext/mbstring/libmbfl/filters/mbfilter_iso2022_jp_ms.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -302,14 +302,7 @@ mbfl_filt_conv_wchar_2022jpms(int c, mbfl_convert_filter *filter)
302302
s1 = (c1 << 8) | c2;
303303
}
304304
if (s1 <= 0) {
305-
c1 = c & ~MBFL_WCSPLANE_MASK;
306-
if (c1 == MBFL_WCSPLANE_WINCP932) {
307-
s1 = c & MBFL_WCSPLANE_MASK;
308-
s2 = 1;
309-
} else if (c1 == MBFL_WCSPLANE_JIS0212) {
310-
s1 = c & MBFL_WCSPLANE_MASK;
311-
s1 |= 0x8080;
312-
} else if (c == 0xa5) { /* YEN SIGN */
305+
if (c == 0xa5) { /* YEN SIGN */
313306
s1 = 0x216f; /* FULLWIDTH YEN SIGN */
314307
} else if (c == 0x203e) { /* OVER LINE */
315308
s1 = 0x2131; /* FULLWIDTH MACRON */

ext/mbstring/libmbfl/filters/mbfilter_iso2022jp_mobile.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -330,14 +330,7 @@ mbfl_filt_conv_wchar_2022jp_mobile(int c, mbfl_convert_filter *filter)
330330
s1 = (c1 << 8) | c2;
331331
}
332332
if (s1 <= 0) {
333-
c1 = c & ~MBFL_WCSPLANE_MASK;
334-
if (c1 == MBFL_WCSPLANE_WINCP932) {
335-
s1 = c & MBFL_WCSPLANE_MASK;
336-
s2 = 1;
337-
} else if (c1 == MBFL_WCSPLANE_JIS0212) {
338-
s1 = c & MBFL_WCSPLANE_MASK;
339-
s1 |= 0x8080;
340-
} else if (c == 0xa5) { /* YEN SIGN */
333+
if (c == 0xa5) { /* YEN SIGN */
341334
s1 = 0x216f; /* FULLWIDTH YEN SIGN */
342335
} else if (c == 0x203e) { /* OVER LINE */
343336
s1 = 0x2131; /* FULLWIDTH MACRON */

ext/mbstring/libmbfl/filters/mbfilter_jis.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,8 @@ mbfl_filt_conv_jis_wchar(int c, mbfl_convert_filter *filter)
274274
int
275275
mbfl_filt_conv_wchar_jis(int c, mbfl_convert_filter *filter)
276276
{
277-
int c1, s;
277+
int s = 0;
278278

279-
s = 0;
280279
if (c >= ucs_a1_jis_table_min && c < ucs_a1_jis_table_max) {
281280
s = ucs_a1_jis_table[c - ucs_a1_jis_table_min];
282281
} 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)
287286
s = ucs_r_jis_table[c - ucs_r_jis_table_min];
288287
}
289288
if (s <= 0) {
290-
c1 = c & ~MBFL_WCSPLANE_MASK;
291-
if (c1 == MBFL_WCSPLANE_JIS0212) {
292-
s = c & MBFL_WCSPLANE_MASK;
293-
s |= 0x8080;
294-
} else if (c == 0xa5) { /* YEN SIGN */
289+
if (c == 0xa5) { /* YEN SIGN */
295290
s = 0x1005c;
296291
} else if (c == 0x203e) { /* OVER LINE */
297292
s = 0x1007e;

ext/mbstring/libmbfl/filters/mbfilter_sjis_2004.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -590,10 +590,6 @@ mbfl_filt_conv_wchar_jis2004(int c, mbfl_convert_filter *filter) {
590590
}
591591

592592
if (s1 <= 0) {
593-
c1 = c & ~MBFL_WCSPLANE_MASK;
594-
if (c1 == MBFL_WCSPLANE_JIS0213) {
595-
s1 = c & MBFL_WCSPLANE_MASK;
596-
}
597593
if (c == 0) {
598594
s1 = 0;
599595
} else if (s1 <= 0) {

ext/mbstring/libmbfl/filters/mbfilter_sjis_mac.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -416,14 +416,7 @@ mbfl_filt_conv_wchar_sjis_mac(int c, mbfl_convert_filter *filter)
416416
}
417417

418418
if (s1 <= 0) {
419-
c1 = c & ~MBFL_WCSPLANE_MASK;
420-
if (c1 == MBFL_WCSPLANE_WINCP932) {
421-
s1 = c & MBFL_WCSPLANE_MASK;
422-
s2 = 1;
423-
} else if (c1 == MBFL_WCSPLANE_JIS0212) {
424-
s1 = c & MBFL_WCSPLANE_MASK;
425-
s1 |= 0x8080;
426-
} else if (c == 0xa0) {
419+
if (c == 0xa0) {
427420
s1 = 0x00a0;
428421
} else if (c == 0xa5) { /* YEN SIGN */
429422
/* Unicode has codepoint 0xFFE5 for a fullwidth Yen sign;

ext/mbstring/libmbfl/filters/mbfilter_sjis_mobile.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -790,14 +790,7 @@ mbfl_filt_conv_wchar_sjis_mobile(int c, mbfl_convert_filter *filter)
790790
s2 = 1;
791791
}
792792
if (s1 <= 0) {
793-
c1 = c & ~MBFL_WCSPLANE_MASK;
794-
if (c1 == MBFL_WCSPLANE_WINCP932) {
795-
s1 = c & MBFL_WCSPLANE_MASK;
796-
s2 = 1;
797-
} else if (c1 == MBFL_WCSPLANE_JIS0212) {
798-
s1 = c & MBFL_WCSPLANE_MASK;
799-
s1 |= 0x8080;
800-
} else if (c == 0xa5) { /* YEN SIGN */
793+
if (c == 0xa5) { /* YEN SIGN */
801794
s1 = 0x216f; /* FULLWIDTH YEN SIGN */
802795
} else if (c == 0x203e) { /* OVER LINE */
803796
s1 = 0x2131; /* FULLWIDTH MACRON */

ext/mbstring/libmbfl/filters/mbfilter_sjis_open.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,7 @@ mbfl_filt_conv_wchar_sjis_open(int c, mbfl_convert_filter *filter)
241241
s2 = 1;
242242
}
243243
if (s1 <= 0) {
244-
c1 = c & ~MBFL_WCSPLANE_MASK;
245-
if (c1 == MBFL_WCSPLANE_WINCP932) {
246-
s1 = c & MBFL_WCSPLANE_MASK;
247-
s2 = 1;
248-
} else if (c1 == MBFL_WCSPLANE_JIS0212) {
249-
s1 = c & MBFL_WCSPLANE_MASK;
250-
s1 |= 0x8080;
251-
} else if (c == 0xa5) { /* YEN SIGN */
244+
if (c == 0xa5) { /* YEN SIGN */
252245
s1 = 0x216f; /* FULLWIDTH YEN SIGN */
253246
} else if (c == 0x203e) { /* OVER LINE */
254247
s1 = 0x2131; /* FULLWIDTH MACRON */

0 commit comments

Comments
 (0)