Skip to content

Commit 6fc8d01

Browse files
pakutomaalexdowad
authored andcommitted
Fix GH-10648: add check function pointer into mbfl_encoding
Previously, mbstring used the same logic for encoding validation as for encoding conversion. However, there are cases where we want to use different logic for validation and conversion. For example, if a string ends up with missing input required by the encoding, or if a character is input that is invalid as an encoding but can be converted, the conversion should succeed and the validation should fail. To achieve this, a function pointer mb_check_fn has been added to struct mbfl_encoding to implement the logic used for validation. Also, added implementation of validation logic for UTF-7, UTF7-IMAP, ISO-2022-JP and JIS.
1 parent a082696 commit 6fc8d01

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1745
-114
lines changed

UPGRADING

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,16 @@ PHP 8.2 UPGRADE NOTES
218218
dba_fetch(string|array $key, $skip, $dba): string|false
219219
is still accepted, but it is recommended to use the new standard variant.
220220

221+
- MBString
222+
. mb_check_encoding() now checks input encoding more strictly.
223+
. mb_detect_encoding() now checks input encoding more strictly
224+
when strict detection is enabled.
225+
. mb_convert_encoding() checks the input encoding more strictly
226+
if multiple encodings are passed to from_encoding
227+
and the mbstring.strict_detection INI directive is set to 1.
228+
This change only affects the encoding selection,
229+
not the result of the conversion.
230+
221231
- Random
222232
. random_bytes() and random_int() now throw \Random\RandomException on CSPRNG failure.
223233
Previously a plain \Exception was thrown.

ext/mbstring/libmbfl/filters/mbfilter_7bit.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ const mbfl_encoding mbfl_encoding_7bit = {
6464
&vtbl_7bit_wchar,
6565
&vtbl_wchar_7bit,
6666
mb_7bit_to_wchar,
67-
mb_wchar_to_7bit
67+
mb_wchar_to_7bit,
68+
NULL
6869
};
6970

7071
#define CK(statement) do { if ((statement) < 0) return (-1); } while (0)

ext/mbstring/libmbfl/filters/mbfilter_base64.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ const mbfl_encoding mbfl_encoding_base64 = {
4444
NULL,
4545
NULL,
4646
mb_base64_to_wchar,
47-
mb_wchar_to_base64
47+
mb_wchar_to_base64,
48+
NULL
4849
};
4950

5051
const struct mbfl_convert_vtbl vtbl_8bit_b64 = {

ext/mbstring/libmbfl/filters/mbfilter_big5.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ const mbfl_encoding mbfl_encoding_big5 = {
6969
&vtbl_big5_wchar,
7070
&vtbl_wchar_big5,
7171
mb_big5_to_wchar,
72-
mb_wchar_to_big5
72+
mb_wchar_to_big5,
73+
NULL
7374
};
7475

7576
const mbfl_encoding mbfl_encoding_cp950 = {
@@ -82,7 +83,8 @@ const mbfl_encoding mbfl_encoding_cp950 = {
8283
&vtbl_cp950_wchar,
8384
&vtbl_wchar_cp950,
8485
mb_cp950_to_wchar,
85-
mb_wchar_to_cp950
86+
mb_wchar_to_cp950,
87+
NULL
8688
};
8789

8890
const struct mbfl_convert_vtbl vtbl_big5_wchar = {

ext/mbstring/libmbfl/filters/mbfilter_cp5022x.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ const mbfl_encoding mbfl_encoding_cp50220 = {
6161
&vtbl_cp50220_wchar,
6262
&vtbl_wchar_cp50220,
6363
mb_cp5022x_to_wchar,
64-
mb_wchar_to_cp50220
64+
mb_wchar_to_cp50220,
65+
NULL
6566
};
6667

6768
const mbfl_encoding mbfl_encoding_cp50221 = {
@@ -74,7 +75,8 @@ const mbfl_encoding mbfl_encoding_cp50221 = {
7475
&vtbl_cp50221_wchar,
7576
&vtbl_wchar_cp50221,
7677
mb_cp5022x_to_wchar,
77-
mb_wchar_to_cp50221
78+
mb_wchar_to_cp50221,
79+
NULL
7880
};
7981

8082
const mbfl_encoding mbfl_encoding_cp50222 = {
@@ -87,7 +89,8 @@ const mbfl_encoding mbfl_encoding_cp50222 = {
8789
&vtbl_cp50222_wchar,
8890
&vtbl_wchar_cp50222,
8991
mb_cp5022x_to_wchar,
90-
mb_wchar_to_cp50222
92+
mb_wchar_to_cp50222,
93+
NULL
9194
};
9295

9396
const struct mbfl_convert_vtbl vtbl_cp50220_wchar = {

ext/mbstring/libmbfl/filters/mbfilter_cp51932.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ const mbfl_encoding mbfl_encoding_cp51932 = {
6969
&vtbl_cp51932_wchar,
7070
&vtbl_wchar_cp51932,
7171
mb_cp51932_to_wchar,
72-
mb_wchar_to_cp51932
72+
mb_wchar_to_cp51932,
73+
NULL
7374
};
7475

7576
const struct mbfl_convert_vtbl vtbl_cp51932_wchar = {

ext/mbstring/libmbfl/filters/mbfilter_cp932.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ const mbfl_encoding mbfl_encoding_cp932 = {
100100
&vtbl_cp932_wchar,
101101
&vtbl_wchar_cp932,
102102
mb_cp932_to_wchar,
103-
mb_wchar_to_cp932
103+
mb_wchar_to_cp932,
104+
NULL
104105
};
105106

106107
const struct mbfl_convert_vtbl vtbl_cp932_wchar = {
@@ -133,7 +134,8 @@ const mbfl_encoding mbfl_encoding_sjiswin = {
133134
&vtbl_sjiswin_wchar,
134135
&vtbl_wchar_sjiswin,
135136
mb_cp932_to_wchar,
136-
mb_wchar_to_sjiswin
137+
mb_wchar_to_sjiswin,
138+
NULL
137139
};
138140

139141
const struct mbfl_convert_vtbl vtbl_sjiswin_wchar = {

ext/mbstring/libmbfl/filters/mbfilter_cp936.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ const mbfl_encoding mbfl_encoding_cp936 = {
6868
&vtbl_cp936_wchar,
6969
&vtbl_wchar_cp936,
7070
mb_cp936_to_wchar,
71-
mb_wchar_to_cp936
71+
mb_wchar_to_cp936,
72+
NULL
7273
};
7374

7475
const struct mbfl_convert_vtbl vtbl_cp936_wchar = {

ext/mbstring/libmbfl/filters/mbfilter_euc_cn.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ const mbfl_encoding mbfl_encoding_euc_cn = {
6767
&vtbl_euccn_wchar,
6868
&vtbl_wchar_euccn,
6969
mb_euccn_to_wchar,
70-
mb_wchar_to_euccn
70+
mb_wchar_to_euccn,
71+
NULL
7172
};
7273

7374
const struct mbfl_convert_vtbl vtbl_euccn_wchar = {

ext/mbstring/libmbfl/filters/mbfilter_euc_jp.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ const mbfl_encoding mbfl_encoding_euc_jp = {
6868
&vtbl_eucjp_wchar,
6969
&vtbl_wchar_eucjp,
7070
mb_eucjp_to_wchar,
71-
mb_wchar_to_eucjp
71+
mb_wchar_to_eucjp,
72+
NULL
7273
};
7374

7475
const struct mbfl_convert_vtbl vtbl_eucjp_wchar = {

ext/mbstring/libmbfl/filters/mbfilter_euc_jp_win.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ const mbfl_encoding mbfl_encoding_eucjp_win = {
6969
&vtbl_eucjpwin_wchar,
7070
&vtbl_wchar_eucjpwin,
7171
mb_eucjpwin_to_wchar,
72-
mb_wchar_to_eucjpwin
72+
mb_wchar_to_eucjpwin,
73+
NULL
7374
};
7475

7576
const struct mbfl_convert_vtbl vtbl_eucjpwin_wchar = {

ext/mbstring/libmbfl/filters/mbfilter_euc_kr.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ const mbfl_encoding mbfl_encoding_euc_kr = {
6666
&vtbl_euckr_wchar,
6767
&vtbl_wchar_euckr,
6868
mb_euckr_to_wchar,
69-
mb_wchar_to_euckr
69+
mb_wchar_to_euckr,
70+
NULL
7071
};
7172

7273
const struct mbfl_convert_vtbl vtbl_euckr_wchar = {

ext/mbstring/libmbfl/filters/mbfilter_euc_tw.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ const mbfl_encoding mbfl_encoding_euc_tw = {
6868
&vtbl_euctw_wchar,
6969
&vtbl_wchar_euctw,
7070
mb_euctw_to_wchar,
71-
mb_wchar_to_euctw
71+
mb_wchar_to_euctw,
72+
NULL
7273
};
7374

7475
const struct mbfl_convert_vtbl vtbl_euctw_wchar = {

ext/mbstring/libmbfl/filters/mbfilter_gb18030.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ const mbfl_encoding mbfl_encoding_gb18030 = {
4949
&vtbl_gb18030_wchar,
5050
&vtbl_wchar_gb18030,
5151
mb_gb18030_to_wchar,
52-
mb_wchar_to_gb18030
52+
mb_wchar_to_gb18030,
53+
NULL
5354
};
5455

5556
const struct mbfl_convert_vtbl vtbl_gb18030_wchar = {

ext/mbstring/libmbfl/filters/mbfilter_htmlent.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ const mbfl_encoding mbfl_encoding_html_ent = {
6666
&vtbl_html_wchar,
6767
&vtbl_wchar_html,
6868
mb_htmlent_to_wchar,
69-
mb_wchar_to_htmlent
69+
mb_wchar_to_htmlent,
70+
NULL
7071
};
7172

7273
const struct mbfl_convert_vtbl vtbl_wchar_html = {

ext/mbstring/libmbfl/filters/mbfilter_hz.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ const mbfl_encoding mbfl_encoding_hz = {
4747
&vtbl_hz_wchar,
4848
&vtbl_wchar_hz,
4949
mb_hz_to_wchar,
50-
mb_wchar_to_hz
50+
mb_wchar_to_hz,
51+
NULL
5152
};
5253

5354
const struct mbfl_convert_vtbl vtbl_hz_wchar = {

ext/mbstring/libmbfl/filters/mbfilter_iso2022_jp_ms.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ const mbfl_encoding mbfl_encoding_2022jpms = {
5151
&vtbl_2022jpms_wchar,
5252
&vtbl_wchar_2022jpms,
5353
mb_iso2022jpms_to_wchar,
54-
mb_wchar_to_iso2022jpms
54+
mb_wchar_to_iso2022jpms,
55+
NULL
5556
};
5657

5758
const struct mbfl_convert_vtbl vtbl_2022jpms_wchar = {

ext/mbstring/libmbfl/filters/mbfilter_iso2022_kr.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ const mbfl_encoding mbfl_encoding_2022kr = {
5454
&vtbl_2022kr_wchar,
5555
&vtbl_wchar_2022kr,
5656
mb_iso2022kr_to_wchar,
57-
mb_wchar_to_iso2022kr
57+
mb_wchar_to_iso2022kr,
58+
NULL
5859
};
5960

6061
const struct mbfl_convert_vtbl vtbl_wchar_2022kr = {

ext/mbstring/libmbfl/filters/mbfilter_iso2022jp_mobile.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ const mbfl_encoding mbfl_encoding_2022jp_kddi = {
7171
&vtbl_2022jp_kddi_wchar,
7272
&vtbl_wchar_2022jp_kddi,
7373
mb_iso2022jp_kddi_to_wchar,
74-
mb_wchar_to_iso2022jp_kddi
74+
mb_wchar_to_iso2022jp_kddi,
75+
NULL
7576
};
7677

7778
const struct mbfl_convert_vtbl vtbl_2022jp_kddi_wchar = {

0 commit comments

Comments
 (0)