Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ PHP NEWS
especially UTF-8. (Nicolas Grekas)
. Improved performance of htmlspecialchars() when nothing needs encoding.
(Nicolas Grekas)
. bindec(), octdec(), hexdec() and base_convert() now throw an Exception
when the passed string contains characters that are invalid for the
specified number base. (Sjoerd Langkemper)

- URI:
. Fix casing of enum cases in UriHostType and UrlHostType to match the RFC
Expand Down
3 changes: 3 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ PHP 8.7 UPGRADE NOTES
application terminate one attribute and append further ones.

- Standard:
. bindec(), octdec(), hexdec() and base_convert() now throw an Exception
when the passed string contains characters that are invalid for the
specified number base.
. The number of filters that can be chained in a php://filter URL is limited
to 16 by default. Set the stream context option max_filter_count to change
this.
Expand Down
25 changes: 18 additions & 7 deletions ext/standard/math.c
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ PHPAPI zend_long _php_math_basetolong(zval *arg, int base)
/*
* Convert a string representation of a base(2-36) number to a zval.
*/
PHPAPI void _php_math_basetozval(zend_string *str, int base, zval *ret)
PHPAPI zend_result _php_math_basetozval(zend_string *str, int base, zval *ret)
{
zend_long num = 0;
double fnum = 0;
Expand Down Expand Up @@ -903,7 +903,6 @@ PHPAPI void _php_math_basetozval(zend_string *str, int base, zval *ret)
num = num * base + c;
break;
} else {
zend_error(E_NOTICE, "Input number is larger than PHP_INT_MAX, precision has been lost in conversion");
fnum = (double)num;
mode = 1;
}
Expand All @@ -914,14 +913,17 @@ PHPAPI void _php_math_basetozval(zend_string *str, int base, zval *ret)
}

if (invalidchars > 0) {
zend_error(E_DEPRECATED, "Invalid characters passed for attempted conversion, these have been ignored");
zend_throw_exception_ex(NULL, 0, "Invalid characters passed for attempted conversion");
return FAILURE;
}

if (mode == 1) {
zend_error(E_NOTICE, "Input number is larger than PHP_INT_MAX, precision has been lost in conversion");
ZVAL_DOUBLE(ret, fnum);
} else {
ZVAL_LONG(ret, num);
}
return SUCCESS;
}
/* }}} */

Expand Down Expand Up @@ -1039,7 +1041,9 @@ PHP_FUNCTION(bindec)
Z_PARAM_STR(arg)
ZEND_PARSE_PARAMETERS_END();

_php_math_basetozval(arg, 2, return_value);
if (SUCCESS != _php_math_basetozval(arg, 2, return_value)) {
RETURN_THROWS();
}
}
/* }}} */

Expand All @@ -1052,7 +1056,9 @@ PHP_FUNCTION(hexdec)
Z_PARAM_STR(arg)
ZEND_PARSE_PARAMETERS_END();

_php_math_basetozval(arg, 16, return_value);
if (SUCCESS != _php_math_basetozval(arg, 16, return_value)) {
RETURN_THROWS();
}
}
/* }}} */

Expand All @@ -1065,7 +1071,9 @@ PHP_FUNCTION(octdec)
Z_PARAM_STR(arg)
ZEND_PARSE_PARAMETERS_END();

_php_math_basetozval(arg, 8, return_value);
if (SUCCESS != _php_math_basetozval(arg, 8, return_value)) {
RETURN_THROWS();
}
}
/* }}} */

Expand Down Expand Up @@ -1142,7 +1150,10 @@ PHP_FUNCTION(base_convert)
RETURN_THROWS();
}

_php_math_basetozval(number, (int)frombase, &temp);
if (SUCCESS != _php_math_basetozval(number, (int)frombase, &temp)) {
RETURN_THROWS();
}

result = _php_math_zvaltobase(&temp, (int)tobase);
if (!result) {
RETURN_THROWS();
Expand Down
2 changes: 1 addition & 1 deletion ext/standard/php_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ PHPAPI zend_string *_php_math_number_format_ex(double d, int dec, const char *de
PHPAPI zend_string *_php_math_number_format_long(zend_long num, zend_long dec, const char *dec_point, size_t dec_point_len, const char *thousand_sep, size_t thousand_sep_len);
PHPAPI zend_string * _php_math_longtobase(zend_long arg, int base);
PHPAPI zend_long _php_math_basetolong(zval *arg, int base);
PHPAPI void _php_math_basetozval(zend_string *str, int base, zval *ret);
PHPAPI zend_result _php_math_basetozval(zend_string *str, int base, zval *ret);
PHPAPI zend_string * _php_math_zvaltobase(zval *arg, int base);

#include <math.h>
Expand Down
Loading
Loading