summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph M. Becker <cmbecker69@gmx.de>2019-09-30 13:05:51 +0200
committerChristoph M. Becker <cmbecker69@gmx.de>2019-09-30 13:06:57 +0200
commit70f367d48aebebbfb676019446d14ad76eca2076 (patch)
tree4aba65e9dbde640bf1ad4d7abfe183fa5f0364f5
parent27f5785363e6da7ff1c58d6a54888dceb0b4a540 (diff)
parent2046b3ce4fd09063fdbe1eaf1824b5a1d0bed125 (diff)
downloadphp-git-70f367d48aebebbfb676019446d14ad76eca2076.tar.gz
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fix #78609: mb_check_encoding() no longer supports stringable objects
-rw-r--r--NEWS2
-rw-r--r--ext/mbstring/mbstring.c30
-rw-r--r--ext/mbstring/tests/bug78609.phpt20
3 files changed, 32 insertions, 20 deletions
diff --git a/NEWS b/NEWS
index 4f46995c4e..a9570b5fb2 100644
--- a/NEWS
+++ b/NEWS
@@ -15,6 +15,8 @@ PHP NEWS
- MBString:
. Fixed bug #78579 (mb_decode_numericentity: args number inconsistency).
(cmb)
+ . Fixed bug #78609 (mb_check_encoding() no longer supports stringable
+ objects). (cmb)
- Standard:
. Fixed bug #78549 (Stack overflow due to nested serialized input). (Nikita)
diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c
index 4d75a2825c..f1a617810a 100644
--- a/ext/mbstring/mbstring.c
+++ b/ext/mbstring/mbstring.c
@@ -4952,27 +4952,17 @@ PHP_FUNCTION(mb_check_encoding)
RETURN_FALSE;
}
- switch(Z_TYPE_P(input)) {
- case IS_LONG:
- case IS_DOUBLE:
- case IS_NULL:
- case IS_TRUE:
- case IS_FALSE:
- RETURN_TRUE;
- break;
- case IS_STRING:
- if (!php_mb_check_encoding(Z_STRVAL_P(input), Z_STRLEN_P(input), enc ? ZSTR_VAL(enc): NULL)) {
- RETURN_FALSE;
- }
- break;
- case IS_ARRAY:
- if (!php_mb_check_encoding_recursive(Z_ARRVAL_P(input), enc)) {
- RETURN_FALSE;
- }
- break;
- default:
- php_error_docref(NULL, E_WARNING, "Input is something other than scalar or array");
+ if (Z_TYPE_P(input) == IS_ARRAY) {
+ if (!php_mb_check_encoding_recursive(HASH_OF(input), enc)) {
+ RETURN_FALSE;
+ }
+ } else {
+ if (!try_convert_to_string(input)) {
+ RETURN_FALSE;
+ }
+ if (!php_mb_check_encoding(Z_STRVAL_P(input), Z_STRLEN_P(input), enc ? ZSTR_VAL(enc): NULL)) {
RETURN_FALSE;
+ }
}
RETURN_TRUE;
}
diff --git a/ext/mbstring/tests/bug78609.phpt b/ext/mbstring/tests/bug78609.phpt
new file mode 100644
index 0000000000..11f9b06f13
--- /dev/null
+++ b/ext/mbstring/tests/bug78609.phpt
@@ -0,0 +1,20 @@
+--TEST--
+Bug #78609 (mb_check_encoding() no longer supports stringable objects)
+--SKIPIF--
+<?php
+if (!extension_loaded('mbstring')) die('skip mbstring extension not available');
+?>
+--FILE--
+<?php
+class Foo
+{
+ public function __toString()
+ {
+ return 'string_representation';
+ }
+}
+
+var_dump(mb_check_encoding(new Foo, 'UTF-8'));
+?>
+--EXPECT--
+bool(true)