From c2935499b14ee605452016ea00f3c0a94c0a1943 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Sun, 2 Feb 2020 13:38:34 +0100 Subject: Fix #79212: NumberFormatter::format() may detect wrong type We have to convert to number *before* detecting the type, to cater to internal objects implementing `cast_object`. We also get rid of the fallback behavior of using `FORMAT_TYPE_INT32`, because that can no longer happen; after `convert_scalar_to_number_ex` the type is either `IS_LONG` or `IS_DOUBLE`. We cater explicitly to the `IS_ARRAY` case what also avoids triggering a type confusion when `::TYPE_INT64` is passed as `$type`. --- ext/intl/formatter/formatter_format.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'ext/intl/formatter') diff --git a/ext/intl/formatter/formatter_format.c b/ext/intl/formatter/formatter_format.c index f3253dcdb2..9736674d77 100644 --- a/ext/intl/formatter/formatter_format.c +++ b/ext/intl/formatter/formatter_format.c @@ -53,23 +53,23 @@ PHP_FUNCTION( numfmt_format ) /* Fetch the object. */ FORMATTER_METHOD_FETCH_OBJECT; - if(type == FORMAT_TYPE_DEFAULT) { - if(Z_TYPE_P(number) == IS_STRING) { - convert_scalar_to_number_ex(number); - } - - if(Z_TYPE_P(number) == IS_LONG) { - /* take INT32 on 32-bit, int64 on 64-bit */ - type = (sizeof(zend_long) == 8)?FORMAT_TYPE_INT64:FORMAT_TYPE_INT32; - } else if(Z_TYPE_P(number) == IS_DOUBLE) { - type = FORMAT_TYPE_DOUBLE; - } else { - type = FORMAT_TYPE_INT32; - } + if(Z_TYPE_P(number) != IS_ARRAY) { + convert_scalar_to_number_ex(number); + } else { + convert_to_long(number); } - if(Z_TYPE_P(number) != IS_DOUBLE && Z_TYPE_P(number) != IS_LONG) { - convert_scalar_to_number(number ); + if(type == FORMAT_TYPE_DEFAULT) { + switch(Z_TYPE_P(number)) { + case IS_LONG: + /* take INT32 on 32-bit, int64 on 64-bit */ + type = (sizeof(zend_long) == 8)?FORMAT_TYPE_INT64:FORMAT_TYPE_INT32; + break; + case IS_DOUBLE: + type = FORMAT_TYPE_DOUBLE; + break; + EMPTY_SWITCH_DEFAULT_CASE(); + } } switch(type) { -- cgit v1.2.1