1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Fixed bug GH-20745 ("Casting out of range floats to int" applies to strings) (#20746)

This reverts the warning for float-strings, to whose it never should have been applied in the first place.
This commit is contained in:
Bob Weinand
2025-12-29 21:29:08 +01:00
committed by GitHub
parent de61d83b0a
commit f754ffa8b2
12 changed files with 4 additions and 34 deletions

2
NEWS
View File

@@ -10,6 +10,8 @@ PHP NEWS
. Fixed bug GH-20714 (Uncatchable exception thrown in generator). (ilutov) . Fixed bug GH-20714 (Uncatchable exception thrown in generator). (ilutov)
. Fixed bug GH-20352 (UAF in php_output_handler_free via re-entrant . Fixed bug GH-20352 (UAF in php_output_handler_free via re-entrant
ob_start() during error deactivation). (ndossche) ob_start() during error deactivation). (ndossche)
. Fixed bug GH-20745 ("Casting out of range floats to int" applies to
strings). (Bob)
- DOM: - DOM:
. Fixed bug GH-20722 (Null pointer dereference in DOM namespace node cloning . Fixed bug GH-20722 (Null pointer dereference in DOM namespace node cloning

View File

@@ -55,9 +55,8 @@ PHP 8.5 UPGRADE NOTES
. Destructuring non-array values (other than NULL) using [] or list() now . Destructuring non-array values (other than NULL) using [] or list() now
emits a warning. emits a warning.
RFC: https://wiki.php.net/rfc/warnings-php-8-5#destructuring_non-array_values RFC: https://wiki.php.net/rfc/warnings-php-8-5#destructuring_non-array_values
. A warning is now emitted when casting floats (or strings that look like . A warning is now emitted when casting floats to int if they cannot be represented
floats) to int if they cannot be represented as one. This affects explicit as one. This affects explicit int casts and implicit int casts.
int casts and implicit int casts.
RFC: https://wiki.php.net/rfc/warnings-php-8-5#casting_out_of_range_floats_to_int RFC: https://wiki.php.net/rfc/warnings-php-8-5#casting_out_of_range_floats_to_int
. A warning is now emitted when casting NAN to other types. . A warning is now emitted when casting NAN to other types.
RFC: https://wiki.php.net/rfc/warnings-php-8-5#coercing_nan_to_other_types RFC: https://wiki.php.net/rfc/warnings-php-8-5#coercing_nan_to_other_types

View File

@@ -40,10 +40,6 @@ Warning: The float NAN is not representable as an int, cast occurred in %s on li
int(0) int(0)
int(3) int(3)
int(3) int(3)
Warning: The float-string "1.0E+121" is not representable as an int, cast occurred in %s on line %d
int(9223372036854775807) int(9223372036854775807)
Warning: The float-string "1.0E+301" is not representable as an int, cast occurred in %s on line %d
int(9223372036854775807) int(9223372036854775807)
int(0) int(0)

View File

@@ -40,10 +40,6 @@ Warning: The float NAN is not representable as an int, cast occurred in %s on li
int(0) int(0)
int(3) int(3)
int(3) int(3)
Warning: The float-string "1.0E+121" is not representable as an int, cast occurred in %s on line %d
int(2147483647) int(2147483647)
Warning: The float-string "1.0E+301" is not representable as an int, cast occurred in %s on line %d
int(2147483647) int(2147483647)
int(0) int(0)

View File

@@ -14,6 +14,5 @@ var_dump($b | 1);
?> ?>
--EXPECTF-- --EXPECTF--
The float-string "1.0E+4%d" is not representable as an int, cast occurred
Implicit conversion from float-string "1.0E+4%d" to int loses precision Implicit conversion from float-string "1.0E+4%d" to int loses precision
int(%d) int(%d)

View File

@@ -25,8 +25,6 @@ var_dump($array[$string_float]);
--EXPECTF-- --EXPECTF--
Warning: The float 1.0E+121 is not representable as an int, cast occurred in %s on line %d Warning: The float 1.0E+121 is not representable as an int, cast occurred in %s on line %d
int(0) int(0)
Warning: The float-string "1.0E+121" is not representable as an int, cast occurred in %s on line %d
bool(true) bool(true)
Warning: The float 1.0E+121 is not representable as an int, cast occurred in %s on line %d Warning: The float 1.0E+121 is not representable as an int, cast occurred in %s on line %d

View File

@@ -77,8 +77,6 @@ var_dump($string);
--EXPECTF-- --EXPECTF--
Warning: The float 1.0E+121 is not representable as an int, cast occurred in %s on line %d Warning: The float 1.0E+121 is not representable as an int, cast occurred in %s on line %d
int(0) int(0)
Warning: The float-string "1.0E+121" is not representable as an int, cast occurred in %s on line %d
int(9223372036854775807) int(9223372036854775807)
Attempt to read Attempt to read
Float Float

View File

@@ -77,8 +77,6 @@ var_dump($string);
--EXPECTF-- --EXPECTF--
Warning: The float 1.0E+121 is not representable as an int, cast occurred in %s on line %d Warning: The float 1.0E+121 is not representable as an int, cast occurred in %s on line %d
int(0) int(0)
Warning: The float-string "1.0E+121" is not representable as an int, cast occurred in %s on line %d
int(2147483647) int(2147483647)
Attempt to read Attempt to read
Float Float

View File

@@ -149,10 +149,8 @@ static zend_always_inline zend_long zend_dval_to_lval_silent(double d)
static zend_always_inline zend_long zend_dval_to_lval_cap(double d, const zend_string *s) static zend_always_inline zend_long zend_dval_to_lval_cap(double d, const zend_string *s)
{ {
if (UNEXPECTED(!zend_finite(d))) { if (UNEXPECTED(!zend_finite(d))) {
zend_oob_string_to_long_error(s);
return 0; return 0;
} else if (!ZEND_DOUBLE_FITS_LONG(d)) { } else if (!ZEND_DOUBLE_FITS_LONG(d)) {
zend_oob_string_to_long_error(s);
return (d > 0 ? ZEND_LONG_MAX : ZEND_LONG_MIN); return (d > 0 ? ZEND_LONG_MAX : ZEND_LONG_MIN);
} }
return (zend_long)d; return (zend_long)d;

View File

@@ -274,7 +274,6 @@ int(1)
string(7) "integer" string(7) "integer"
-- Iteration 20 -- -- Iteration 20 --
string(6) "string" string(6) "string"
2: The float-string "2974394749328742328432" is not representable as an int, cast occurred
bool(true) bool(true)
int(2147483647) int(2147483647)
string(7) "integer" string(7) "integer"
@@ -305,7 +304,6 @@ int(1)
string(7) "integer" string(7) "integer"
-- Iteration 26 -- -- Iteration 26 --
string(6) "string" string(6) "string"
2: The float-string "2974394749328742328432" is not representable as an int, cast occurred
bool(true) bool(true)
int(2147483647) int(2147483647)
string(7) "integer" string(7) "integer"
@@ -675,7 +673,6 @@ int(1)
string(7) "integer" string(7) "integer"
-- Iteration 20 -- -- Iteration 20 --
string(6) "string" string(6) "string"
2: The float-string "2974394749328742328432" is not representable as an int, cast occurred
bool(true) bool(true)
int(2147483647) int(2147483647)
string(7) "integer" string(7) "integer"
@@ -706,7 +703,6 @@ int(1)
string(7) "integer" string(7) "integer"
-- Iteration 26 -- -- Iteration 26 --
string(6) "string" string(6) "string"
2: The float-string "2974394749328742328432" is not representable as an int, cast occurred
bool(true) bool(true)
int(2147483647) int(2147483647)
string(7) "integer" string(7) "integer"

View File

@@ -221,19 +221,11 @@ int(-2147483648)
int(2147483647) int(2147483647)
*** Testing intval() on non integer types *** *** Testing intval() on non integer types ***
Warning: The float-string "-2147483649" is not representable as an int, cast occurred in %s on line %d
int(-2147483648) int(-2147483648)
Warning: The float-string "2147483648" is not representable as an int, cast occurred in %s on line %d
int(2147483647) int(2147483647)
int(0) int(0)
int(0) int(0)
Warning: The float-string "020000000001" is not representable as an int, cast occurred in %s on line %d
int(2147483647) int(2147483647)
Warning: The float-string "-020000000001" is not representable as an int, cast occurred in %s on line %d
int(-2147483648) int(-2147483648)
int(0) int(0)
int(0) int(0)

View File

@@ -75,8 +75,6 @@ foreach ($values as $key => $value) {
</body> </body>
</html> </html>
--- double overflow --- --- double overflow ---
Warning: The float-string "1.2089258196146E+24" is not representable as an int, cast occurred in %s on line %d
<html> <html>
<head> <head>
<title></title> <title></title>