Skip to content

Commit 3152b7b

Browse files
committedJan 6, 2023
Use different mblen_table for different SJIS variants
1 parent d104481 commit 3152b7b

File tree

5 files changed

+48
-10
lines changed

5 files changed

+48
-10
lines changed
 

‎NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ PHP NEWS
2121
. Fixed bug GH-10112 (LDAP\Connection::__construct() refers to ldap_create()).
2222
(cmb)
2323

24+
- MBString:
25+
. Fixed: mb_strlen (and a couple of other mbstring functions) would wrongly treat 0x80, 0xFD, 0xFE, 0xFF, and certain other byte values as the first byte of a 2-byte SJIS character. (Alex Dowad)
26+
2427
- Opcache:
2528
. Fix inverted bailout value in zend_runtime_jit() (Max Kellermann).
2629
. Fix access to uninitialized variable in accel_preload(). (nielsdos)

‎ext/mbstring/libmbfl/filters/mbfilter_sjis.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
static int mbfl_filt_conv_sjis_wchar_flush(mbfl_convert_filter *filter);
4040

41-
const unsigned char mblen_table_sjis[] = { /* 0x81-0x9F,0xE0-0xFC */
41+
const unsigned char mblen_table_sjis[] = { /* 0x81-0x9F,0xE0-0xEF */
4242
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
4343
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
4444
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
@@ -54,7 +54,7 @@ const unsigned char mblen_table_sjis[] = { /* 0x81-0x9F,0xE0-0xFC */
5454
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
5555
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
5656
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
57-
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1
57+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
5858
};
5959

6060
static const char *mbfl_encoding_sjis_aliases[] = {"x-sjis", "SHIFT-JIS", NULL};

‎ext/mbstring/libmbfl/filters/mbfilter_sjis_2004.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#include "unicode_table_jis2004.h"
4040
#include "unicode_table_jis.h"
4141

42-
extern const unsigned char mblen_table_sjis[];
42+
extern const unsigned char mblen_table_sjis_mobile[];
4343

4444
extern int mbfl_bisec_srch(int w, const unsigned short *tbl, int n);
4545
extern int mbfl_bisec_srch2(int w, const unsigned short tbl[], int n);
@@ -51,7 +51,7 @@ const mbfl_encoding mbfl_encoding_sjis2004 = {
5151
"SJIS-2004",
5252
"Shift_JIS",
5353
mbfl_encoding_sjis2004_aliases,
54-
mblen_table_sjis,
54+
mblen_table_sjis_mobile, /* Leading byte values used for SJIS-2004 are the same as mobile SJIS variants */
5555
MBFL_ENCTYPE_GL_UNSAFE,
5656
&vtbl_sjis2004_wchar,
5757
&vtbl_wchar_sjis2004

‎ext/mbstring/libmbfl/filters/mbfilter_sjis_mac.c

+19-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,24 @@
3535

3636
#include "sjis_mac2uni.h"
3737

38-
extern const unsigned char mblen_table_sjis[];
38+
const unsigned char mblen_table_sjismac[] = { /* 0x81-0x9F,0xE0-0xED */
39+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
40+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
41+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
42+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
43+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
44+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
45+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
46+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
47+
1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
48+
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
49+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
50+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
51+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
52+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
53+
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1,
54+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
55+
};
3956

4057
static int mbfl_filt_conv_wchar_sjis_mac_flush(mbfl_convert_filter *filter);
4158
static int mbfl_filt_conv_sjis_mac_wchar_flush(mbfl_convert_filter *filter);
@@ -47,7 +64,7 @@ const mbfl_encoding mbfl_encoding_sjis_mac = {
4764
"SJIS-mac",
4865
"Shift_JIS",
4966
mbfl_encoding_sjis_mac_aliases,
50-
mblen_table_sjis,
67+
mblen_table_sjismac,
5168
MBFL_ENCTYPE_GL_UNSAFE,
5269
&vtbl_sjis_mac_wchar,
5370
&vtbl_wchar_sjis_mac

‎ext/mbstring/libmbfl/filters/mbfilter_sjis_mobile.c

+22-4
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,26 @@
3535

3636
#include "emoji2uni.h"
3737

38+
const unsigned char mblen_table_sjis_mobile[] = { /* 0x81-0x9F,0xE0-0xFC */
39+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
40+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
41+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
42+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
43+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
44+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
45+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
46+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
47+
1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
48+
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
49+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
50+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
51+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
52+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
53+
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
54+
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1
55+
};
56+
3857
extern int mbfl_bisec_srch2(int w, const unsigned short tbl[], int n);
39-
extern const unsigned char mblen_table_sjis[];
4058

4159
static int mbfl_filt_conv_sjis_wchar_flush(mbfl_convert_filter *filter);
4260

@@ -49,7 +67,7 @@ const mbfl_encoding mbfl_encoding_sjis_docomo = {
4967
"SJIS-Mobile#DOCOMO",
5068
"Shift_JIS",
5169
mbfl_encoding_sjis_docomo_aliases,
52-
mblen_table_sjis,
70+
mblen_table_sjis_mobile,
5371
MBFL_ENCTYPE_GL_UNSAFE,
5472
&vtbl_sjis_docomo_wchar,
5573
&vtbl_wchar_sjis_docomo
@@ -60,7 +78,7 @@ const mbfl_encoding mbfl_encoding_sjis_kddi = {
6078
"SJIS-Mobile#KDDI",
6179
"Shift_JIS",
6280
mbfl_encoding_sjis_kddi_aliases,
63-
mblen_table_sjis,
81+
mblen_table_sjis_mobile,
6482
MBFL_ENCTYPE_GL_UNSAFE,
6583
&vtbl_sjis_kddi_wchar,
6684
&vtbl_wchar_sjis_kddi
@@ -71,7 +89,7 @@ const mbfl_encoding mbfl_encoding_sjis_sb = {
7189
"SJIS-Mobile#SOFTBANK",
7290
"Shift_JIS",
7391
mbfl_encoding_sjis_sb_aliases,
74-
mblen_table_sjis,
92+
mblen_table_sjis_mobile,
7593
MBFL_ENCTYPE_GL_UNSAFE,
7694
&vtbl_sjis_sb_wchar,
7795
&vtbl_wchar_sjis_sb

0 commit comments

Comments
 (0)
Please sign in to comment.