@@ -351,9 +351,10 @@ static const mbfl_encoding *php_mb_get_encoding(zend_string *encoding_name, uint
351351
352352/* {{{ static int php_mb_parse_encoding_list()
353353 * Return FAILURE if input contains any illegal encoding, otherwise SUCCESS.
354+ * Emits a ValueError in function context and a warning in INI context, in INI context arg_num must be 0.
354355 */
355- static int
356- php_mb_parse_encoding_list ( const char * value , size_t value_length , const mbfl_encoding * * * return_list , size_t * return_size , int persistent )
356+ static int php_mb_parse_encoding_list ( const char * value , size_t value_length ,
357+ const mbfl_encoding * * * return_list , size_t * return_size , int persistent , uint32_t arg_num )
357358{
358359 if (value == NULL || value_length == 0 ) {
359360 * return_list = NULL ;
@@ -416,15 +417,20 @@ php_mb_parse_encoding_list(const char *value, size_t value_length, const mbfl_en
416417 }
417418 } else {
418419 const mbfl_encoding * encoding = mbfl_name2encoding (p1 );
419- if (encoding ) {
420- * entry ++ = encoding ;
421- n ++ ;
422- } else {
423- php_error_docref (NULL , E_WARNING , "Unknown encoding \"%s\"" , p1 );
420+ if (!encoding ) {
421+ /* Called from an INI setting modification */
422+ if (arg_num == 0 ) {
423+ php_error_docref ("ref.mbstring" , E_WARNING , "INI setting contains invalid encoding \"%s\"" , p1 );
424+ } else {
425+ zend_argument_value_error (arg_num , "contains invalid encoding \"%s\"" , p1 );
426+ }
424427 efree (tmpstr );
425428 pefree (list , persistent );
426429 return FAILURE ;
427430 }
431+
432+ * entry ++ = encoding ;
433+ n ++ ;
428434 }
429435 p1 = p2 + 1 ;
430436 } while (n < size && p2 != NULL );
@@ -439,9 +445,10 @@ php_mb_parse_encoding_list(const char *value, size_t value_length, const mbfl_en
439445
440446/* {{{ static int php_mb_parse_encoding_array()
441447 * Return FAILURE if input contains any illegal encoding, otherwise SUCCESS.
448+ * Emits a ValueError in function context and a warning in INI context, in INI context arg_num must be 0.
442449 */
443- static int
444- php_mb_parse_encoding_array ( HashTable * target_hash , const mbfl_encoding * * * return_list , size_t * return_size )
450+ static int php_mb_parse_encoding_array ( HashTable * target_hash , const mbfl_encoding * * * return_list ,
451+ size_t * return_size , uint32_t arg_num )
445452{
446453 /* Allocate enough space to include the default detect order if "auto" is used. */
447454 size_t size = zend_hash_num_elements (target_hash ) + MBSTRG (default_detect_order_list_size );
@@ -475,8 +482,7 @@ php_mb_parse_encoding_array(HashTable *target_hash, const mbfl_encoding ***retur
475482 * entry ++ = encoding ;
476483 n ++ ;
477484 } else {
478- php_error_docref (NULL , E_WARNING ,
479- "Unknown encoding \"%s\"" , ZSTR_VAL (encoding_str ));
485+ zend_argument_value_error (arg_num , "contains invalid encoding \"%s\"" , ZSTR_VAL (encoding_str ));
480486 zend_string_release (encoding_str );
481487 efree (list );
482488 return FAILURE ;
@@ -576,7 +582,7 @@ static size_t php_mb_zend_encoding_converter(unsigned char **to, size_t *to_leng
576582
577583static int php_mb_zend_encoding_list_parser (const char * encoding_list , size_t encoding_list_len , const zend_encoding * * * return_list , size_t * return_size , int persistent )
578584{
579- return php_mb_parse_encoding_list (encoding_list , encoding_list_len , (const mbfl_encoding * * * )return_list , return_size , persistent );
585+ return php_mb_parse_encoding_list (encoding_list , encoding_list_len , (const mbfl_encoding * * * )return_list , return_size , persistent , 0 );
580586}
581587
582588static const zend_encoding * php_mb_zend_internal_encoding_getter (void )
@@ -869,7 +875,7 @@ static PHP_INI_MH(OnUpdate_mbstring_detect_order)
869875 return SUCCESS ;
870876 }
871877
872- if (FAILURE == php_mb_parse_encoding_list (ZSTR_VAL (new_value ), ZSTR_LEN (new_value ), & list , & size , 1 ) || size == 0 ) {
878+ if (FAILURE == php_mb_parse_encoding_list (ZSTR_VAL (new_value ), ZSTR_LEN (new_value ), & list , & size , 1 , 0 ) || size == 0 ) {
873879 return FAILURE ;
874880 }
875881
@@ -885,7 +891,7 @@ static PHP_INI_MH(OnUpdate_mbstring_detect_order)
885891static int _php_mb_ini_mbstring_http_input_set (const char * new_value , size_t new_value_length ) {
886892 const mbfl_encoding * * list ;
887893 size_t size ;
888- if (FAILURE == php_mb_parse_encoding_list (new_value , new_value_length , & list , & size , 1 ) || size == 0 ) {
894+ if (FAILURE == php_mb_parse_encoding_list (new_value , new_value_length , & list , & size , 1 , 0 ) || size == 0 ) {
889895 return FAILURE ;
890896 }
891897 if (MBSTRG (http_input_list )) {
@@ -1551,12 +1557,12 @@ PHP_FUNCTION(mb_detect_order)
15511557 const mbfl_encoding * * list ;
15521558 size_t size ;
15531559 if (order_ht ) {
1554- if (FAILURE == php_mb_parse_encoding_array (order_ht , & list , & size )) {
1555- RETURN_FALSE ;
1560+ if (FAILURE == php_mb_parse_encoding_array (order_ht , & list , & size , 1 )) {
1561+ RETURN_THROWS () ;
15561562 }
15571563 } else {
1558- if (FAILURE == php_mb_parse_encoding_list (ZSTR_VAL (order_str ), ZSTR_LEN (order_str ), & list , & size , 0 )) {
1559- RETURN_FALSE ;
1564+ if (FAILURE == php_mb_parse_encoding_list (ZSTR_VAL (order_str ), ZSTR_LEN (order_str ), & list , & size , 0 , 1 )) {
1565+ RETURN_THROWS () ;
15601566 }
15611567 }
15621568
@@ -2699,13 +2705,14 @@ PHP_FUNCTION(mb_convert_encoding)
26992705 }
27002706
27012707 if (from_encodings_ht ) {
2702- if (php_mb_parse_encoding_array (from_encodings_ht , & from_encodings , & num_from_encodings ) == FAILURE ) {
2703- RETURN_FALSE ;
2708+ if (php_mb_parse_encoding_array (from_encodings_ht , & from_encodings , & num_from_encodings , 3 ) == FAILURE ) {
2709+ RETURN_THROWS () ;
27042710 }
27052711 free_from_encodings = 1 ;
27062712 } else if (from_encodings_str ) {
2707- if (php_mb_parse_encoding_list (ZSTR_VAL (from_encodings_str ), ZSTR_LEN (from_encodings_str ), & from_encodings , & num_from_encodings , 0 ) == FAILURE ) {
2708- RETURN_FALSE ;
2713+ if (php_mb_parse_encoding_list (ZSTR_VAL (from_encodings_str ), ZSTR_LEN (from_encodings_str ),
2714+ & from_encodings , & num_from_encodings , 0 , 3 ) == FAILURE ) {
2715+ RETURN_THROWS ();
27092716 }
27102717 free_from_encodings = 1 ;
27112718 } else {
@@ -2885,13 +2892,13 @@ PHP_FUNCTION(mb_detect_encoding)
28852892
28862893 /* make encoding list */
28872894 if (encoding_ht ) {
2888- if (FAILURE == php_mb_parse_encoding_array (encoding_ht , & elist , & size )) {
2889- RETURN_FALSE ;
2895+ if (FAILURE == php_mb_parse_encoding_array (encoding_ht , & elist , & size , 2 )) {
2896+ RETURN_THROWS () ;
28902897 }
28912898 free_elist = 1 ;
28922899 } else if (encoding_str ) {
2893- if (FAILURE == php_mb_parse_encoding_list (ZSTR_VAL (encoding_str ), ZSTR_LEN (encoding_str ), & elist , & size , 0 )) {
2894- RETURN_FALSE ;
2900+ if (FAILURE == php_mb_parse_encoding_list (ZSTR_VAL (encoding_str ), ZSTR_LEN (encoding_str ), & elist , & size , 0 , 2 )) {
2901+ RETURN_THROWS () ;
28952902 }
28962903 free_elist = 1 ;
28972904 } else {
@@ -3285,12 +3292,12 @@ PHP_FUNCTION(mb_convert_variables)
32853292
32863293 /* pre-conversion encoding */
32873294 if (from_enc_ht ) {
3288- if (php_mb_parse_encoding_array (from_enc_ht , & elist , & elistsz ) == FAILURE ) {
3289- RETURN_FALSE ;
3295+ if (php_mb_parse_encoding_array (from_enc_ht , & elist , & elistsz , 2 ) == FAILURE ) {
3296+ RETURN_THROWS () ;
32903297 }
32913298 } else {
3292- if (php_mb_parse_encoding_list (ZSTR_VAL (from_enc_str ), ZSTR_LEN (from_enc_str ), & elist , & elistsz , 0 ) == FAILURE ) {
3293- RETURN_FALSE ;
3299+ if (php_mb_parse_encoding_list (ZSTR_VAL (from_enc_str ), ZSTR_LEN (from_enc_str ), & elist , & elistsz , 0 , 2 ) == FAILURE ) {
3300+ RETURN_THROWS () ;
32943301 }
32953302 }
32963303
0 commit comments