Skip to content

Commit

Permalink
Use different mblen_table for different SJIS variants
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdowad committed Jan 6, 2023
1 parent d104481 commit 3152b7b
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 10 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ PHP NEWS
. Fixed bug GH-10112 (LDAP\Connection::__construct() refers to ldap_create()).
(cmb)

- MBString:
. 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)

- Opcache:
. Fix inverted bailout value in zend_runtime_jit() (Max Kellermann).
. Fix access to uninitialized variable in accel_preload(). (nielsdos)
Expand Down
4 changes: 2 additions & 2 deletions ext/mbstring/libmbfl/filters/mbfilter_sjis.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

static int mbfl_filt_conv_sjis_wchar_flush(mbfl_convert_filter *filter);

const unsigned char mblen_table_sjis[] = { /* 0x81-0x9F,0xE0-0xFC */
const unsigned char mblen_table_sjis[] = { /* 0x81-0x9F,0xE0-0xEF */
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
Expand All @@ -54,7 +54,7 @@ const unsigned char mblen_table_sjis[] = { /* 0x81-0x9F,0xE0-0xFC */
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
};

static const char *mbfl_encoding_sjis_aliases[] = {"x-sjis", "SHIFT-JIS", NULL};
Expand Down
4 changes: 2 additions & 2 deletions ext/mbstring/libmbfl/filters/mbfilter_sjis_2004.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include "unicode_table_jis2004.h"
#include "unicode_table_jis.h"

extern const unsigned char mblen_table_sjis[];
extern const unsigned char mblen_table_sjis_mobile[];

extern int mbfl_bisec_srch(int w, const unsigned short *tbl, int n);
extern int mbfl_bisec_srch2(int w, const unsigned short tbl[], int n);
Expand All @@ -51,7 +51,7 @@ const mbfl_encoding mbfl_encoding_sjis2004 = {
"SJIS-2004",
"Shift_JIS",
mbfl_encoding_sjis2004_aliases,
mblen_table_sjis,
mblen_table_sjis_mobile, /* Leading byte values used for SJIS-2004 are the same as mobile SJIS variants */
MBFL_ENCTYPE_GL_UNSAFE,
&vtbl_sjis2004_wchar,
&vtbl_wchar_sjis2004
Expand Down
21 changes: 19 additions & 2 deletions ext/mbstring/libmbfl/filters/mbfilter_sjis_mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,24 @@

#include "sjis_mac2uni.h"

extern const unsigned char mblen_table_sjis[];
const unsigned char mblen_table_sjismac[] = { /* 0x81-0x9F,0xE0-0xED */
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
};

static int mbfl_filt_conv_wchar_sjis_mac_flush(mbfl_convert_filter *filter);
static int mbfl_filt_conv_sjis_mac_wchar_flush(mbfl_convert_filter *filter);
Expand All @@ -47,7 +64,7 @@ const mbfl_encoding mbfl_encoding_sjis_mac = {
"SJIS-mac",
"Shift_JIS",
mbfl_encoding_sjis_mac_aliases,
mblen_table_sjis,
mblen_table_sjismac,
MBFL_ENCTYPE_GL_UNSAFE,
&vtbl_sjis_mac_wchar,
&vtbl_wchar_sjis_mac
Expand Down
26 changes: 22 additions & 4 deletions ext/mbstring/libmbfl/filters/mbfilter_sjis_mobile.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,26 @@

#include "emoji2uni.h"

const unsigned char mblen_table_sjis_mobile[] = { /* 0x81-0x9F,0xE0-0xFC */
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1
};

extern int mbfl_bisec_srch2(int w, const unsigned short tbl[], int n);
extern const unsigned char mblen_table_sjis[];

static int mbfl_filt_conv_sjis_wchar_flush(mbfl_convert_filter *filter);

Expand All @@ -49,7 +67,7 @@ const mbfl_encoding mbfl_encoding_sjis_docomo = {
"SJIS-Mobile#DOCOMO",
"Shift_JIS",
mbfl_encoding_sjis_docomo_aliases,
mblen_table_sjis,
mblen_table_sjis_mobile,
MBFL_ENCTYPE_GL_UNSAFE,
&vtbl_sjis_docomo_wchar,
&vtbl_wchar_sjis_docomo
Expand All @@ -60,7 +78,7 @@ const mbfl_encoding mbfl_encoding_sjis_kddi = {
"SJIS-Mobile#KDDI",
"Shift_JIS",
mbfl_encoding_sjis_kddi_aliases,
mblen_table_sjis,
mblen_table_sjis_mobile,
MBFL_ENCTYPE_GL_UNSAFE,
&vtbl_sjis_kddi_wchar,
&vtbl_wchar_sjis_kddi
Expand All @@ -71,7 +89,7 @@ const mbfl_encoding mbfl_encoding_sjis_sb = {
"SJIS-Mobile#SOFTBANK",
"Shift_JIS",
mbfl_encoding_sjis_sb_aliases,
mblen_table_sjis,
mblen_table_sjis_mobile,
MBFL_ENCTYPE_GL_UNSAFE,
&vtbl_sjis_sb_wchar,
&vtbl_wchar_sjis_sb
Expand Down

0 comments on commit 3152b7b

Please sign in to comment.