From 63374fab65ceb1e08c5e838b8f97b05e3bae7026 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Mon, 30 Sep 2019 11:07:03 +0200 Subject: [PATCH] Fix #78609: mb_check_encoding() no longer supports stringable objects We apply type juggling for other types than array. --- ext/mbstring/mbstring.c | 28 ++++++++-------------------- ext/mbstring/tests/bug78609.phpt | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+), 20 deletions(-) create mode 100644 ext/mbstring/tests/bug78609.phpt diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c index 173539f4b8c96..516b6143241fa 100644 --- a/ext/mbstring/mbstring.c +++ b/ext/mbstring/mbstring.c @@ -5027,27 +5027,15 @@ 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(HASH_OF(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 { + convert_to_string(input); + 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 0000000000000..11f9b06f13d5c --- /dev/null +++ b/ext/mbstring/tests/bug78609.phpt @@ -0,0 +1,20 @@ +--TEST-- +Bug #78609 (mb_check_encoding() no longer supports stringable objects) +--SKIPIF-- + +--FILE-- + +--EXPECT-- +bool(true)