@@ -106,8 +106,6 @@ static void php_mb_gpc_set_input_encoding(const zend_encoding *encoding);
106
106
107
107
static inline zend_bool php_mb_is_unsupported_no_encoding (enum mbfl_no_encoding no_enc );
108
108
109
- static inline zend_bool php_mb_is_no_encoding_unicode (enum mbfl_no_encoding no_enc );
110
-
111
109
static inline zend_bool php_mb_is_no_encoding_utf8 (enum mbfl_no_encoding no_enc );
112
110
/* }}} */
113
111
@@ -3172,13 +3170,6 @@ static inline zend_bool php_mb_is_unsupported_no_encoding(enum mbfl_no_encoding
3172
3170
}
3173
3171
3174
3172
3175
- /* See mbfl_no_encoding definition for list of unicode encodings */
3176
- static inline zend_bool php_mb_is_no_encoding_unicode (enum mbfl_no_encoding no_enc )
3177
- {
3178
- return (no_enc >= mbfl_no_encoding_ucs4 && no_enc <= mbfl_no_encoding_utf8_sb );
3179
- }
3180
-
3181
-
3182
3173
/* See mbfl_no_encoding definition for list of UTF-8 encodings */
3183
3174
static inline zend_bool php_mb_is_no_encoding_utf8 (enum mbfl_no_encoding no_enc )
3184
3175
{
@@ -5143,10 +5134,18 @@ static inline char* php_mb_chr(zend_long cp, const char* enc, size_t *output_len
5143
5134
}
5144
5135
}
5145
5136
5146
- if (php_mb_is_no_encoding_utf8 (no_enc )) {
5137
+ if (php_mb_is_unsupported_no_encoding (no_enc )) {
5138
+ php_error_docref (NULL , E_WARNING , "Unsupported encoding \"%s\"" , enc );
5139
+ return NULL ;
5140
+ }
5141
+
5142
+ if (cp < 0 || cp > 0x10ffff ) {
5143
+ return NULL ;
5144
+ }
5147
5145
5148
- if (0 > cp || cp > 0x10ffff || (cp > 0xd7ff && 0xe000 > cp )) {
5149
- cp = MBSTRG (current_filter_illegal_substchar );
5146
+ if (php_mb_is_no_encoding_utf8 (no_enc )) {
5147
+ if (cp > 0xd7ff && 0xe000 > cp ) {
5148
+ return NULL ;
5150
5149
}
5151
5150
5152
5151
if (cp < 0x80 ) {
@@ -5182,20 +5181,6 @@ static inline char* php_mb_chr(zend_long cp, const char* enc, size_t *output_len
5182
5181
}
5183
5182
5184
5183
return ret ;
5185
-
5186
- } else if (php_mb_is_unsupported_no_encoding (no_enc )) {
5187
- php_error_docref (NULL , E_WARNING , "Unsupported encoding \"%s\"" , enc );
5188
- return NULL ;
5189
- }
5190
-
5191
- if (0 > cp || 0x10ffff < cp ) {
5192
-
5193
- if (php_mb_is_no_encoding_unicode (MBSTRG (current_internal_encoding )-> no_encoding )) {
5194
- cp = MBSTRG (current_filter_illegal_substchar );
5195
- } else {
5196
- cp = 0x3f ;
5197
- }
5198
-
5199
5184
}
5200
5185
5201
5186
buf_len = 4 ;
@@ -5206,9 +5191,21 @@ static inline char* php_mb_chr(zend_long cp, const char* enc, size_t *output_len
5206
5191
buf [3 ] = cp & 0xff ;
5207
5192
buf [4 ] = 0 ;
5208
5193
5209
- ret = php_mb_convert_encoding (buf , buf_len , enc , "UCS-4BE" , & ret_len );
5210
- efree (buf );
5194
+ {
5195
+ long orig_illegalchars = MBSTRG (illegalchars );
5196
+ MBSTRG (illegalchars ) = 0 ;
5197
+ ret = php_mb_convert_encoding (buf , buf_len , enc , "UCS-4BE" , & ret_len );
5198
+ if (MBSTRG (illegalchars ) != 0 ) {
5199
+ efree (buf );
5200
+ efree (ret );
5201
+ MBSTRG (illegalchars ) = orig_illegalchars ;
5202
+ return NULL ;
5203
+ }
5204
+
5205
+ MBSTRG (illegalchars ) = orig_illegalchars ;
5206
+ }
5211
5207
5208
+ efree (buf );
5212
5209
if (output_len ) {
5213
5210
* output_len = ret_len ;
5214
5211
}
0 commit comments