From 1f6ac30769f58b1c304e4e9fda44097fa6d4f29e Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Wed, 17 Sep 2025 15:06:25 +0200 Subject: [PATCH 01/10] Allow empty statements before declare(strict_types) Fixes GH-19719 Closes GH-19859 --- NEWS | 2 ++ Zend/tests/gh19719.phpt | 21 +++++++++++++++++++++ Zend/zend_compile.c | 2 +- 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 Zend/tests/gh19719.phpt diff --git a/NEWS b/NEWS index 6bd00000a1000..7b6f8f9440d83 100644 --- a/NEWS +++ b/NEWS @@ -13,6 +13,8 @@ PHP NEWS using OPcache). (timwolla) . Fixed bug GH-19480 (error_log php.ini cannot be unset when open_basedir is configured). (nielsdos) + . Fixed bug GH-19719 (Allow empty statements before declare(strict_types)). + (nielsdos) - Curl: . Fix cloning of CURLOPT_POSTFIELDS when using the clone operator instead diff --git a/Zend/tests/gh19719.phpt b/Zend/tests/gh19719.phpt new file mode 100644 index 0000000000000..715e847846fe1 --- /dev/null +++ b/Zend/tests/gh19719.phpt @@ -0,0 +1,21 @@ +--TEST-- +GH-19719: Allow empty expressions before declare(strict_types) +--FILE-- + +getMessage(), "\n"; +} + +?> +--EXPECTF-- +takesInt(): Argument #1 ($x) must be of type int, string given, called in %s on line %d diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index ad735c41acaff..f43fdd7b31827 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -7008,7 +7008,7 @@ static void zend_compile_declare(zend_ast *ast) /* {{{ */ } else if (zend_string_equals_literal_ci(name, "strict_types")) { zval value_zv; - if (FAILURE == zend_is_first_statement(ast, /* allow_nop */ 0)) { + if (FAILURE == zend_is_first_statement(ast, /* allow_nop */ true)) { zend_error_noreturn(E_COMPILE_ERROR, "strict_types declaration must be " "the very first statement in the script"); } From 9fe6fb2566ee521cb3af13eda103c52c9276d4a9 Mon Sep 17 00:00:00 2001 From: Jacob Adams Date: Tue, 24 Jun 2025 15:56:47 -0600 Subject: [PATCH 02/10] ext/iconv: Build fix for illumos distributions and solaris close GH-18933 --- NEWS | 3 +++ ext/iconv/iconv.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 7b6f8f9440d83..4e7e74d304644 100644 --- a/NEWS +++ b/NEWS @@ -34,6 +34,9 @@ PHP NEWS . Fixed GH-8157 (post_max_size evaluates .user.ini too late in php-fpm). (Jakub Zelenka) +- Iconv: + . Extends the ICONV_CONST preprocessor for illumos/solaris. (jMichaelA) + - Opcache: . Fixed bug GH-19669 (assertion failure in zend_jit_trace_type_to_info_ex). (Arnaud) diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c index 092e15669875e..2b19b1e3c7828 100644 --- a/ext/iconv/iconv.c +++ b/ext/iconv/iconv.c @@ -43,7 +43,7 @@ #undef iconv #endif -#if defined(__NetBSD__) +#if defined(__NetBSD__) || (defined(__sun) && defined(__SVR4)) // unfortunately, netbsd has still the old non posix conformant signature // libiconv tends to match the eventual system's iconv too. #define ICONV_CONST const From 5897071ab642f41fb19b7b5bc16537318c6235ea Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Sun, 21 Sep 2025 21:56:04 +0200 Subject: [PATCH 03/10] Fix refcounting on zend_empty_array in ext-uri (GH-19908) Fixes GH-19892 --- NEWS | 1 + Zend/zend_API.h | 1 + ext/uri/php_uri.c | 2 +- ext/uri/tests/gh19892.phpt | 12 ++++++++++++ 4 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 ext/uri/tests/gh19892.phpt diff --git a/NEWS b/NEWS index 4e7e74d304644..c05b203a8d873 100644 --- a/NEWS +++ b/NEWS @@ -58,6 +58,7 @@ PHP NEWS . Add new Uri\UriError exception that is thrown for internal error conditions. (timwolla) . Further clean up the internal API. (timwolla) + . Fixed bug GH-19892 (Refcounting on zend_empty_array). (ilutov, timwolla) - Windows: . Fix GH-19722 (_get_osfhandle asserts in debug mode when given a socket). diff --git a/Zend/zend_API.h b/Zend/zend_API.h index f4a6fc5f50e9d..8cde8317530e4 100644 --- a/Zend/zend_API.h +++ b/Zend/zend_API.h @@ -1364,6 +1364,7 @@ ZEND_API zend_result zend_try_assign_typed_ref_zval_ex(zend_reference *ref, zval #define ZEND_TRY_ASSIGN_REF_ARR(zv, arr) do { \ ZEND_ASSERT(Z_ISREF_P(zv)); \ + ZEND_ASSERT(!(GC_FLAGS(arr) & GC_IMMUTABLE)); \ _ZEND_TRY_ASSIGN_ARR(zv, arr, 1); \ } while (0) diff --git a/ext/uri/php_uri.c b/ext/uri/php_uri.c index bfe14e117477f..308c54ddc4a86 100644 --- a/ext/uri/php_uri.c +++ b/ext/uri/php_uri.c @@ -308,7 +308,7 @@ static zend_result pass_errors_by_ref_and_free(zval *errors_zv, zval *errors) return SUCCESS; } - ZEND_TRY_ASSIGN_REF_ARR(errors_zv, Z_ARRVAL_P(errors)); + ZEND_TRY_ASSIGN_REF_TMP(errors_zv, errors); if (EG(exception)) { return FAILURE; } diff --git a/ext/uri/tests/gh19892.phpt b/ext/uri/tests/gh19892.phpt new file mode 100644 index 0000000000000..42a9c660e0d05 --- /dev/null +++ b/ext/uri/tests/gh19892.phpt @@ -0,0 +1,12 @@ +--TEST-- +GH-19892: Successful \Uri\WhatWg\Url::parse() with empty errors array +--FILE-- + +--EXPECT-- +array(0) { +} From d58ecb5d3d1b0e28cbf978142729b339ded2ddf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Sun, 21 Sep 2025 22:23:33 +0200 Subject: [PATCH 04/10] uri: Clean up logic in `uri_unserialize()` (#19903) * uri: Check early whether we would be overwriting an existing URI in `uri_unserialize()` * uri: Access the CE consistently in `uri_unserialize()` --- ext/uri/php_uri.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ext/uri/php_uri.c b/ext/uri/php_uri.c index 308c54ddc4a86..67de8110702d2 100644 --- a/ext/uri/php_uri.c +++ b/ext/uri/php_uri.c @@ -823,6 +823,13 @@ static void uri_unserialize(INTERNAL_FUNCTION_PARAMETERS) ZEND_PARSE_PARAMETERS_END(); zend_object *object = Z_OBJ_P(ZEND_THIS); + uri_internal_t *internal_uri = uri_internal_from_obj(object); + if (internal_uri->uri != NULL) { + /* Intentionally throw two exceptions for proper chaining. */ + zend_throw_error(NULL, "Cannot modify readonly object of class %s", ZSTR_VAL(object->ce->name)); + zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %s object", ZSTR_VAL(object->ce->name)); + RETURN_THROWS(); + } /* Verify the expected number of elements, this implicitly ensures that no additional elements are present. */ if (zend_hash_num_elements(data) != 2) { @@ -849,13 +856,6 @@ static void uri_unserialize(INTERNAL_FUNCTION_PARAMETERS) RETURN_THROWS(); } - uri_internal_t *internal_uri = uri_internal_from_obj(object); - if (internal_uri->uri != NULL) { - /* Intentionally throw two exceptions for proper chaining. */ - zend_throw_error(NULL, "Cannot modify readonly object of class %s", ZSTR_VAL(Z_OBJCE_P(ZEND_THIS)->name)); - zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %s object", ZSTR_VAL(object->ce->name)); - RETURN_THROWS(); - } internal_uri->uri = internal_uri->parser->parse(Z_STRVAL_P(uri_zv), Z_STRLEN_P(uri_zv), NULL, NULL, true); if (internal_uri->uri == NULL) { zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %s object", ZSTR_VAL(object->ce->name)); From c7485a0b8f83078c2b082dfc9e5a7aa9b60522c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Sun, 21 Sep 2025 22:23:51 +0200 Subject: [PATCH 05/10] uri: Fix const-correctness violation in `uri_*_from_obj` (#19907) The functions derived non-const pointers from a const-pointer, which is not correct. Since php/php-src#19854 no `const` pointers are passed into these functions, so we can just make the parameter non-const. --- ext/uri/php_uri_common.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/uri/php_uri_common.h b/ext/uri/php_uri_common.h index 0932413486b20..2e2f9ce6452f7 100644 --- a/ext/uri/php_uri_common.h +++ b/ext/uri/php_uri_common.h @@ -147,11 +147,11 @@ typedef struct uri_object_t { zend_object std; } uri_object_t; -static inline uri_object_t *uri_object_from_obj(const zend_object *object) { +static inline uri_object_t *uri_object_from_obj(zend_object *object) { return (uri_object_t*)((char*)(object) - XtOffsetOf(uri_object_t, std)); } -static inline uri_internal_t *uri_internal_from_obj(const zend_object *object) { +static inline uri_internal_t *uri_internal_from_obj(zend_object *object) { return &(uri_object_from_obj(object)->internal); } From 5f00673a4503d3e3f052ddb675bc66f9ff0cd88e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Sun, 21 Sep 2025 23:19:54 +0200 Subject: [PATCH 06/10] uri: Fix handling of large port numbers in URI struct (#19905) * uri: Fix handling of large port numbers in URI struct * uri: Explain the choice of type for `php_uri.port` * NEWS --- NEWS | 2 + ext/standard/ftp_fopen_wrapper.c | 2 +- ext/standard/http_fopen_wrapper.c | 4 +- ext/uri/php_uri.h | 4 +- ext/uri/tests/100.phpt | 21 ++++++++- ext/uri/tests/102.phpt | 71 +++++++++++++++++++++++++++++++ ext/zend_test/test.c | 54 +++++++++++++++++++++++ 7 files changed, 153 insertions(+), 5 deletions(-) create mode 100644 ext/uri/tests/102.phpt diff --git a/NEWS b/NEWS index c05b203a8d873..548349b406375 100644 --- a/NEWS +++ b/NEWS @@ -59,6 +59,8 @@ PHP NEWS conditions. (timwolla) . Further clean up the internal API. (timwolla) . Fixed bug GH-19892 (Refcounting on zend_empty_array). (ilutov, timwolla) + . Fixed handling of port numbers > 65535 with the internal + `php_uri_parse_to_struct()` API. (timwolla) - Windows: . Fix GH-19722 (_get_osfhandle asserts in debug mode when given a socket). diff --git a/ext/standard/ftp_fopen_wrapper.c b/ext/standard/ftp_fopen_wrapper.c index c747020ad6290..b36d232de9534 100644 --- a/ext/standard/ftp_fopen_wrapper.c +++ b/ext/standard/ftp_fopen_wrapper.c @@ -155,7 +155,7 @@ static php_stream *php_ftp_fopen_connect(php_stream_wrapper *wrapper, const char if (resource->port == 0) resource->port = 21; - transport_len = (int)spprintf(&transport, 0, "tcp://%s:%d", ZSTR_VAL(resource->host), resource->port); + transport_len = (int)spprintf(&transport, 0, "tcp://%s:" ZEND_LONG_FMT, ZSTR_VAL(resource->host), resource->port); stream = php_stream_xport_create(transport, transport_len, REPORT_ERRORS, STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT, NULL, NULL, context, NULL, NULL); efree(transport); if (stream == NULL) { diff --git a/ext/standard/http_fopen_wrapper.c b/ext/standard/http_fopen_wrapper.c index b8ede088517ca..e342c77666662 100644 --- a/ext/standard/http_fopen_wrapper.c +++ b/ext/standard/http_fopen_wrapper.c @@ -446,7 +446,7 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, use_proxy = 1; transport_string = zend_string_copy(Z_STR_P(tmpzval)); } else { - transport_string = zend_strpprintf(0, "%s://%s:%d", use_ssl ? "ssl" : "tcp", ZSTR_VAL(resource->host), resource->port); + transport_string = zend_strpprintf(0, "%s://%s:" ZEND_LONG_FMT, use_ssl ? "ssl" : "tcp", ZSTR_VAL(resource->host), resource->port); } } @@ -1083,7 +1083,7 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, header_info.location = NULL; } if ((use_ssl && resource->port != 443) || (!use_ssl && resource->port != 80)) { - spprintf(&new_path, 0, "%s://%s:%d%s", ZSTR_VAL(resource->scheme), + spprintf(&new_path, 0, "%s://%s:" ZEND_LONG_FMT "%s", ZSTR_VAL(resource->scheme), ZSTR_VAL(resource->host), resource->port, loc_path); } else { spprintf(&new_path, 0, "%s://%s%s", ZSTR_VAL(resource->scheme), diff --git a/ext/uri/php_uri.h b/ext/uri/php_uri.h index dd796433f0975..9cfe6dce1ab97 100644 --- a/ext/uri/php_uri.h +++ b/ext/uri/php_uri.h @@ -27,7 +27,9 @@ typedef struct php_uri { zend_string *user; zend_string *password; zend_string *host; - unsigned short port; + /* port is a zend_long to match the userland port getter, which + * returns the port in zval. */ + zend_long port; zend_string *path; zend_string *query; zend_string *fragment; diff --git a/ext/uri/tests/100.phpt b/ext/uri/tests/100.phpt index bf3d34c29255a..0c1abcdd00b6f 100644 --- a/ext/uri/tests/100.phpt +++ b/ext/uri/tests/100.phpt @@ -10,7 +10,7 @@ var_dump(zend_test_uri_parser("https://%65xample:%65xample@%65xample.com:123/%65 ?> --EXPECT-- -array(2) { +array(3) { ["normalized"]=> array(8) { ["scheme"]=> @@ -49,4 +49,23 @@ array(2) { ["fragment"]=> string(9) "%65xample" } + ["struct"]=> + array(8) { + ["scheme"]=> + string(5) "https" + ["username"]=> + string(9) "%65xample" + ["password"]=> + string(9) "%65xample" + ["host"]=> + string(13) "%65xample.com" + ["port"]=> + int(123) + ["path"]=> + string(15) "/%65xample.html" + ["query"]=> + string(19) "%65xample=%65xample" + ["fragment"]=> + string(9) "%65xample" + } } diff --git a/ext/uri/tests/102.phpt b/ext/uri/tests/102.phpt new file mode 100644 index 0000000000000..6080c1be884cd --- /dev/null +++ b/ext/uri/tests/102.phpt @@ -0,0 +1,71 @@ +--TEST-- +Test the handling large ports for the uri struct +--EXTENSIONS-- +uri +zend_test +--FILE-- + +--EXPECT-- +array(3) { + ["normalized"]=> + array(8) { + ["scheme"]=> + string(5) "https" + ["username"]=> + NULL + ["password"]=> + NULL + ["host"]=> + string(11) "example.com" + ["port"]=> + int(42424242) + ["path"]=> + string(0) "" + ["query"]=> + NULL + ["fragment"]=> + NULL + } + ["raw"]=> + array(8) { + ["scheme"]=> + string(5) "https" + ["username"]=> + NULL + ["password"]=> + NULL + ["host"]=> + string(11) "example.com" + ["port"]=> + int(42424242) + ["path"]=> + string(0) "" + ["query"]=> + NULL + ["fragment"]=> + NULL + } + ["struct"]=> + array(8) { + ["scheme"]=> + string(5) "https" + ["username"]=> + NULL + ["password"]=> + NULL + ["host"]=> + string(11) "example.com" + ["port"]=> + int(42424242) + ["path"]=> + string(0) "" + ["query"]=> + NULL + ["fragment"]=> + NULL + } +} diff --git a/ext/zend_test/test.c b/ext/zend_test/test.c index 99bdae0bcc7ac..6b0139e186b62 100644 --- a/ext/zend_test/test.c +++ b/ext/zend_test/test.c @@ -746,6 +746,11 @@ static ZEND_FUNCTION(zend_test_uri_parser) RETURN_THROWS(); } + php_uri *uri_struct = php_uri_parse_to_struct(parser, ZSTR_VAL(uri_string), ZSTR_LEN(uri_string), PHP_URI_COMPONENT_READ_MODE_RAW, false); + if (uri_struct == NULL) { + RETURN_THROWS(); + } + zval value; array_init(return_value); @@ -787,7 +792,56 @@ static ZEND_FUNCTION(zend_test_uri_parser) php_uri_get_fragment(uri, PHP_URI_COMPONENT_READ_MODE_RAW, &value); zend_hash_add(Z_ARR(raw), ZSTR_KNOWN(ZEND_STR_FRAGMENT), &value); zend_hash_str_add(Z_ARR_P(return_value), "raw", strlen("raw"), &raw); + zval from_struct; + zval dummy; + array_init(&from_struct); + if (uri_struct->scheme) { + ZVAL_STR_COPY(&dummy, uri_struct->scheme); + } else { + ZVAL_NULL(&dummy); + } + zend_hash_add(Z_ARR(from_struct), ZSTR_KNOWN(ZEND_STR_SCHEME), &dummy); + if (uri_struct->user) { + ZVAL_STR_COPY(&dummy, uri_struct->user); + } else { + ZVAL_NULL(&dummy); + } + zend_hash_add(Z_ARR(from_struct), ZSTR_KNOWN(ZEND_STR_USERNAME), &dummy); + if (uri_struct->password) { + ZVAL_STR_COPY(&dummy, uri_struct->password); + } else { + ZVAL_NULL(&dummy); + } + zend_hash_add(Z_ARR(from_struct), ZSTR_KNOWN(ZEND_STR_PASSWORD), &dummy); + if (uri_struct->host) { + ZVAL_STR_COPY(&dummy, uri_struct->host); + } else { + ZVAL_NULL(&dummy); + } + zend_hash_add(Z_ARR(from_struct), ZSTR_KNOWN(ZEND_STR_HOST), &dummy); + ZVAL_LONG(&dummy, uri_struct->port); + zend_hash_add(Z_ARR(from_struct), ZSTR_KNOWN(ZEND_STR_PORT), &dummy); + if (uri_struct->path) { + ZVAL_STR_COPY(&dummy, uri_struct->path); + } else { + ZVAL_NULL(&dummy); + } + zend_hash_add(Z_ARR(from_struct), ZSTR_KNOWN(ZEND_STR_PATH), &dummy); + if (uri_struct->query) { + ZVAL_STR_COPY(&dummy, uri_struct->query); + } else { + ZVAL_NULL(&dummy); + } + zend_hash_add(Z_ARR(from_struct), ZSTR_KNOWN(ZEND_STR_QUERY), &dummy); + if (uri_struct->fragment) { + ZVAL_STR_COPY(&dummy, uri_struct->fragment); + } else { + ZVAL_NULL(&dummy); + } + zend_hash_add(Z_ARR(from_struct), ZSTR_KNOWN(ZEND_STR_FRAGMENT), &dummy); + zend_hash_str_add(Z_ARR_P(return_value), "struct", strlen("struct"), &from_struct); + php_uri_struct_free(uri_struct); php_uri_free(uri); } From b4ed215299a1bd4b405959cf14541e4e2760956f Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Sun, 21 Sep 2025 23:53:16 +0100 Subject: [PATCH 07/10] core: Warn when non-representable floats are coerced to int (#19760) RFC: https://wiki.php.net/rfc/warnings-php-8-5#casting_out_of_range_floats_to_int --- Zend/Optimizer/sccp.c | 6 +- Zend/Optimizer/zend_inference.c | 1 + .../bitwise_not_precision_exception.phpt | 2 +- Zend/tests/bug46701.phpt | 10 +- Zend/tests/bug78340.phpt | 2 +- Zend/tests/falsetoarray_003.phpt | 2 +- Zend/tests/int_overflow_32bit.phpt | 11 +- Zend/tests/int_overflow_64bit.phpt | 8 +- Zend/tests/int_underflow_32bit.phpt | 10 +- ...rrayObject_container_offset_behaviour.phpt | 89 +++++++ .../array_container_offset_behaviour.phpt | 89 +++++++ Zend/tests/{ => offsets}/array_offset.phpt | 0 .../tests/{ => offsets}/array_offset_002.phpt | 2 +- .../false_container_offset_behaviour.phpt | 89 +++++++ .../null_container_offset_behaviour.phpt | 87 +++++++ .../string_container_offset_behaviour.phpt | 95 +++++++- Zend/tests/offsets/test_offset_helpers.inc | 2 +- .../runtime_compile_time_binary_operands.phpt | 2 +- .../float_to_int}/dval_to_lval_32.phpt | 13 +- .../float_to_int}/dval_to_lval_64.phpt | 11 +- .../explicit_casts_should_not_warn.phpt | 14 +- .../explicit_casts_should_not_warn_32bit.phpt | 12 +- .../non-rep-float-as-int-extra1.phpt | 19 ++ .../non-rep-float-as-int-extra2.phpt | 17 ++ .../non-rep-float-as-int-extra3.phpt | 18 ++ .../non-rep-float-as-int-extra4.phpt | 18 ++ ...g_float_does_not_fit_zend_long_arrays.phpt | 11 +- ..._float_does_not_fit_zend_long_strings.phpt | 3 + ..._does_not_fit_zend_long_strings_32bit.phpt | 3 + .../type_coercion/int_special_values.phpt | 8 +- Zend/zend_compile.c | 31 ++- Zend/zend_execute.c | 86 ++++--- Zend/zend_operators.c | 44 ++-- Zend/zend_operators.h | 30 ++- Zend/zend_vm_def.h | 10 + Zend/zend_vm_execute.h | 120 ++++++++++ ext/date/tests/bug79015.phpt | 1 + ext/dom/php_dom.c | 2 +- ext/intl/tests/gh13766.phpt | 2 +- ext/opcache/jit/zend_jit_helpers.c | 226 +++++++++--------- ext/opcache/tests/jit/add_011.phpt | 5 +- ext/opcache/tests/jit/array_elem_002.phpt | 2 +- ext/opcache/tests/jit/gh19669-001.phpt | 3 +- ext/opcache/tests/jit/gh19669-002.phpt | 3 +- .../tests/jit/reg_alloc_003_32bits.phpt | 2 +- ext/openssl/tests/openssl_decrypt_basic.phpt | 3 +- ext/standard/array.c | 18 +- .../gettype_settype_variation2.phpt | 12 + .../tests/general_functions/intval.phpt | 24 +- ext/standard/tests/math/bug30695.phpt | 16 +- ext/standard/tests/strings/bug47842.phpt | 4 +- ext/standard/tests/strings/pack.phpt | 22 +- ext/standard/tests/strings/pack64.phpt | 18 +- .../tests/strings/vprintf_variation12.phpt | 8 +- .../tests/strings/vprintf_variation14.phpt | 8 +- .../tests/strings/vprintf_variation15.phpt | 6 +- .../strings/vprintf_variation15_64bit.phpt | 4 +- .../tests/strings/vprintf_variation16.phpt | 8 +- .../tests/strings/vprintf_variation4.phpt | 4 +- main/php_variables.c | 2 +- tests/lang/bug27354.phpt | 2 +- .../operators/bitwiseNot_basiclong_64bit.phpt | 2 +- 62 files changed, 1107 insertions(+), 275 deletions(-) rename Zend/tests/{ => offsets}/array_offset.phpt (100%) rename Zend/tests/{ => offsets}/array_offset_002.phpt (80%) rename Zend/tests/{ => type_coercion/float_to_int}/dval_to_lval_32.phpt (51%) rename Zend/tests/{ => type_coercion/float_to_int}/dval_to_lval_64.phpt (52%) create mode 100644 Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra1.phpt create mode 100644 Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra2.phpt create mode 100644 Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra3.phpt create mode 100644 Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra4.phpt diff --git a/Zend/Optimizer/sccp.c b/Zend/Optimizer/sccp.c index c1faf2a3fbe03..9b8216e589bea 100644 --- a/Zend/Optimizer/sccp.c +++ b/Zend/Optimizer/sccp.c @@ -371,7 +371,7 @@ static inline zend_result fetch_array_elem(zval **result, zval *op1, zval *op2) *result = zend_hash_index_find(Z_ARR_P(op1), Z_LVAL_P(op2)); return SUCCESS; case IS_DOUBLE: { - zend_long lval = zend_dval_to_lval(Z_DVAL_P(op2)); + zend_long lval = zend_dval_to_lval_silent(Z_DVAL_P(op2)); if (!zend_is_long_compatible(Z_DVAL_P(op2), lval)) { return FAILURE; } @@ -459,7 +459,7 @@ static inline zend_result ct_eval_del_array_elem(zval *result, const zval *key) zend_hash_index_del(Z_ARR_P(result), Z_LVAL_P(key)); break; case IS_DOUBLE: { - zend_long lval = zend_dval_to_lval(Z_DVAL_P(key)); + zend_long lval = zend_dval_to_lval_silent(Z_DVAL_P(key)); if (!zend_is_long_compatible(Z_DVAL_P(key), lval)) { return FAILURE; } @@ -504,7 +504,7 @@ static inline zend_result ct_eval_add_array_elem(zval *result, zval *value, cons value = zend_hash_index_update(Z_ARR_P(result), Z_LVAL_P(key), value); break; case IS_DOUBLE: { - zend_long lval = zend_dval_to_lval(Z_DVAL_P(key)); + zend_long lval = zend_dval_to_lval_silent(Z_DVAL_P(key)); if (!zend_is_long_compatible(Z_DVAL_P(key), lval)) { return FAILURE; } diff --git a/Zend/Optimizer/zend_inference.c b/Zend/Optimizer/zend_inference.c index 62e04cb0e306b..7f84ed55de60e 100644 --- a/Zend/Optimizer/zend_inference.c +++ b/Zend/Optimizer/zend_inference.c @@ -5283,6 +5283,7 @@ ZEND_API bool zend_may_throw_ex(const zend_op *opline, const zend_ssa_op *ssa_op case ZEND_CAST: switch (opline->extended_value) { case IS_LONG: + return (t1 & (MAY_BE_DOUBLE|MAY_BE_STRING|MAY_BE_OBJECT)); case IS_DOUBLE: return (t1 & MAY_BE_OBJECT); case IS_STRING: diff --git a/Zend/tests/bitwise_not_precision_exception.phpt b/Zend/tests/bitwise_not_precision_exception.phpt index fa821100464e7..e28bf8f4e17b6 100644 --- a/Zend/tests/bitwise_not_precision_exception.phpt +++ b/Zend/tests/bitwise_not_precision_exception.phpt @@ -12,4 +12,4 @@ try { } ?> --EXPECT-- -Implicit conversion from float INF to int loses precision +The float INF is not representable as an int, cast occurred diff --git a/Zend/tests/bug46701.phpt b/Zend/tests/bug46701.phpt index e7cc823d85c5e..620d5209443e5 100644 --- a/Zend/tests/bug46701.phpt +++ b/Zend/tests/bug46701.phpt @@ -27,11 +27,11 @@ new foo; ?> --EXPECTF-- -Deprecated: Implicit conversion from float 3428599296 to int loses precision in %s on line %d +Warning: The float 3428599296 is not representable as an int, cast occurred in %s on line %d -Deprecated: Implicit conversion from float 3459455488 to int loses precision in %s on line %d +Warning: The float 3459455488 is not representable as an int, cast occurred in %s on line %d -Deprecated: Implicit conversion from float 3459616768 to int loses precision in %s on line %d +Warning: The float 3459616768 is not representable as an int, cast occurred in %s on line %d array(3) { [-866368000]=> int(1) @@ -41,10 +41,10 @@ array(3) { int(3) } -Deprecated: Implicit conversion from float 3459455488 to int loses precision in %s on line %d +Warning: The float 3459455488 is not representable as an int, cast occurred in %s on line %d int(2) -Deprecated: Implicit conversion from float 3459616768 to int loses precision in %s on line %d +Warning: The float 3459616768 is not representable as an int, cast occurred in %s on line %d array(1) { [-835350528]=> int(3) diff --git a/Zend/tests/bug78340.phpt b/Zend/tests/bug78340.phpt index 4012e83af6acd..22ea0c19353e9 100644 --- a/Zend/tests/bug78340.phpt +++ b/Zend/tests/bug78340.phpt @@ -32,7 +32,7 @@ class lib { function stream_stat() { return [ - 'dev' => 3632233996, + 'dev' => PHP_INT_MAX, 'size' => strlen($this->bytes), 'ino' => $this->ino ]; diff --git a/Zend/tests/falsetoarray_003.phpt b/Zend/tests/falsetoarray_003.phpt index 11b32771e1fc1..117e443ef9584 100644 --- a/Zend/tests/falsetoarray_003.phpt +++ b/Zend/tests/falsetoarray_003.phpt @@ -11,6 +11,6 @@ $a=[]; ?> DONE --EXPECTF-- -Err: Implicit conversion from float %f to int loses precision +Err: The float %f is not representable as an int, cast occurred Err: Undefined array key %i DONE diff --git a/Zend/tests/int_overflow_32bit.phpt b/Zend/tests/int_overflow_32bit.phpt index 15dce6eea7dcf..e337932bcd554 100644 --- a/Zend/tests/int_overflow_32bit.phpt +++ b/Zend/tests/int_overflow_32bit.phpt @@ -20,10 +20,19 @@ foreach ($doubles as $d) { echo "Done\n"; ?> ---EXPECT-- +--EXPECTF-- +Warning: The float 2147483648 is not representable as an int, cast occurred in %s on line %d int(-2147483648) + +Warning: The float 2147483649 is not representable as an int, cast occurred in %s on line %d int(-2147483647) + +Warning: The float 2147483658 is not representable as an int, cast occurred in %s on line %d int(-2147483638) + +Warning: The float 2147483748 is not representable as an int, cast occurred in %s on line %d int(-2147483548) + +Warning: The float 2147484648 is not representable as an int, cast occurred in %s on line %d int(-2147482648) Done diff --git a/Zend/tests/int_overflow_64bit.phpt b/Zend/tests/int_overflow_64bit.phpt index 7c541250205c8..cc14e14949ca8 100644 --- a/Zend/tests/int_overflow_64bit.phpt +++ b/Zend/tests/int_overflow_64bit.phpt @@ -22,10 +22,16 @@ foreach ($doubles as $d) { echo "Done\n"; ?> ---EXPECT-- +--EXPECTF-- int(9223372036854775807) + +Warning: The float %f is not representable as an int, cast occurred in %s on line %d int(-9223372036854775808) + +Warning: The float %f is not representable as an int, cast occurred in %s on line %d int(-9223372036854775808) + +Warning: The float %f is not representable as an int, cast occurred in %s on line %d int(0) int(-9223372036854775808) int(-9223372036854775808) diff --git a/Zend/tests/int_underflow_32bit.phpt b/Zend/tests/int_underflow_32bit.phpt index 71464a758aeea..88c0e79834b4b 100644 --- a/Zend/tests/int_underflow_32bit.phpt +++ b/Zend/tests/int_underflow_32bit.phpt @@ -20,10 +20,18 @@ foreach ($doubles as $d) { echo "Done\n"; ?> ---EXPECT-- +--EXPECTF-- int(-2147483648) + +Warning: The float -2147483649 is not representable as an int, cast occurred in %s on line %d int(2147483647) + +Warning: The float -2147483658 is not representable as an int, cast occurred in %s on line %d int(2147483638) + +Warning: The float -2147483748 is not representable as an int, cast occurred in %s on line %d int(2147483548) + +Warning: The float -2147484648 is not representable as an int, cast occurred in %s on line %d int(2147482648) Done diff --git a/Zend/tests/offsets/ArrayObject_container_offset_behaviour.phpt b/Zend/tests/offsets/ArrayObject_container_offset_behaviour.phpt index c44c2df24f77b..bcfbd4b317367 100644 --- a/Zend/tests/offsets/ArrayObject_container_offset_behaviour.phpt +++ b/Zend/tests/offsets/ArrayObject_container_offset_behaviour.phpt @@ -132,6 +132,93 @@ OUTPUT; $EXPECTED_OUTPUT_FLOAT_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTF_OUTPUT_FLOAT_OFFSETS) . '$/s'; +const EXPECTF_OUTPUT_FLOAT_OOB_OFFSETS = << --EXPECT-- -Err: Implicit conversion from float 1.0E+20 to int loses precision +Err: The float 1.0E+20 is not representable as an int, cast occurred array(0) { } diff --git a/Zend/tests/offsets/false_container_offset_behaviour.phpt b/Zend/tests/offsets/false_container_offset_behaviour.phpt index 736e51830a453..0647400baee0a 100644 --- a/Zend/tests/offsets/false_container_offset_behaviour.phpt +++ b/Zend/tests/offsets/false_container_offset_behaviour.phpt @@ -135,6 +135,93 @@ OUTPUT; $EXPECTED_OUTPUT_FLOAT_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTF_OUTPUT_FLOAT_OFFSETS) . '$/s'; +const EXPECTF_OUTPUT_FLOAT_OOB_OFFSETS = << '\d+', '%x' => '[0-9a-fA-F]+', '%f' => '[+-]?(?:\d+|(?=\.\d))(?:\.\d+)?(?:[Ee][+-]?\d+)?', - '%F' => '([+-]?(?:\d+|(?=\.\d))(?:\.\d+)?(?:[Ee][+-]?\d+)?)|(NAN)|(INF)', + '%F' => '([+-]?(?:\d+|(?=\.\d))(?:\.\d+)?(?:[Ee][+-]?\d+)?)|(NAN)|(INF)|([+-]?\d+)', '%c' => '.', '%0' => '\x00', ]); diff --git a/Zend/tests/runtime_compile_time_binary_operands.phpt b/Zend/tests/runtime_compile_time_binary_operands.phpt index e18134283e83d..948246f73b403 100644 --- a/Zend/tests/runtime_compile_time_binary_operands.phpt +++ b/Zend/tests/runtime_compile_time_binary_operands.phpt @@ -8,7 +8,7 @@ if (getenv("SKIP_SLOW_TESTS")) die('skip slow test'); ?> --FILE-- ---EXPECT-- +--EXPECTF-- +Warning: The float -4.000000000000001E+21 is not representable as an int, cast occurred in %s on line %d int(-2056257536) + +Warning: The float -4.0000000000000005E+21 is not representable as an int, cast occurred in %s on line %d int(-2055733248) + +Warning: The float -4.0E+21 is not representable as an int, cast occurred in %s on line %d int(-2055208960) + +Warning: The float -3.9999999999999995E+21 is not representable as an int, cast occurred in %s on line %d int(-2054684672) + +Warning: The float -3.999999999999999E+21 is not representable as an int, cast occurred in %s on line %d int(-2054160384) + +Warning: The float -2147483649.8 is not representable as an int, cast occurred in %s on line %d int(2147483647) diff --git a/Zend/tests/dval_to_lval_64.phpt b/Zend/tests/type_coercion/float_to_int/dval_to_lval_64.phpt similarity index 52% rename from Zend/tests/dval_to_lval_64.phpt rename to Zend/tests/type_coercion/float_to_int/dval_to_lval_64.phpt index b54f861bf55cf..993950534fc17 100644 --- a/Zend/tests/dval_to_lval_64.phpt +++ b/Zend/tests/type_coercion/float_to_int/dval_to_lval_64.phpt @@ -21,9 +21,18 @@ if (PHP_INT_SIZE != 8) } ?> ---EXPECT-- +--EXPECTF-- +Warning: The float -4.000000000000001E+21 is not representable as an int, cast occurred in %s on line %d int(2943463994971652096) + +Warning: The float -4.0000000000000005E+21 is not representable as an int, cast occurred in %s on line %d int(2943463994972176384) + +Warning: The float -4.0E+21 is not representable as an int, cast occurred in %s on line %d int(2943463994972700672) + +Warning: The float -3.9999999999999995E+21 is not representable as an int, cast occurred in %s on line %d int(2943463994973224960) + +Warning: The float -3.999999999999999E+21 is not representable as an int, cast occurred in %s on line %d int(2943463994973749248) diff --git a/Zend/tests/type_coercion/float_to_int/explicit_casts_should_not_warn.phpt b/Zend/tests/type_coercion/float_to_int/explicit_casts_should_not_warn.phpt index 71c68e57574bf..2b876597b9b1e 100644 --- a/Zend/tests/type_coercion/float_to_int/explicit_casts_should_not_warn.phpt +++ b/Zend/tests/type_coercion/float_to_int/explicit_casts_should_not_warn.phpt @@ -1,5 +1,5 @@ --TEST-- -Explicit (int) cast must not warn +Explicit (int) cast must not warn if value is representable --SKIPIF-- ---EXPECT-- +--EXPECTF-- int(3) int(3) + +Warning: The float 1.0E+121 is not representable as an int, cast occurred in %s on line %d int(0) + +Warning: The float 1.0E+301 is not representable as an int, cast occurred in %s on line %d int(0) + +Warning: The float NAN is not representable as an int, cast occurred in %s on line %d int(0) 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) + +Warning: The float-string "1.0E+301" is not representable as an int, cast occurred in %s on line %d int(9223372036854775807) int(0) diff --git a/Zend/tests/type_coercion/float_to_int/explicit_casts_should_not_warn_32bit.phpt b/Zend/tests/type_coercion/float_to_int/explicit_casts_should_not_warn_32bit.phpt index fee011df06ea8..b34e762dfff35 100644 --- a/Zend/tests/type_coercion/float_to_int/explicit_casts_should_not_warn_32bit.phpt +++ b/Zend/tests/type_coercion/float_to_int/explicit_casts_should_not_warn_32bit.phpt @@ -25,14 +25,24 @@ foreach($values as $value) { } ?> ---EXPECT-- +--EXPECTF-- int(3) int(3) + +Warning: The float 1.0E+121 is not representable as an int, cast occurred in %s on line %d int(0) + +Warning: The float 1.0E+301 is not representable as an int, cast occurred in %s on line %d int(0) + +Warning: The float NAN is not representable as an int, cast occurred in %s on line %d int(0) 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) + +Warning: The float-string "1.0E+301" is not representable as an int, cast occurred in %s on line %d int(2147483647) int(0) diff --git a/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra1.phpt b/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra1.phpt new file mode 100644 index 0000000000000..aacf0dc855190 --- /dev/null +++ b/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra1.phpt @@ -0,0 +1,19 @@ +--TEST-- +Non rep float string to int conversions should not crash when modified +--FILE-- + +--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 +int(%d) diff --git a/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra2.phpt b/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra2.phpt new file mode 100644 index 0000000000000..0e96acfd182d2 --- /dev/null +++ b/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra2.phpt @@ -0,0 +1,17 @@ +--TEST-- +Non rep float string to int conversions should not crash when modified +--FILE-- + +--EXPECT-- +The float 1.0E+42 is not representable as an int, cast occurred diff --git a/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra3.phpt b/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra3.phpt new file mode 100644 index 0000000000000..0bfbeb01a2d00 --- /dev/null +++ b/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra3.phpt @@ -0,0 +1,18 @@ +--TEST-- +Non rep float string to int conversions should not crash when modified +--FILE-- + +--EXPECT-- +The float 1.0E+42 is not representable as an int, cast occurred +bool(false) diff --git a/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra4.phpt b/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra4.phpt new file mode 100644 index 0000000000000..8134ce08d2eed --- /dev/null +++ b/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra4.phpt @@ -0,0 +1,18 @@ +--TEST-- +Non rep float string to int conversions should not crash when modified +--FILE-- + +--EXPECT-- +The float 1.0E+42 is not representable as an int, cast occurred +bool(false) diff --git a/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_arrays.phpt b/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_arrays.phpt index bb27d1bb49ddb..779e103e6f821 100644 --- a/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_arrays.phpt +++ b/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_arrays.phpt @@ -23,12 +23,15 @@ var_dump($array[$string_float]); ?> --EXPECTF-- +Warning: The float 1.0E+121 is not representable as an int, cast occurred in %s on line %d int(0) + +Warning: The float-string "1.0E+121" is not representable as an int, cast occurred in %s on line %d bool(true) -Deprecated: Implicit conversion from float 1.0E+121 to int loses precision in %s on line %d +Warning: The float 1.0E+121 is not representable as an int, cast occurred in %s on line %d -Deprecated: Implicit conversion from float 1.0E+121 to int loses precision in %s on line %d +Warning: The float 1.0E+121 is not representable as an int, cast occurred in %s on line %d array(2) { [0]=> string(11) "Large float" @@ -42,13 +45,13 @@ array(2) { string(18) "String large float" } -Deprecated: Implicit conversion from float 1.0E+121 to int loses precision in %s on line %d +Warning: The float 1.0E+121 is not representable as an int, cast occurred in %s on line %d string(1) "0" Warning: Undefined array key "1.0E+121" in %s on line %d NULL -Deprecated: Implicit conversion from float 1.0E+121 to int loses precision in %s on line %d +Warning: The float 1.0E+121 is not representable as an int, cast occurred in %s on line %d string(1) "0" Warning: Undefined array key "1.0E+121" in %s on line %d diff --git a/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_strings.phpt b/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_strings.phpt index 0c63cba1f5bc0..b4651d28ac4b3 100644 --- a/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_strings.phpt +++ b/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_strings.phpt @@ -75,7 +75,10 @@ var_dump($string); ?> --EXPECTF-- +Warning: The float 1.0E+121 is not representable as an int, cast occurred in %s on line %d int(0) + +Warning: The float-string "1.0E+121" is not representable as an int, cast occurred in %s on line %d int(9223372036854775807) Attempt to read Float diff --git a/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_strings_32bit.phpt b/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_strings_32bit.phpt index cf2e396c311ba..3ec2c62cacdd4 100644 --- a/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_strings_32bit.phpt +++ b/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_strings_32bit.phpt @@ -75,7 +75,10 @@ var_dump($string); ?> --EXPECTF-- +Warning: The float 1.0E+121 is not representable as an int, cast occurred in %s on line %d int(0) + +Warning: The float-string "1.0E+121" is not representable as an int, cast occurred in %s on line %d int(2147483647) Attempt to read Float diff --git a/Zend/tests/type_coercion/int_special_values.phpt b/Zend/tests/type_coercion/int_special_values.phpt index eedb9ab2c02ac..e536ff988e0ae 100644 --- a/Zend/tests/type_coercion/int_special_values.phpt +++ b/Zend/tests/type_coercion/int_special_values.phpt @@ -17,14 +17,18 @@ foreach($values as $value) { echo PHP_EOL; } ?> ---EXPECT-- +--EXPECTF-- float(0) int(0) float(INF) + +Warning: The float INF is not representable as an int, cast occurred in %s on line %d int(0) float(-INF) + +Warning: The float -INF is not representable as an int, cast occurred in %s on line %d int(0) float(0) @@ -34,4 +38,6 @@ float(-0) int(0) float(NAN) + +Warning: The float NAN is not representable as an int, cast occurred in %s on line %d int(0) diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index f43fdd7b31827..b46b5d5bff8d2 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -9939,14 +9939,14 @@ ZEND_API bool zend_is_op_long_compatible(const zval *op) } if (Z_TYPE_P(op) == IS_DOUBLE - && !zend_is_long_compatible(Z_DVAL_P(op), zend_dval_to_lval(Z_DVAL_P(op)))) { + && !zend_is_long_compatible(Z_DVAL_P(op), zend_dval_to_lval_silent(Z_DVAL_P(op)))) { return false; } if (Z_TYPE_P(op) == IS_STRING) { double dval = 0; uint8_t is_num = is_numeric_str_function(Z_STR_P(op), NULL, &dval); - if (is_num == 0 || (is_num == IS_DOUBLE && !zend_is_long_compatible(dval, zend_dval_to_lval(dval)))) { + if (is_num == 0 || (is_num == IS_DOUBLE && !zend_is_long_compatible(dval, zend_dval_to_lval_silent(dval)))) { return false; } } @@ -9995,11 +9995,23 @@ ZEND_API bool zend_binary_op_produces_error(uint32_t opcode, const zval *op1, co return 1; } - if ((opcode == ZEND_MOD && zval_get_long(op2) == 0) - || (opcode == ZEND_DIV && zval_get_double(op2) == 0.0)) { + /* Operation which cast float/float-strings to integers might produce incompatible float to int errors */ + if (opcode == ZEND_SL || opcode == ZEND_SR || opcode == ZEND_BW_OR + || opcode == ZEND_BW_AND || opcode == ZEND_BW_XOR) { + return !zend_is_op_long_compatible(op1) || !zend_is_op_long_compatible(op2); + } + + if (opcode == ZEND_DIV && zval_get_double(op2) == 0.0) { /* Division by zero throws an error. */ return 1; } + + /* Mod is an operation that will cast float/float-strings to integers which might + produce float to int incompatible errors, and also cannot be divided by 0 */ + if (opcode == ZEND_MOD) { + return !zend_is_op_long_compatible(op1) || !zend_is_op_long_compatible(op2) || zval_get_long(op2) == 0; + } + if ((opcode == ZEND_POW) && zval_get_double(op1) == 0 && zval_get_double(op2) < 0) { /* 0 ** (<0) throws a division by zero error. */ return 1; @@ -10009,12 +10021,6 @@ ZEND_API bool zend_binary_op_produces_error(uint32_t opcode, const zval *op1, co return 1; } - /* Operation which cast float/float-strings to integers might produce incompatible float to int errors */ - if (opcode == ZEND_SL || opcode == ZEND_SR || opcode == ZEND_BW_OR - || opcode == ZEND_BW_AND || opcode == ZEND_BW_XOR || opcode == ZEND_MOD) { - return !zend_is_op_long_compatible(op1) || !zend_is_op_long_compatible(op2); - } - return 0; } /* }}} */ @@ -10166,7 +10172,7 @@ static bool zend_try_ct_eval_array(zval *result, zend_ast *ast) /* {{{ */ zend_symtable_update(Z_ARRVAL_P(result), Z_STR_P(key), value); break; case IS_DOUBLE: { - zend_long lval = zend_dval_to_lval(Z_DVAL_P(key)); + zend_long lval = zend_dval_to_lval_silent(Z_DVAL_P(key)); /* Incompatible float will generate an error, leave this to run-time */ if (!zend_is_long_compatible(Z_DVAL_P(key), lval)) { zval_ptr_dtor_nogc(value); @@ -12057,6 +12063,9 @@ bool zend_try_ct_eval_cast(zval *result, uint32_t type, zval *op1) ZVAL_BOOL(result, zval_is_true(op1)); return true; case IS_LONG: + if (Z_TYPE_P(op1) == IS_DOUBLE && !ZEND_DOUBLE_FITS_LONG(Z_DVAL_P((op1)))) { + return false; + } ZVAL_LONG(result, zval_get_long(op1)); return true; case IS_DOUBLE: diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 940c2f98b382f..5665cc0c3f784 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -1732,10 +1732,13 @@ static zend_never_inline zend_long zend_check_string_offset(zval *dim, int type zend_illegal_string_offset(dim, type); return 0; } + case IS_DOUBLE: + /* Suppress potential double warning */ + zend_error(E_WARNING, "String offset cast occurred"); + return zend_dval_to_lval_silent(Z_DVAL_P(dim)); case IS_UNDEF: ZVAL_UNDEFINED_OP2(); ZEND_FALLTHROUGH; - case IS_DOUBLE: case IS_NULL: case IS_FALSE: case IS_TRUE: @@ -2668,21 +2671,18 @@ static zend_never_inline uint8_t slow_index_convert(HashTable *ht, const zval *d value->str = ZSTR_EMPTY_ALLOC(); return IS_STRING; case IS_DOUBLE: - value->lval = zend_dval_to_lval(Z_DVAL_P(dim)); - if (!zend_is_long_compatible(Z_DVAL_P(dim), value->lval)) { - /* The array may be destroyed while throwing the notice. - * Temporarily increase the refcount to detect this situation. */ - if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { - GC_ADDREF(ht); - } - zend_incompatible_double_to_long_error(Z_DVAL_P(dim)); - if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { - zend_array_destroy(ht); - return IS_NULL; - } - if (EG(exception)) { - return IS_NULL; - } + /* The array may be destroyed while throwing the notice. + * Temporarily increase the refcount to detect this situation. */ + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { + GC_ADDREF(ht); + } + value->lval = zend_dval_to_lval_safe(Z_DVAL_P(dim)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { + zend_array_destroy(ht); + return IS_NULL; + } + if (EG(exception)) { + return IS_NULL; } return IS_LONG; case IS_RESOURCE: @@ -2753,23 +2753,20 @@ static zend_never_inline uint8_t slow_index_convert_w(HashTable *ht, const zval value->str = ZSTR_EMPTY_ALLOC(); return IS_STRING; case IS_DOUBLE: - value->lval = zend_dval_to_lval(Z_DVAL_P(dim)); - if (!zend_is_long_compatible(Z_DVAL_P(dim), value->lval)) { - /* The array may be destroyed while throwing the notice. - * Temporarily increase the refcount to detect this situation. */ - if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { - GC_ADDREF(ht); - } - zend_incompatible_double_to_long_error(Z_DVAL_P(dim)); - if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) { - if (!GC_REFCOUNT(ht)) { - zend_array_destroy(ht); - } - return IS_NULL; - } - if (EG(exception)) { - return IS_NULL; + /* The array may be destroyed while throwing the notice. + * Temporarily increase the refcount to detect this situation. */ + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { + GC_ADDREF(ht); + } + value->lval = zend_dval_to_lval_safe(Z_DVAL_P(dim)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) { + if (!GC_REFCOUNT(ht)) { + zend_array_destroy(ht); } + return IS_NULL; + } + if (EG(exception)) { + return IS_NULL; } return IS_LONG; case IS_RESOURCE: @@ -3129,6 +3126,11 @@ static zend_always_inline void zend_fetch_dimension_address_read(zval *result, z return; } } + /* To prevent double warning */ + if (Z_TYPE_P(dim) == IS_DOUBLE) { + offset = zend_dval_to_lval_silent(Z_DVAL_P(dim)); + goto out; + } break; case IS_REFERENCE: dim = Z_REFVAL_P(dim); @@ -3239,7 +3241,17 @@ static zend_never_inline zval* ZEND_FASTCALL zend_find_array_dim_slow(HashTable zend_ulong hval; if (Z_TYPE_P(offset) == IS_DOUBLE) { + /* The array may be destroyed while throwing a warning in case the float is not representable as an int. + * Temporarily increase the refcount to detect this situation. */ + GC_TRY_ADDREF(ht); hval = zend_dval_to_lval_safe(Z_DVAL_P(offset)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { + zend_array_destroy(ht); + return NULL; + } + if (EG(exception)) { + return NULL; + } num_idx: return zend_hash_index_find(ht, hval); } else if (Z_TYPE_P(offset) == IS_NULL) { @@ -3378,7 +3390,17 @@ static zend_never_inline bool ZEND_FASTCALL zend_array_key_exists_fast(HashTable key = Z_REFVAL_P(key); goto try_again; } else if (Z_TYPE_P(key) == IS_DOUBLE) { + /* The array may be destroyed while throwing a warning in case the float is not representable as an int. + * Temporarily increase the refcount to detect this situation. */ + GC_TRY_ADDREF(ht); hval = zend_dval_to_lval_safe(Z_DVAL_P(key)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { + zend_array_destroy(ht); + return false; + } + if (EG(exception)) { + return false; + } goto num_key; } else if (Z_TYPE_P(key) == IS_FALSE) { hval = 0; diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c index e6e0c82c79f20..91421b45fdf31 100644 --- a/Zend/zend_operators.c +++ b/Zend/zend_operators.c @@ -387,12 +387,9 @@ static zend_never_inline zend_long ZEND_FASTCALL zendi_try_get_long(const zval * return 1; case IS_DOUBLE: { double dval = Z_DVAL_P(op); - zend_long lval = zend_dval_to_lval(dval); - if (!zend_is_long_compatible(dval, lval)) { - zend_incompatible_double_to_long_error(dval); - if (UNEXPECTED(EG(exception))) { - *failed = 1; - } + zend_long lval = zend_dval_to_lval_safe(dval); + if (UNEXPECTED(EG(exception))) { + *failed = 1; } return lval; } @@ -418,6 +415,8 @@ static zend_never_inline zend_long ZEND_FASTCALL zendi_try_get_long(const zval * zend_error(E_WARNING, "A non-numeric value encountered"); if (UNEXPECTED(EG(exception))) { *failed = 1; + zend_tmp_string_release(op_str); + return 0; } } if (EXPECTED(type == IS_LONG)) { @@ -428,14 +427,18 @@ static zend_never_inline zend_long ZEND_FASTCALL zendi_try_get_long(const zval * * We use use saturating conversion to emulate strtol()'s * behaviour. */ - lval = zend_dval_to_lval_cap(dval); + if (op_str == NULL) { + /* zend_dval_to_lval_cap() can emit a warning so always do the copy here */ + op_str = zend_string_copy(Z_STR_P(op)); + } + lval = zend_dval_to_lval_cap(dval, op_str); if (!zend_is_long_compatible(dval, lval)) { - zend_incompatible_string_to_long_error(op_str ? op_str : Z_STR_P(op)); + zend_incompatible_string_to_long_error(op_str); if (UNEXPECTED(EG(exception))) { *failed = 1; } } - zend_tmp_string_release(op_str); + zend_string_release(op_str); return lval; } } @@ -911,6 +914,14 @@ ZEND_API void ZEND_COLD zend_incompatible_string_to_long_error(const zend_string { zend_error(E_DEPRECATED, "Implicit conversion from float-string \"%s\" to int loses precision", ZSTR_VAL(s)); } +ZEND_API void ZEND_COLD zend_oob_double_to_long_error(double d) +{ + zend_error_unchecked(E_WARNING, "The float %.*H is not representable as an int, cast occurred", -1, d); +} +ZEND_API void ZEND_COLD zend_oob_string_to_long_error(const zend_string *s) +{ + zend_error_unchecked(E_WARNING, "The float-string \"%s\" is not representable as an int, cast occurred", ZSTR_VAL(s)); +} ZEND_API zend_long ZEND_FASTCALL zval_get_long_func(const zval *op, bool is_strict) /* {{{ */ { @@ -952,7 +963,7 @@ ZEND_API zend_long ZEND_FASTCALL zval_get_long_func(const zval *op, bool is_stri * behaviour. */ /* Most usages are expected to not be (int) casts */ - lval = zend_dval_to_lval_cap(dval); + lval = zend_dval_to_lval_cap(dval, Z_STR_P(op)); if (UNEXPECTED(is_strict)) { if (!zend_is_long_compatible(dval, lval)) { zend_incompatible_string_to_long_error(Z_STR_P(op)); @@ -1613,15 +1624,12 @@ ZEND_API zend_result ZEND_FASTCALL bitwise_not_function(zval *result, zval *op1) ZVAL_LONG(result, ~Z_LVAL_P(op1)); return SUCCESS; case IS_DOUBLE: { - zend_long lval = zend_dval_to_lval(Z_DVAL_P(op1)); - if (!zend_is_long_compatible(Z_DVAL_P(op1), lval)) { - zend_incompatible_double_to_long_error(Z_DVAL_P(op1)); - if (EG(exception)) { - if (result != op1) { - ZVAL_UNDEF(result); - } - return FAILURE; + zend_long lval = zend_dval_to_lval_safe(Z_DVAL_P(op1)); + if (EG(exception)) { + if (result != op1) { + ZVAL_UNDEF(result); } + return FAILURE; } ZVAL_LONG(result, ~lval); return SUCCESS; diff --git a/Zend/zend_operators.h b/Zend/zend_operators.h index 63b0fb62e49f2..e821827f57f58 100644 --- a/Zend/zend_operators.h +++ b/Zend/zend_operators.h @@ -115,11 +115,28 @@ ZEND_API const char* ZEND_FASTCALL zend_memnrstr_ex(const char *haystack, const # define ZEND_DOUBLE_FITS_LONG(d) (!((d) >= (double)ZEND_LONG_MAX || (d) < (double)ZEND_LONG_MIN)) #endif +ZEND_API void zend_incompatible_double_to_long_error(double d); +ZEND_API void zend_incompatible_string_to_long_error(const zend_string *s); +ZEND_API void ZEND_COLD zend_oob_double_to_long_error(double d); +ZEND_API void ZEND_COLD zend_oob_string_to_long_error(const zend_string *s); + ZEND_API zend_long ZEND_FASTCALL zend_dval_to_lval_slow(double d); static zend_always_inline zend_long zend_dval_to_lval(double d) { - if (UNEXPECTED(!zend_finite(d)) || UNEXPECTED(zend_isnan(d))) { + if (UNEXPECTED(!zend_finite(d))) { + zend_oob_double_to_long_error(d); + return 0; + } else if (!ZEND_DOUBLE_FITS_LONG(d)) { + zend_oob_double_to_long_error(d); + return zend_dval_to_lval_slow(d); + } + return (zend_long)d; +} + +static zend_always_inline zend_long zend_dval_to_lval_silent(double d) +{ + if (UNEXPECTED(!zend_finite(d))) { return 0; } else if (!ZEND_DOUBLE_FITS_LONG(d)) { return zend_dval_to_lval_slow(d); @@ -128,11 +145,13 @@ static zend_always_inline zend_long zend_dval_to_lval(double d) } /* Used to convert a string float to integer during an (int) cast */ -static zend_always_inline zend_long zend_dval_to_lval_cap(double d) +static zend_always_inline zend_long zend_dval_to_lval_cap(double d, const zend_string *s) { - if (UNEXPECTED(!zend_finite(d)) || UNEXPECTED(zend_isnan(d))) { + if (UNEXPECTED(!zend_finite(d))) { + zend_oob_string_to_long_error(s); return 0; } else if (!ZEND_DOUBLE_FITS_LONG(d)) { + zend_oob_string_to_long_error(s); return (d > 0 ? ZEND_LONG_MAX : ZEND_LONG_MIN); } return (zend_long)d; @@ -143,13 +162,10 @@ static zend_always_inline bool zend_is_long_compatible(double d, zend_long l) { return (double)l == d; } -ZEND_API void zend_incompatible_double_to_long_error(double d); -ZEND_API void zend_incompatible_string_to_long_error(const zend_string *s); - static zend_always_inline zend_long zend_dval_to_lval_safe(double d) { zend_long l = zend_dval_to_lval(d); - if (!zend_is_long_compatible(d, l)) { + if (!zend_is_long_compatible(d, l) && ZEND_DOUBLE_FITS_LONG(d)) { zend_incompatible_double_to_long_error(d); } return l; diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index 3d6463d064873..3ebf816cf3817 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -6751,7 +6751,17 @@ ZEND_VM_C_LABEL(num_index_dim): offset = Z_REFVAL_P(offset); ZEND_VM_C_GOTO(offset_again); } else if (Z_TYPE_P(offset) == IS_DOUBLE) { + /* The array may be destroyed while throwing a warning in case the float is not representable as an int. + * Temporarily increase the refcount to detect this situation. */ + GC_TRY_ADDREF(ht); hval = zend_dval_to_lval_safe(Z_DVAL_P(offset)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { + zend_array_destroy(ht); + break; + } + if (EG(exception)) { + break; + } ZEND_VM_C_GOTO(num_index_dim); } else if (Z_TYPE_P(offset) == IS_NULL) { key = ZSTR_EMPTY_ALLOC(); diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 33c8e9c223173..b0d6f2bc33d96 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -26627,7 +26627,17 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_FUNC_CCONV ZEND_UNSET_DIM_SPE offset = Z_REFVAL_P(offset); goto offset_again; } else if (Z_TYPE_P(offset) == IS_DOUBLE) { + /* The array may be destroyed while throwing a warning in case the float is not representable as an int. + * Temporarily increase the refcount to detect this situation. */ + GC_TRY_ADDREF(ht); hval = zend_dval_to_lval_safe(Z_DVAL_P(offset)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { + zend_array_destroy(ht); + break; + } + if (EG(exception)) { + break; + } goto num_index_dim; } else if (Z_TYPE_P(offset) == IS_NULL) { key = ZSTR_EMPTY_ALLOC(); @@ -29168,7 +29178,17 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_FUNC_CCONV ZEND_UNSET_DIM_SPE offset = Z_REFVAL_P(offset); goto offset_again; } else if (Z_TYPE_P(offset) == IS_DOUBLE) { + /* The array may be destroyed while throwing a warning in case the float is not representable as an int. + * Temporarily increase the refcount to detect this situation. */ + GC_TRY_ADDREF(ht); hval = zend_dval_to_lval_safe(Z_DVAL_P(offset)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { + zend_array_destroy(ht); + break; + } + if (EG(exception)) { + break; + } goto num_index_dim; } else if (Z_TYPE_P(offset) == IS_NULL) { key = ZSTR_EMPTY_ALLOC(); @@ -33687,7 +33707,17 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_FUNC_CCONV ZEND_UNSET_DIM_SPE offset = Z_REFVAL_P(offset); goto offset_again; } else if (Z_TYPE_P(offset) == IS_DOUBLE) { + /* The array may be destroyed while throwing a warning in case the float is not representable as an int. + * Temporarily increase the refcount to detect this situation. */ + GC_TRY_ADDREF(ht); hval = zend_dval_to_lval_safe(Z_DVAL_P(offset)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { + zend_array_destroy(ht); + break; + } + if (EG(exception)) { + break; + } goto num_index_dim; } else if (Z_TYPE_P(offset) == IS_NULL) { key = ZSTR_EMPTY_ALLOC(); @@ -46191,7 +46221,17 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_FUNC_CCONV ZEND_UNSET_DIM_SPE offset = Z_REFVAL_P(offset); goto offset_again; } else if (Z_TYPE_P(offset) == IS_DOUBLE) { + /* The array may be destroyed while throwing a warning in case the float is not representable as an int. + * Temporarily increase the refcount to detect this situation. */ + GC_TRY_ADDREF(ht); hval = zend_dval_to_lval_safe(Z_DVAL_P(offset)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { + zend_array_destroy(ht); + break; + } + if (EG(exception)) { + break; + } goto num_index_dim; } else if (Z_TYPE_P(offset) == IS_NULL) { key = ZSTR_EMPTY_ALLOC(); @@ -50020,7 +50060,17 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_FUNC_CCONV ZEND_UNSET_DIM_SPE offset = Z_REFVAL_P(offset); goto offset_again; } else if (Z_TYPE_P(offset) == IS_DOUBLE) { + /* The array may be destroyed while throwing a warning in case the float is not representable as an int. + * Temporarily increase the refcount to detect this situation. */ + GC_TRY_ADDREF(ht); hval = zend_dval_to_lval_safe(Z_DVAL_P(offset)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { + zend_array_destroy(ht); + break; + } + if (EG(exception)) { + break; + } goto num_index_dim; } else if (Z_TYPE_P(offset) == IS_NULL) { key = ZSTR_EMPTY_ALLOC(); @@ -55769,7 +55819,17 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_FUNC_CCONV ZEND_UNSET_DIM_SPE offset = Z_REFVAL_P(offset); goto offset_again; } else if (Z_TYPE_P(offset) == IS_DOUBLE) { + /* The array may be destroyed while throwing a warning in case the float is not representable as an int. + * Temporarily increase the refcount to detect this situation. */ + GC_TRY_ADDREF(ht); hval = zend_dval_to_lval_safe(Z_DVAL_P(offset)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { + zend_array_destroy(ht); + break; + } + if (EG(exception)) { + break; + } goto num_index_dim; } else if (Z_TYPE_P(offset) == IS_NULL) { key = ZSTR_EMPTY_ALLOC(); @@ -81788,7 +81848,17 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_CCONV ZEND_UNSET_DIM_SPEC_VAR offset = Z_REFVAL_P(offset); goto offset_again; } else if (Z_TYPE_P(offset) == IS_DOUBLE) { + /* The array may be destroyed while throwing a warning in case the float is not representable as an int. + * Temporarily increase the refcount to detect this situation. */ + GC_TRY_ADDREF(ht); hval = zend_dval_to_lval_safe(Z_DVAL_P(offset)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { + zend_array_destroy(ht); + break; + } + if (EG(exception)) { + break; + } goto num_index_dim; } else if (Z_TYPE_P(offset) == IS_NULL) { key = ZSTR_EMPTY_ALLOC(); @@ -84329,7 +84399,17 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_CCONV ZEND_UNSET_DIM_SPEC_VAR offset = Z_REFVAL_P(offset); goto offset_again; } else if (Z_TYPE_P(offset) == IS_DOUBLE) { + /* The array may be destroyed while throwing a warning in case the float is not representable as an int. + * Temporarily increase the refcount to detect this situation. */ + GC_TRY_ADDREF(ht); hval = zend_dval_to_lval_safe(Z_DVAL_P(offset)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { + zend_array_destroy(ht); + break; + } + if (EG(exception)) { + break; + } goto num_index_dim; } else if (Z_TYPE_P(offset) == IS_NULL) { key = ZSTR_EMPTY_ALLOC(); @@ -88848,7 +88928,17 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_CCONV ZEND_UNSET_DIM_SPEC_VAR offset = Z_REFVAL_P(offset); goto offset_again; } else if (Z_TYPE_P(offset) == IS_DOUBLE) { + /* The array may be destroyed while throwing a warning in case the float is not representable as an int. + * Temporarily increase the refcount to detect this situation. */ + GC_TRY_ADDREF(ht); hval = zend_dval_to_lval_safe(Z_DVAL_P(offset)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { + zend_array_destroy(ht); + break; + } + if (EG(exception)) { + break; + } goto num_index_dim; } else if (Z_TYPE_P(offset) == IS_NULL) { key = ZSTR_EMPTY_ALLOC(); @@ -101352,7 +101442,17 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_CCONV ZEND_UNSET_DIM_SPEC_CV_ offset = Z_REFVAL_P(offset); goto offset_again; } else if (Z_TYPE_P(offset) == IS_DOUBLE) { + /* The array may be destroyed while throwing a warning in case the float is not representable as an int. + * Temporarily increase the refcount to detect this situation. */ + GC_TRY_ADDREF(ht); hval = zend_dval_to_lval_safe(Z_DVAL_P(offset)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { + zend_array_destroy(ht); + break; + } + if (EG(exception)) { + break; + } goto num_index_dim; } else if (Z_TYPE_P(offset) == IS_NULL) { key = ZSTR_EMPTY_ALLOC(); @@ -105181,7 +105281,17 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_CCONV ZEND_UNSET_DIM_SPEC_CV_ offset = Z_REFVAL_P(offset); goto offset_again; } else if (Z_TYPE_P(offset) == IS_DOUBLE) { + /* The array may be destroyed while throwing a warning in case the float is not representable as an int. + * Temporarily increase the refcount to detect this situation. */ + GC_TRY_ADDREF(ht); hval = zend_dval_to_lval_safe(Z_DVAL_P(offset)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { + zend_array_destroy(ht); + break; + } + if (EG(exception)) { + break; + } goto num_index_dim; } else if (Z_TYPE_P(offset) == IS_NULL) { key = ZSTR_EMPTY_ALLOC(); @@ -110828,7 +110938,17 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_CCONV ZEND_UNSET_DIM_SPEC_CV_ offset = Z_REFVAL_P(offset); goto offset_again; } else if (Z_TYPE_P(offset) == IS_DOUBLE) { + /* The array may be destroyed while throwing a warning in case the float is not representable as an int. + * Temporarily increase the refcount to detect this situation. */ + GC_TRY_ADDREF(ht); hval = zend_dval_to_lval_safe(Z_DVAL_P(offset)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { + zend_array_destroy(ht); + break; + } + if (EG(exception)) { + break; + } goto num_index_dim; } else if (Z_TYPE_P(offset) == IS_NULL) { key = ZSTR_EMPTY_ALLOC(); diff --git a/ext/date/tests/bug79015.phpt b/ext/date/tests/bug79015.phpt index 99cb03f75d5cb..b2f1a63fa4c21 100644 --- a/ext/date/tests/bug79015.phpt +++ b/ext/date/tests/bug79015.phpt @@ -6,6 +6,7 @@ $payload = 'O:12:"DateInterval":9:{s:1:"y";i:1;s:1:"m";i:0;s:1:"d";i:4;s:1:"h";i var_dump(unserialize($payload)); ?> --EXPECTF-- +Warning: The float 9.99999999999E+18 is not representable as an int, cast occurred in %s on line %d object(DateInterval)#%d (%d) { ["y"]=> int(1) diff --git a/ext/dom/php_dom.c b/ext/dom/php_dom.c index ee99f97f35455..095d07e875ea9 100644 --- a/ext/dom/php_dom.c +++ b/ext/dom/php_dom.c @@ -2261,7 +2261,7 @@ static bool dom_nodemap_or_nodelist_process_offset_as_named(zval *offset, zend_l if (0 == (is_numeric_string_type = is_numeric_string(Z_STRVAL_P(offset), Z_STRLEN_P(offset), lval, &dval, true))) { return true; } else if (is_numeric_string_type == IS_DOUBLE) { - *lval = zend_dval_to_lval_cap(dval); + *lval = zend_dval_to_lval_cap(dval, Z_STR_P(offset)); } } else { *lval = zval_get_long(offset); diff --git a/ext/intl/tests/gh13766.phpt b/ext/intl/tests/gh13766.phpt index 70567fa860537..9ed8d985de470 100644 --- a/ext/intl/tests/gh13766.phpt +++ b/ext/intl/tests/gh13766.phpt @@ -32,4 +32,4 @@ int(%d) string(19) "America/Los_Angeles" IntlDateFormatter::parseToCalendar(): Argument #2 ($offset) must be of type int, string given -Deprecated: Implicit conversion from float %r(1\.4757395258967641E\+20|34359738352)%r to int loses precision in %s on line %d +Warning: The float %r(1\.4757395258967641E\+20|34359738352)%r is not representable as an int, cast occurred in %s on line %d diff --git a/ext/opcache/jit/zend_jit_helpers.c b/ext/opcache/jit/zend_jit_helpers.c index ce48d10223412..d49d5ee3007e4 100644 --- a/ext/opcache/jit/zend_jit_helpers.c +++ b/ext/opcache/jit/zend_jit_helpers.c @@ -513,33 +513,30 @@ static void ZEND_FASTCALL zend_jit_fetch_dim_r_helper(zend_array *ht, zval *dim, } return; case IS_DOUBLE: - hval = zend_dval_to_lval(Z_DVAL_P(dim)); - if (!zend_is_long_compatible(Z_DVAL_P(dim), hval)) { - /* The array may be destroyed while throwing the notice. - * Temporarily increase the refcount to detect this situation. */ - if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { - GC_ADDREF(ht); - } - execute_data = EG(current_execute_data); - opline = EX(opline); - zend_incompatible_double_to_long_error(Z_DVAL_P(dim)); - if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { - zend_array_destroy(ht); - if (opline->result_type & (IS_VAR | IS_TMP_VAR)) { - if (EG(exception)) { - ZVAL_UNDEF(EX_VAR(opline->result.var)); - } else { - ZVAL_NULL(EX_VAR(opline->result.var)); - } - } - return; - } - if (EG(exception)) { - if (opline->result_type & (IS_VAR | IS_TMP_VAR)) { + /* The array may be destroyed while throwing the notice. + * Temporarily increase the refcount to detect this situation. */ + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { + GC_ADDREF(ht); + } + execute_data = EG(current_execute_data); + opline = EX(opline); + hval = zend_dval_to_lval_safe(Z_DVAL_P(dim)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { + zend_array_destroy(ht); + if (opline->result_type & (IS_VAR | IS_TMP_VAR)) { + if (EG(exception)) { ZVAL_UNDEF(EX_VAR(opline->result.var)); + } else { + ZVAL_NULL(EX_VAR(opline->result.var)); } - return; } + return; + } + if (EG(exception)) { + if (opline->result_type & (IS_VAR | IS_TMP_VAR)) { + ZVAL_UNDEF(EX_VAR(opline->result.var)); + } + return; } goto num_index; case IS_RESOURCE: @@ -663,33 +660,30 @@ static void ZEND_FASTCALL zend_jit_fetch_dim_is_helper(zend_array *ht, zval *dim return; case IS_DOUBLE: - hval = zend_dval_to_lval(Z_DVAL_P(dim)); - if (!zend_is_long_compatible(Z_DVAL_P(dim), hval)) { - /* The array may be destroyed while throwing the notice. - * Temporarily increase the refcount to detect this situation. */ - if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { - GC_ADDREF(ht); - } - execute_data = EG(current_execute_data); - opline = EX(opline); - zend_incompatible_double_to_long_error(Z_DVAL_P(dim)); - if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { - zend_array_destroy(ht); - if (opline->result_type & (IS_VAR | IS_TMP_VAR)) { - if (EG(exception)) { - ZVAL_UNDEF(EX_VAR(opline->result.var)); - } else { - ZVAL_NULL(EX_VAR(opline->result.var)); - } - } - return; - } - if (EG(exception)) { - if (opline->result_type & (IS_VAR | IS_TMP_VAR)) { + /* The array may be destroyed while throwing the notice. + * Temporarily increase the refcount to detect this situation. */ + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { + GC_ADDREF(ht); + } + execute_data = EG(current_execute_data); + opline = EX(opline); + hval = zend_dval_to_lval_safe(Z_DVAL_P(dim)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { + zend_array_destroy(ht); + if (opline->result_type & (IS_VAR | IS_TMP_VAR)) { + if (EG(exception)) { ZVAL_UNDEF(EX_VAR(opline->result.var)); + } else { + ZVAL_NULL(EX_VAR(opline->result.var)); } - return; } + return; + } + if (EG(exception)) { + if (opline->result_type & (IS_VAR | IS_TMP_VAR)) { + ZVAL_UNDEF(EX_VAR(opline->result.var)); + } + return; } goto num_index; case IS_RESOURCE: @@ -799,21 +793,18 @@ static int ZEND_FASTCALL zend_jit_fetch_dim_isset_helper(zend_array *ht, zval *d return result; } case IS_DOUBLE: - hval = zend_dval_to_lval(Z_DVAL_P(dim)); - if (!zend_is_long_compatible(Z_DVAL_P(dim), hval)) { - /* The array may be destroyed while throwing the notice. - * Temporarily increase the refcount to detect this situation. */ - if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { - GC_ADDREF(ht); - } - zend_incompatible_double_to_long_error(Z_DVAL_P(dim)); - if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { - zend_array_destroy(ht); - return 0; - } - if (EG(exception)) { - return 0; - } + /* The array may be destroyed while throwing the notice. + * Temporarily increase the refcount to detect this situation. */ + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { + GC_ADDREF(ht); + } + hval = zend_dval_to_lval_safe(Z_DVAL_P(dim)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { + zend_array_destroy(ht); + return 0; + } + if (EG(exception)) { + return 0; } goto num_index; case IS_RESOURCE: @@ -933,35 +924,32 @@ static zval* ZEND_FASTCALL zend_jit_fetch_dim_rw_helper(zend_array *ht, zval *di offset_key = ZSTR_EMPTY_ALLOC(); goto str_index; case IS_DOUBLE: - hval = zend_dval_to_lval(Z_DVAL_P(dim)); - if (!zend_is_long_compatible(Z_DVAL_P(dim), hval)) { - /* The array may be destroyed while throwing the notice. - * Temporarily increase the refcount to detect this situation. */ - if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { - GC_ADDREF(ht); - } - execute_data = EG(current_execute_data); - opline = EX(opline); - zend_incompatible_double_to_long_error(Z_DVAL_P(dim)); - if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) { - if (!GC_REFCOUNT(ht)) { - zend_array_destroy(ht); - } - if (opline->result_type & (IS_VAR | IS_TMP_VAR)) { - if (EG(exception)) { - ZVAL_UNDEF(EX_VAR(opline->result.var)); - } else { - ZVAL_NULL(EX_VAR(opline->result.var)); - } - } - return NULL; + /* The array may be destroyed while throwing the notice. + * Temporarily increase the refcount to detect this situation. */ + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { + GC_ADDREF(ht); + } + execute_data = EG(current_execute_data); + opline = EX(opline); + hval = zend_dval_to_lval_safe(Z_DVAL_P(dim)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) { + if (!GC_REFCOUNT(ht)) { + zend_array_destroy(ht); } - if (EG(exception)) { - if (opline->result_type & (IS_VAR | IS_TMP_VAR)) { + if (opline->result_type & (IS_VAR | IS_TMP_VAR)) { + if (EG(exception)) { ZVAL_UNDEF(EX_VAR(opline->result.var)); + } else { + ZVAL_NULL(EX_VAR(opline->result.var)); } - return NULL; } + return NULL; + } + if (EG(exception)) { + if (opline->result_type & (IS_VAR | IS_TMP_VAR)) { + ZVAL_UNDEF(EX_VAR(opline->result.var)); + } + return NULL; } goto num_index; case IS_RESOURCE: @@ -1096,35 +1084,32 @@ static zval* ZEND_FASTCALL zend_jit_fetch_dim_w_helper(zend_array *ht, zval *dim offset_key = ZSTR_EMPTY_ALLOC(); goto str_index; case IS_DOUBLE: - hval = zend_dval_to_lval(Z_DVAL_P(dim)); - if (!zend_is_long_compatible(Z_DVAL_P(dim), hval)) { - /* The array may be destroyed while throwing the notice. - * Temporarily increase the refcount to detect this situation. */ - if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { - GC_ADDREF(ht); - } - execute_data = EG(current_execute_data); - opline = EX(opline); - zend_incompatible_double_to_long_error(Z_DVAL_P(dim)); - if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) { - if (!GC_REFCOUNT(ht)) { - zend_array_destroy(ht); - } - if (opline->result_type & (IS_VAR | IS_TMP_VAR)) { - if (EG(exception)) { - ZVAL_UNDEF(EX_VAR(opline->result.var)); - } else { - ZVAL_NULL(EX_VAR(opline->result.var)); - } - } - return NULL; + /* The array may be destroyed while throwing the notice. + * Temporarily increase the refcount to detect this situation. */ + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { + GC_ADDREF(ht); + } + execute_data = EG(current_execute_data); + opline = EX(opline); + hval = zend_dval_to_lval_safe(Z_DVAL_P(dim)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) { + if (!GC_REFCOUNT(ht)) { + zend_array_destroy(ht); } - if (EG(exception)) { - if (opline->result_type & (IS_VAR | IS_TMP_VAR)) { + if (opline->result_type & (IS_VAR | IS_TMP_VAR)) { + if (EG(exception)) { ZVAL_UNDEF(EX_VAR(opline->result.var)); + } else { + ZVAL_NULL(EX_VAR(opline->result.var)); } - return NULL; } + return NULL; + } + if (EG(exception)) { + if (opline->result_type & (IS_VAR | IS_TMP_VAR)) { + ZVAL_UNDEF(EX_VAR(opline->result.var)); + } + return NULL; } goto num_index; case IS_RESOURCE: @@ -1211,10 +1196,13 @@ static zend_never_inline zend_long zend_check_string_offset(zval *dim, int type) zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_STRING), dim, BP_VAR_R); return 0; } + case IS_DOUBLE: + /* Suppress potential double warning */ + zend_error(E_WARNING, "String offset cast occurred"); + return zend_dval_to_lval_silent(Z_DVAL_P(dim)); case IS_UNDEF: zend_jit_undefined_op_helper(EG(current_execute_data)->opline->op2.var); ZEND_FALLTHROUGH; - case IS_DOUBLE: case IS_NULL: case IS_FALSE: case IS_TRUE: @@ -1286,14 +1274,17 @@ static void ZEND_FASTCALL zend_jit_fetch_dim_str_is_helper(zend_string *str, zva switch (Z_TYPE_P(dim)) { /* case IS_LONG: */ case IS_STRING: - if (IS_LONG == is_numeric_string(Z_STRVAL_P(dim), Z_STRLEN_P(dim), NULL, NULL, false)) { - break; + if (IS_LONG == is_numeric_string(Z_STRVAL_P(dim), Z_STRLEN_P(dim), &offset, NULL, false)) { + goto out; } ZVAL_NULL(result); return; + case IS_DOUBLE: + offset = zend_dval_to_lval_silent(Z_DVAL_P(dim)); + goto out; case IS_UNDEF: zend_jit_undefined_op_helper(EG(current_execute_data)->opline->op2.var); - case IS_DOUBLE: + ZEND_FALLTHROUGH; case IS_NULL: case IS_FALSE: case IS_TRUE: @@ -1314,6 +1305,7 @@ static void ZEND_FASTCALL zend_jit_fetch_dim_str_is_helper(zend_string *str, zva offset = Z_LVAL_P(dim); } +out: if ((zend_ulong)offset >= (zend_ulong)ZSTR_LEN(str)) { if (offset < 0) { /* Handle negative offset */ diff --git a/ext/opcache/tests/jit/add_011.phpt b/ext/opcache/tests/jit/add_011.phpt index 28c598c5540a0..17bd7be99d157 100644 --- a/ext/opcache/tests/jit/add_011.phpt +++ b/ext/opcache/tests/jit/add_011.phpt @@ -195,5 +195,6 @@ int(-9223371969208523780) Warning: Undefined variable $u in %sadd_011.php on line 5 -Deprecated: Implicit conversion from float %f to int loses precision in %sadd_011.php on line 5 -int(66572500992) \ No newline at end of file +Warning: The float %f is not representable as an int, cast occurred in %sadd_011.php on line 5 +int(66572500992) + diff --git a/ext/opcache/tests/jit/array_elem_002.phpt b/ext/opcache/tests/jit/array_elem_002.phpt index 250f54349051b..01de92acfccf8 100644 --- a/ext/opcache/tests/jit/array_elem_002.phpt +++ b/ext/opcache/tests/jit/array_elem_002.phpt @@ -11,7 +11,7 @@ $string_float= PHP_INT_MAX; $a = [$float => 'a', $string_float => 'b', 'c', 'd']; ?> --EXPECTF-- -Deprecated: Implicit conversion from float 1.0E+38 to int loses precision in %sarray_elem_002.php on line 4 +Warning: The float 1.0E+38 is not representable as an int, cast occurred in %sarray_elem_002.php on line 4 Fatal error: Uncaught Error: Cannot add element to the array as the next element is already occupied in %sarray_elem_002.php:4 Stack trace: diff --git a/ext/opcache/tests/jit/gh19669-001.phpt b/ext/opcache/tests/jit/gh19669-001.phpt index 7d63643bb0157..e8c54c542c83c 100644 --- a/ext/opcache/tests/jit/gh19669-001.phpt +++ b/ext/opcache/tests/jit/gh19669-001.phpt @@ -20,5 +20,6 @@ function test() { } var_dump(test()); ?> ---EXPECT-- +--EXPECTF-- +Warning: The float -1.8446744073709552E+19 is not representable as an int, cast occurred in %s on line %d int(-3) diff --git a/ext/opcache/tests/jit/gh19669-002.phpt b/ext/opcache/tests/jit/gh19669-002.phpt index 373356bcd0612..3a1aa0aa958c9 100644 --- a/ext/opcache/tests/jit/gh19669-002.phpt +++ b/ext/opcache/tests/jit/gh19669-002.phpt @@ -20,5 +20,6 @@ function test() { } var_dump(test()); ?> ---EXPECT-- +--EXPECTF-- +Warning: The float -1.8446744073709552E+19 is not representable as an int, cast occurred in %s on line %d int(-10) diff --git a/ext/opcache/tests/jit/reg_alloc_003_32bits.phpt b/ext/opcache/tests/jit/reg_alloc_003_32bits.phpt index 9b373c6230852..ecef070c3f2f5 100644 --- a/ext/opcache/tests/jit/reg_alloc_003_32bits.phpt +++ b/ext/opcache/tests/jit/reg_alloc_003_32bits.phpt @@ -23,5 +23,5 @@ function test($char_code) { echo test(65), "\n"; ?> --EXPECTF-- -Deprecated: Implicit conversion from float 4294967168 to int loses precision in %s on line %d +Warning: The float 4294967168 is not representable as an int, cast occurred in %s on line %d correct diff --git a/ext/openssl/tests/openssl_decrypt_basic.phpt b/ext/openssl/tests/openssl_decrypt_basic.phpt index 6cb2297a979b1..0f674dbc1e348 100644 --- a/ext/openssl/tests/openssl_decrypt_basic.phpt +++ b/ext/openssl/tests/openssl_decrypt_basic.phpt @@ -10,8 +10,7 @@ $password = "openssl"; $ivlen = openssl_cipher_iv_length($method); $iv = ''; -srand(time() + ((int)(microtime(true) * 1000000) % 1000000)); -while(strlen($iv) < $ivlen) $iv .= chr(rand(0,255)); +while(strlen($iv) < $ivlen) $iv .= random_bytes(1); $encrypted = openssl_encrypt($data, $method, $password, 0, $iv); $output = openssl_decrypt($encrypted, $method, $password, 0, $iv); diff --git a/ext/standard/array.c b/ext/standard/array.c index 96795e623cb9e..be9702c5ef650 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -1219,7 +1219,7 @@ PHP_FUNCTION(min) min_lval = Z_LVAL(args[i]); min = &args[i]; } - } else if (Z_TYPE(args[i]) == IS_DOUBLE && (zend_dval_to_lval((double) min_lval) == min_lval)) { + } else if (Z_TYPE(args[i]) == IS_DOUBLE && (zend_dval_to_lval_silent((double) min_lval) == min_lval)) { /* if min_lval can be exactly represented as a double, go to double dedicated code */ min_dval = (double) min_lval; goto double_compare; @@ -1239,7 +1239,7 @@ PHP_FUNCTION(min) min_dval = Z_DVAL(args[i]); min = &args[i]; } - } else if (Z_TYPE(args[i]) == IS_LONG && (zend_dval_to_lval((double) Z_LVAL(args[i])) == Z_LVAL(args[i]))) { + } else if (Z_TYPE(args[i]) == IS_LONG && (zend_dval_to_lval_silent((double) Z_LVAL(args[i])) == Z_LVAL(args[i]))) { /* if the value can be exactly represented as a double, use double dedicated code otherwise generic */ if (min_dval > (double)Z_LVAL(args[i])) { min_dval = (double)Z_LVAL(args[i]); @@ -1277,7 +1277,7 @@ ZEND_FRAMELESS_FUNCTION(min, 2) if (EXPECTED(Z_TYPE_P(rhs) == IS_LONG)) { RETURN_COPY_VALUE(lhs_lval < Z_LVAL_P(rhs) ? lhs : rhs); - } else if (Z_TYPE_P(rhs) == IS_DOUBLE && (zend_dval_to_lval((double) lhs_lval) == lhs_lval)) { + } else if (Z_TYPE_P(rhs) == IS_DOUBLE && (zend_dval_to_lval_silent((double) lhs_lval) == lhs_lval)) { /* if lhs_lval can be exactly represented as a double, go to double dedicated code */ lhs_dval = (double) lhs_lval; goto double_compare; @@ -1290,7 +1290,7 @@ ZEND_FRAMELESS_FUNCTION(min, 2) if (EXPECTED(Z_TYPE_P(rhs) == IS_DOUBLE)) { double_compare: RETURN_COPY_VALUE(lhs_dval < Z_DVAL_P(rhs) ? lhs : rhs); - } else if (Z_TYPE_P(rhs) == IS_LONG && (zend_dval_to_lval((double) Z_LVAL_P(rhs)) == Z_LVAL_P(rhs))) { + } else if (Z_TYPE_P(rhs) == IS_LONG && (zend_dval_to_lval_silent((double) Z_LVAL_P(rhs)) == Z_LVAL_P(rhs))) { /* if the value can be exactly represented as a double, use double dedicated code otherwise generic */ RETURN_COPY_VALUE(lhs_dval < (double)Z_LVAL_P(rhs) ? lhs : rhs); } else { @@ -1347,7 +1347,7 @@ PHP_FUNCTION(max) max_lval = Z_LVAL(args[i]); max = &args[i]; } - } else if (Z_TYPE(args[i]) == IS_DOUBLE && (zend_dval_to_lval((double) max_lval) == max_lval)) { + } else if (Z_TYPE(args[i]) == IS_DOUBLE && (zend_dval_to_lval_silent((double) max_lval) == max_lval)) { /* if max_lval can be exactly represented as a double, go to double dedicated code */ max_dval = (double) max_lval; goto double_compare; @@ -1367,7 +1367,7 @@ PHP_FUNCTION(max) max_dval = Z_DVAL(args[i]); max = &args[i]; } - } else if (Z_TYPE(args[i]) == IS_LONG && (zend_dval_to_lval((double) Z_LVAL(args[i])) == Z_LVAL(args[i]))) { + } else if (Z_TYPE(args[i]) == IS_LONG && (zend_dval_to_lval_silent((double) Z_LVAL(args[i])) == Z_LVAL(args[i]))) { /* if the value can be exactly represented as a double, use double dedicated code otherwise generic */ if (max_dval < (double)Z_LVAL(args[i])) { max_dval = (double)Z_LVAL(args[i]); @@ -1405,7 +1405,7 @@ ZEND_FRAMELESS_FUNCTION(max, 2) if (EXPECTED(Z_TYPE_P(rhs) == IS_LONG)) { RETURN_COPY_VALUE(lhs_lval >= Z_LVAL_P(rhs) ? lhs : rhs); - } else if (Z_TYPE_P(rhs) == IS_DOUBLE && (zend_dval_to_lval((double) lhs_lval) == lhs_lval)) { + } else if (Z_TYPE_P(rhs) == IS_DOUBLE && (zend_dval_to_lval_silent((double) lhs_lval) == lhs_lval)) { /* if lhs_lval can be exactly represented as a double, go to double dedicated code */ lhs_dval = (double) lhs_lval; goto double_compare; @@ -1418,7 +1418,7 @@ ZEND_FRAMELESS_FUNCTION(max, 2) if (EXPECTED(Z_TYPE_P(rhs) == IS_DOUBLE)) { double_compare: RETURN_COPY_VALUE(lhs_dval >= Z_DVAL_P(rhs) ? lhs : rhs); - } else if (Z_TYPE_P(rhs) == IS_LONG && (zend_dval_to_lval((double) Z_LVAL_P(rhs)) == Z_LVAL_P(rhs))) { + } else if (Z_TYPE_P(rhs) == IS_LONG && (zend_dval_to_lval_silent((double) Z_LVAL_P(rhs)) == Z_LVAL_P(rhs))) { /* if the value can be exactly represented as a double, use double dedicated code otherwise generic */ RETURN_COPY_VALUE(lhs_dval >= (double)Z_LVAL_P(rhs) ? lhs : rhs); } else { @@ -2980,7 +2980,7 @@ PHP_FUNCTION(range) is_step_negative = true; step_double *= -1; } - step = zend_dval_to_lval(step_double); + step = zend_dval_to_lval_silent(step_double); if (!zend_is_long_compatible(step_double, step)) { is_step_double = true; } diff --git a/ext/standard/tests/general_functions/gettype_settype_variation2.phpt b/ext/standard/tests/general_functions/gettype_settype_variation2.phpt index 12f001e924e46..5f35d713d512f 100644 --- a/ext/standard/tests/general_functions/gettype_settype_variation2.phpt +++ b/ext/standard/tests/general_functions/gettype_settype_variation2.phpt @@ -274,6 +274,7 @@ int(1) string(7) "integer" -- Iteration 20 -- string(6) "string" +2: The float-string "2974394749328742328432" is not representable as an int, cast occurred bool(true) int(2147483647) string(7) "integer" @@ -304,6 +305,7 @@ int(1) string(7) "integer" -- Iteration 26 -- string(6) "string" +2: The float-string "2974394749328742328432" is not representable as an int, cast occurred bool(true) int(2147483647) string(7) "integer" @@ -424,11 +426,13 @@ int(2147483647) string(7) "integer" -- Iteration 50 -- string(6) "double" +2: The float 2147483649 is not representable as an int, cast occurred bool(true) int(-2147483647) string(7) "integer" -- Iteration 51 -- string(6) "double" +2: The float 1232147483649 is not representable as an int, cast occurred bool(true) int(-508130303) string(7) "integer" @@ -439,6 +443,7 @@ int(85) string(7) "integer" -- Iteration 53 -- string(6) "double" +2: The float 1058513956921 is not representable as an int, cast occurred bool(true) int(1952002105) string(7) "integer" @@ -459,6 +464,7 @@ int(-365) string(7) "integer" -- Iteration 57 -- string(6) "double" +2: The float 80561044571754 is not representable as an int, cast occurred bool(true) int(343000682) string(7) "integer" @@ -669,6 +675,7 @@ int(1) string(7) "integer" -- Iteration 20 -- string(6) "string" +2: The float-string "2974394749328742328432" is not representable as an int, cast occurred bool(true) int(2147483647) string(7) "integer" @@ -699,6 +706,7 @@ int(1) string(7) "integer" -- Iteration 26 -- string(6) "string" +2: The float-string "2974394749328742328432" is not representable as an int, cast occurred bool(true) int(2147483647) string(7) "integer" @@ -819,11 +827,13 @@ int(2147483647) string(7) "integer" -- Iteration 50 -- string(6) "double" +2: The float 2147483649 is not representable as an int, cast occurred bool(true) int(-2147483647) string(7) "integer" -- Iteration 51 -- string(6) "double" +2: The float 1232147483649 is not representable as an int, cast occurred bool(true) int(-508130303) string(7) "integer" @@ -834,6 +844,7 @@ int(85) string(7) "integer" -- Iteration 53 -- string(6) "double" +2: The float 1058513956921 is not representable as an int, cast occurred bool(true) int(1952002105) string(7) "integer" @@ -854,6 +865,7 @@ int(-365) string(7) "integer" -- Iteration 57 -- string(6) "double" +2: The float 80561044571754 is not representable as an int, cast occurred bool(true) int(343000682) string(7) "integer" diff --git a/ext/standard/tests/general_functions/intval.phpt b/ext/standard/tests/general_functions/intval.phpt index 51d3b128f4797..83377d85a099a 100644 --- a/ext/standard/tests/general_functions/intval.phpt +++ b/ext/standard/tests/general_functions/intval.phpt @@ -94,13 +94,10 @@ $not_int_types = array ( array(), array(0), array(1), - array(NULL), array(null), array("string"), array(true), - array(TRUE), array(false), - array(FALSE), array(1,2,3,4), array(1 => "One", "two" => 2), @@ -127,12 +124,6 @@ $not_int_types = array ( /* booleans */ true, false, - TRUE, - FALSE, - - /* undefined and unset vars */ - @$unset_var, - @$undefined_var ); @@ -230,11 +221,19 @@ int(-2147483648) int(2147483647) *** 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) + +Warning: The float-string "2147483648" is not representable as an int, cast occurred in %s on line %d int(2147483647) int(0) int(0) + +Warning: The float-string "020000000001" is not representable as an int, cast occurred in %s on line %d int(2147483647) + +Warning: The float-string "-020000000001" is not representable as an int, cast occurred in %s on line %d int(-2147483648) int(0) int(0) @@ -256,9 +255,6 @@ int(1) int(1) int(1) int(1) -int(1) -int(1) -int(1) int(0) int(0) int(0) @@ -279,9 +275,5 @@ int(0) int(0) int(1) int(0) -int(1) -int(0) -int(0) -int(0) --- Done --- diff --git a/ext/standard/tests/math/bug30695.phpt b/ext/standard/tests/math/bug30695.phpt index 82771d0e0ab92..a2ac79c112629 100644 --- a/ext/standard/tests/math/bug30695.phpt +++ b/ext/standard/tests/math/bug30695.phpt @@ -53,22 +53,22 @@ if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only"); echo "\n", toUTF8(65), "\n", toUTF8(233), "\n", toUTF8(1252), "\n", toUTF8(20095), "\n"; ?> --EXPECTF-- -Deprecated: Implicit conversion from float 4294967168 to int loses precision in %s on line %d +Warning: The float 4294967168 is not representable as an int, cast occurred in %s on line %d A -Deprecated: Implicit conversion from float 4294967168 to int loses precision in %s on line %d +Warning: The float 4294967168 is not representable as an int, cast occurred in %s on line %d -Deprecated: Implicit conversion from float 4294965248 to int loses precision in %s on line %d +Warning: The float 4294965248 is not representable as an int, cast occurred in %s on line %d é -Deprecated: Implicit conversion from float 4294967168 to int loses precision in %s on line %d +Warning: The float 4294967168 is not representable as an int, cast occurred in %s on line %d -Deprecated: Implicit conversion from float 4294965248 to int loses precision in %s on line %d +Warning: The float 4294965248 is not representable as an int, cast occurred in %s on line %d Ӥ -Deprecated: Implicit conversion from float 4294967168 to int loses precision in %s on line %d +Warning: The float 4294967168 is not representable as an int, cast occurred in %s on line %d -Deprecated: Implicit conversion from float 4294965248 to int loses precision in %s on line %d +Warning: The float 4294965248 is not representable as an int, cast occurred in %s on line %d -Deprecated: Implicit conversion from float 4294901760 to int loses precision in %s on line %d +Warning: The float 4294901760 is not representable as an int, cast occurred in %s on line %d 乿 diff --git a/ext/standard/tests/strings/bug47842.phpt b/ext/standard/tests/strings/bug47842.phpt index fe97308ea53a7..1c8da881e7ced 100644 --- a/ext/standard/tests/strings/bug47842.phpt +++ b/ext/standard/tests/strings/bug47842.phpt @@ -23,12 +23,14 @@ printf("printf 64-bit signed int '18446744073709551615' (2^64)-1 = %u\n", 184467 echo "Done\n"; ?> ---EXPECT-- +--EXPECTF-- -Test sscanf 32-bit signed int '2147483647' (2^31)-1 = 2147483647 sscanf 32-bit unsign int '4294967295' (2^32)-1 = 4294967295 sscanf 64-bit signed int '9223372036854775807' (2^63)-1 = 9223372036854775807 sscanf 64-bit unsign int '18446744073709551615' (2^64)-1 = 18446744073709551615 printf 64-bit signed int '9223372036854775807' (2^63)-1 = 9223372036854775807 + +Warning: The float 1.8446744073709552E+19 is not representable as an int, cast occurred in %s on line %d printf 64-bit signed int '18446744073709551615' (2^64)-1 = 0 Done diff --git a/ext/standard/tests/strings/pack.phpt b/ext/standard/tests/strings/pack.phpt index af449266671da..e71f9ce37a964 100644 --- a/ext/standard/tests/strings/pack.phpt +++ b/ext/standard/tests/strings/pack.phpt @@ -97,7 +97,7 @@ print_r(unpack("v", pack("v", -1000))); print_r(unpack("v", pack("v", -64434))); print_r(unpack("v", pack("v", -65535))); ?> ---EXPECT-- +--EXPECTF-- Array ( [1] => h @@ -143,10 +143,14 @@ Array ( [1] => -64434 ) + +Warning: The float 4294967296 is not representable as an int, cast occurred in %s on line %d Array ( [1] => 0 ) + +Warning: The float -4294967296 is not representable as an int, cast occurred in %s on line %d Array ( [1] => 0 @@ -159,10 +163,14 @@ Array ( [1] => 0 ) + +Warning: The float 2147483650 is not representable as an int, cast occurred in %s on line %d Array ( [1] => -2147483646 ) + +Warning: The float 4294967295 is not representable as an int, cast occurred in %s on line %d Array ( [1] => -1 @@ -179,10 +187,14 @@ Array ( [1] => 0 ) + +Warning: The float 2147483650 is not representable as an int, cast occurred in %s on line %d Array ( [1] => -2147483646 ) + +Warning: The float 4294967296 is not representable as an int, cast occurred in %s on line %d Array ( [1] => 0 @@ -227,10 +239,14 @@ Array ( [1] => 0 ) + +Warning: The float 2147483650 is not representable as an int, cast occurred in %s on line %d Array ( [1] => -2147483646 ) + +Warning: The float 4294967296 is not representable as an int, cast occurred in %s on line %d Array ( [1] => 0 @@ -299,10 +315,14 @@ Array ( [1] => 0 ) + +Warning: The float 2147483650 is not representable as an int, cast occurred in %s on line %d Array ( [1] => -2147483646 ) + +Warning: The float 4294967296 is not representable as an int, cast occurred in %s on line %d Array ( [1] => 0 diff --git a/ext/standard/tests/strings/pack64.phpt b/ext/standard/tests/strings/pack64.phpt index 84e69008284d4..238195287b2b2 100644 --- a/ext/standard/tests/strings/pack64.phpt +++ b/ext/standard/tests/strings/pack64.phpt @@ -37,7 +37,7 @@ print_r(unpack("i", pack("i", -2147483647))); print_r(unpack("i", pack("i", -2147483648))); // Min int32 print_r(unpack("I", pack("I", 4294967295))); // Max uint32 ?> ---EXPECT-- +--EXPECTF-- Array ( [1] => 281474976710654 @@ -46,6 +46,8 @@ Array ( [1] => 0 ) + +Warning: The float 9.223372036854776E+18 is not representable as an int, cast occurred in %s on line %d Array ( [1] => -9223372036854775808 @@ -54,6 +56,8 @@ Array ( [1] => -1 ) + +Warning: The float 9.223372036854776E+18 is not representable as an int, cast occurred in %s on line %d Array ( [1] => -9223372036854775808 @@ -66,6 +70,8 @@ Array ( [1] => 0 ) + +Warning: The float 9.223372036854776E+18 is not representable as an int, cast occurred in %s on line %d Array ( [1] => -9223372036854775808 @@ -74,6 +80,8 @@ Array ( [1] => -1 ) + +Warning: The float 9.223372036854776E+18 is not representable as an int, cast occurred in %s on line %d Array ( [1] => -9223372036854775808 @@ -86,6 +94,8 @@ Array ( [1] => 0 ) + +Warning: The float 9.223372036854776E+18 is not representable as an int, cast occurred in %s on line %d Array ( [1] => -9223372036854775808 @@ -94,6 +104,8 @@ Array ( [1] => -1 ) + +Warning: The float 9.223372036854776E+18 is not representable as an int, cast occurred in %s on line %d Array ( [1] => -9223372036854775808 @@ -106,6 +118,8 @@ Array ( [1] => 0 ) + +Warning: The float 9.223372036854776E+18 is not representable as an int, cast occurred in %s on line %d Array ( [1] => -9223372036854775808 @@ -114,6 +128,8 @@ Array ( [1] => -1 ) + +Warning: The float 9.223372036854776E+18 is not representable as an int, cast occurred in %s on line %d Array ( [1] => -9223372036854775808 diff --git a/ext/standard/tests/strings/vprintf_variation12.phpt b/ext/standard/tests/strings/vprintf_variation12.phpt index cac53da18f4d8..f2e4270af3100 100644 --- a/ext/standard/tests/strings/vprintf_variation12.phpt +++ b/ext/standard/tests/strings/vprintf_variation12.phpt @@ -74,10 +74,16 @@ foreach($args_array as $args) { } ?> ---EXPECT-- +--EXPECTF-- *** Testing vprintf() : octal formats and non-octal values *** -- Iteration 1 -- + +Warning: The float 20000000000 is not representable as an int, cast occurred in %s on line %d + +Warning: The float 2000000000000 is not representable as an int, cast occurred in %s on line %d + +Warning: The float 22000000000000 is not representable as an int, cast occurred in %s on line %d 2 0 12 361100 37777775456 2322 diff --git a/ext/standard/tests/strings/vprintf_variation14.phpt b/ext/standard/tests/strings/vprintf_variation14.phpt index ce65e8726d871..4bda95917770a 100644 --- a/ext/standard/tests/strings/vprintf_variation14.phpt +++ b/ext/standard/tests/strings/vprintf_variation14.phpt @@ -75,10 +75,16 @@ foreach($args_array as $args) { } ?> ---EXPECT-- +--EXPECTF-- *** Testing vprintf() : hexa formats and non-hexa values *** -- Iteration 1 -- + +Warning: The float 20000000000 is not representable as an int, cast occurred in %s on line %d + +Warning: The float 2000000000000 is not representable as an int, cast occurred in %s on line %d + +Warning: The float 22000000000000 is not representable as an int, cast occurred in %s on line %d 2 0 a 1e240 x fffffb2e 4d2 diff --git a/ext/standard/tests/strings/vprintf_variation15.phpt b/ext/standard/tests/strings/vprintf_variation15.phpt index c8ae74f2aa75e..2eda443ebb95f 100644 --- a/ext/standard/tests/strings/vprintf_variation15.phpt +++ b/ext/standard/tests/strings/vprintf_variation15.phpt @@ -44,7 +44,7 @@ foreach($formats as $format) { } ?> ---EXPECT-- +--EXPECTF-- *** Testing vprintf() : unsigned formats and unsigned values *** -- Iteration 1 -- @@ -52,10 +52,14 @@ foreach($formats as $format) { int(16) -- Iteration 2 -- + +Warning: The float 12345678900 is not representable as an int, cast occurred in %s on line %d 3755744308 1234 12345 int(21) -- Iteration 3 -- + +Warning: The float 101234567000 is not representable as an int, cast occurred in %s on line %d 1234000 2450319192 120 int(25) diff --git a/ext/standard/tests/strings/vprintf_variation15_64bit.phpt b/ext/standard/tests/strings/vprintf_variation15_64bit.phpt index 2729e8f54af74..0ccb490095aac 100644 --- a/ext/standard/tests/strings/vprintf_variation15_64bit.phpt +++ b/ext/standard/tests/strings/vprintf_variation15_64bit.phpt @@ -44,7 +44,7 @@ foreach($formats as $format) { } ?> ---EXPECT-- +--EXPECTF-- *** Testing vprintf() : unsigned formats and unsigned values *** -- Iteration 1 -- @@ -56,6 +56,8 @@ int(16) int(22) -- Iteration 3 -- + +Warning: The float 1.0E+21 is not representable as an int, cast occurred in %s on line %d 1234000 3875820019684212736 120 int(34) diff --git a/ext/standard/tests/strings/vprintf_variation16.phpt b/ext/standard/tests/strings/vprintf_variation16.phpt index 70ecdab99e071..c064b7c4f0c78 100644 --- a/ext/standard/tests/strings/vprintf_variation16.phpt +++ b/ext/standard/tests/strings/vprintf_variation16.phpt @@ -66,10 +66,16 @@ foreach($args_array as $args) { $counter++; } ?> ---EXPECT-- +--EXPECTF-- *** Testing vprintf() : unsigned formats and signed & other types of values *** -- Iteration 1 -- + +Warning: The float 20000000000 is not representable as an int, cast occurred in %s on line %d + +Warning: The float 2000000000000 is not representable as an int, cast occurred in %s on line %d + +Warning: The float 22000000000000 is not representable as an int, cast occurred in %s on line %d 2 0 10 123456 123456 1234 2820130816 2840207360 1177509888 diff --git a/ext/standard/tests/strings/vprintf_variation4.phpt b/ext/standard/tests/strings/vprintf_variation4.phpt index 63018a9db8a86..96836f83ee618 100644 --- a/ext/standard/tests/strings/vprintf_variation4.phpt +++ b/ext/standard/tests/strings/vprintf_variation4.phpt @@ -67,10 +67,12 @@ foreach($args_array as $args) { } ?> ---EXPECT-- +--EXPECTF-- *** Testing vprintf() : int formats and non-integer values *** -- Iteration 1 -- + +Warning: The float 20000000000 is not representable as an int, cast occurred in %s on line %d 2 +0 10 123456 -1234 1234 -1474836480 200000 4000 22000000 diff --git a/main/php_variables.c b/main/php_variables.c index e0fe979d94d9b..971e1c77ea9f4 100644 --- a/main/php_variables.c +++ b/main/php_variables.c @@ -745,7 +745,7 @@ static inline void php_register_server_variables(void) /* store request init time */ ZVAL_DOUBLE(&tmp, sapi_get_request_time()); php_register_variable_quick("REQUEST_TIME_FLOAT", sizeof("REQUEST_TIME_FLOAT")-1, &tmp, ht); - ZVAL_LONG(&tmp, zend_dval_to_lval(Z_DVAL(tmp))); + ZVAL_LONG(&tmp, zend_dval_to_lval_silent(Z_DVAL(tmp))); php_register_variable_quick("REQUEST_TIME", sizeof("REQUEST_TIME")-1, &tmp, ht); } /* }}} */ diff --git a/tests/lang/bug27354.phpt b/tests/lang/bug27354.phpt index 5d18910bc9f32..e3cac1b170238 100644 --- a/tests/lang/bug27354.phpt +++ b/tests/lang/bug27354.phpt @@ -10,7 +10,7 @@ var_dump(-2147483648 % -2); --EXPECTF-- int(0) -Deprecated: Implicit conversion from float -9.223372036860776E+18 to int loses precision in %s on line %d +Warning: The float -9.223372036860776E+18 is not representable as an int, cast occurred in %s on line %d int(0) int(0) int(0) diff --git a/tests/lang/operators/bitwiseNot_basiclong_64bit.phpt b/tests/lang/operators/bitwiseNot_basiclong_64bit.phpt index 0e701051f5f47..1a1105a557a35 100644 --- a/tests/lang/operators/bitwiseNot_basiclong_64bit.phpt +++ b/tests/lang/operators/bitwiseNot_basiclong_64bit.phpt @@ -52,7 +52,7 @@ int(-4294967294) int(-9223372036854775807) --- testing: 9.2233720368548E+18 --- -Deprecated: Implicit conversion from float 9.223372036854776E+18 to int loses precision in %s on line %d +Warning: The float 9.223372036854776E+18 is not representable as an int, cast occurred in %s on line %d int(9223372036854775807) --- testing: -9223372036854775807 --- int(9223372036854775806) From 2a19375dd07e532c5bf48256a7521a4ff82813f9 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Sun, 21 Sep 2025 23:56:27 +0100 Subject: [PATCH 08/10] Update NEWS and UPGRADING for OOB floats to int casts --- NEWS | 2 ++ UPGRADING | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/NEWS b/NEWS index 548349b406375..4798f3e407b2b 100644 --- a/NEWS +++ b/NEWS @@ -15,6 +15,8 @@ PHP NEWS configured). (nielsdos) . Fixed bug GH-19719 (Allow empty statements before declare(strict_types)). (nielsdos) + . Casting floats that are not representable as ints now emits a warning. + (Girgias) - Curl: . Fix cloning of CURLOPT_POSTFIELDS when using the clone operator instead diff --git a/UPGRADING b/UPGRADING index e0974f16e4a85..c84a373d857b5 100644 --- a/UPGRADING +++ b/UPGRADING @@ -55,6 +55,10 @@ PHP 8.5 UPGRADE NOTES . Destructing non-array values (other than NULL) using [] or list() now emits a warning. 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 + floats) to int if they cannot be represented as one. This affects explicit + int casts and implicit int casts. + RFC: https://wiki.php.net/rfc/warnings-php-8-5#casting_out_of_range_floats_to_int - BZ2: . bzcompress() now throws a ValueError when $block_size is not between From 4fbd2480bface6d3f9b2c06f76c54e45f67ef92a Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Mon, 22 Sep 2025 00:06:30 +0100 Subject: [PATCH 09/10] ext/date: Deprecate __wakeup() methods in favour of __unserialize() (#19827) The __wakeup() method is obsolete as a __unserialize() magic method is implemented. Therefore, any class extending from those classes that overload deserialization should call the __unserialize() method instead of __wakeup() to properly handle the deserialization. This deprecation follows the wording of the deprecation of the SplFixedArray::__wakeup() magic method. --- ext/date/php_date.stub.php | 6 ++++ ext/date/php_date_arginfo.h | 61 ++++++++++++++++++++++++++++++++----- 2 files changed, 60 insertions(+), 7 deletions(-) diff --git a/ext/date/php_date.stub.php b/ext/date/php_date.stub.php index 0b151c9d42163..da2182dfb6fa7 100644 --- a/ext/date/php_date.stub.php +++ b/ext/date/php_date.stub.php @@ -323,6 +323,7 @@ public function getMicrosecond(): int; public function diff(DateTimeInterface $targetObject, bool $absolute = false): DateInterval; /** @tentative-return-type */ + #[\Deprecated(since: '8.5', message: 'this method is obsolete, as serialization hooks are provided by __unserialize() and __serialize()')] public function __wakeup(): void; public function __serialize(): array; @@ -339,6 +340,7 @@ public function __serialize(): array {} public function __unserialize(array $data): void {} /** @tentative-return-type */ + #[\Deprecated(since: '8.5', message: 'this method is obsolete, as serialization hooks are provided by __unserialize() and __serialize()')] public function __wakeup(): void {} /** @tentative-return-type */ @@ -456,6 +458,7 @@ public function __serialize(): array {} public function __unserialize(array $data): void {} /** @tentative-return-type */ + #[\Deprecated(since: '8.5', message: 'this method is obsolete, as serialization hooks are provided by __unserialize() and __serialize()')] public function __wakeup(): void {} /** @tentative-return-type */ @@ -632,6 +635,7 @@ public function __serialize(): array {} public function __unserialize(array $data): void {} /** @tentative-return-type */ + #[\Deprecated(since: '8.5', message: 'this method is obsolete, as serialization hooks are provided by __unserialize() and __serialize()')] public function __wakeup(): void {} /** @tentative-return-type */ @@ -658,6 +662,7 @@ public function __serialize(): array; public function __unserialize(array $data): void; /** @tentative-return-type */ + #[\Deprecated(since: '8.5', message: 'this method is obsolete, as serialization hooks are provided by __unserialize() and __serialize()')] public function __wakeup(): void {} /** @tentative-return-type */ @@ -734,6 +739,7 @@ public function __serialize(): array; public function __unserialize(array $data): void; /** @tentative-return-type */ + #[\Deprecated(since: '8.5', message: 'this method is obsolete, as serialization hooks are provided by __unserialize() and __serialize()')] public function __wakeup(): void {} /** @tentative-return-type */ diff --git a/ext/date/php_date_arginfo.h b/ext/date/php_date_arginfo.h index 5b583772e6582..873103d8ff90b 100644 --- a/ext/date/php_date_arginfo.h +++ b/ext/date/php_date_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 16d118b58a713bbea5174c170129aa9f6206de68 */ + * Stub hash: 8556e1b5f05ae9f78200f05f01d9f8e815cba49d */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_strtotime, 0, 1, MAY_BE_LONG|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, datetime, IS_STRING, 0) @@ -675,7 +675,7 @@ static const zend_function_entry class_DateTimeInterface_methods[] = { ZEND_RAW_FENTRY("getTimestamp", NULL, arginfo_class_DateTimeInterface_getTimestamp, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT, NULL, NULL) ZEND_RAW_FENTRY("getMicrosecond", NULL, arginfo_class_DateTimeInterface_getMicrosecond, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT, NULL, NULL) ZEND_RAW_FENTRY("diff", NULL, arginfo_class_DateTimeInterface_diff, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT, NULL, NULL) - ZEND_RAW_FENTRY("__wakeup", NULL, arginfo_class_DateTimeInterface___wakeup, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT, NULL, NULL) + ZEND_RAW_FENTRY("__wakeup", NULL, arginfo_class_DateTimeInterface___wakeup, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT|ZEND_ACC_DEPRECATED, NULL, NULL) ZEND_RAW_FENTRY("__serialize", NULL, arginfo_class_DateTimeInterface___serialize, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT, NULL, NULL) ZEND_RAW_FENTRY("__unserialize", NULL, arginfo_class_DateTimeInterface___unserialize, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT, NULL, NULL) ZEND_FE_END @@ -685,7 +685,7 @@ static const zend_function_entry class_DateTime_methods[] = { ZEND_ME(DateTime, __construct, arginfo_class_DateTime___construct, ZEND_ACC_PUBLIC) ZEND_ME(DateTime, __serialize, arginfo_class_DateTime___serialize, ZEND_ACC_PUBLIC) ZEND_ME(DateTime, __unserialize, arginfo_class_DateTime___unserialize, ZEND_ACC_PUBLIC) - ZEND_ME(DateTime, __wakeup, arginfo_class_DateTime___wakeup, ZEND_ACC_PUBLIC) + ZEND_ME(DateTime, __wakeup, arginfo_class_DateTime___wakeup, ZEND_ACC_PUBLIC|ZEND_ACC_DEPRECATED) ZEND_ME(DateTime, __set_state, arginfo_class_DateTime___set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) ZEND_ME(DateTime, createFromImmutable, arginfo_class_DateTime_createFromImmutable, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) ZEND_ME(DateTime, createFromInterface, arginfo_class_DateTime_createFromInterface, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) @@ -714,7 +714,7 @@ static const zend_function_entry class_DateTimeImmutable_methods[] = { ZEND_ME(DateTimeImmutable, __construct, arginfo_class_DateTimeImmutable___construct, ZEND_ACC_PUBLIC) ZEND_ME(DateTimeImmutable, __serialize, arginfo_class_DateTimeImmutable___serialize, ZEND_ACC_PUBLIC) ZEND_ME(DateTimeImmutable, __unserialize, arginfo_class_DateTimeImmutable___unserialize, ZEND_ACC_PUBLIC) - ZEND_ME(DateTimeImmutable, __wakeup, arginfo_class_DateTimeImmutable___wakeup, ZEND_ACC_PUBLIC) + ZEND_ME(DateTimeImmutable, __wakeup, arginfo_class_DateTimeImmutable___wakeup, ZEND_ACC_PUBLIC|ZEND_ACC_DEPRECATED) ZEND_ME(DateTimeImmutable, __set_state, arginfo_class_DateTimeImmutable___set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) ZEND_RAW_FENTRY("createFromFormat", zif_date_create_immutable_from_format, arginfo_class_DateTimeImmutable_createFromFormat, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC, NULL, NULL) ZEND_ME(DateTimeImmutable, createFromTimestamp, arginfo_class_DateTimeImmutable_createFromTimestamp, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) @@ -749,7 +749,7 @@ static const zend_function_entry class_DateTimeZone_methods[] = { ZEND_RAW_FENTRY("listIdentifiers", zif_timezone_identifiers_list, arginfo_class_DateTimeZone_listIdentifiers, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC, NULL, NULL) ZEND_ME(DateTimeZone, __serialize, arginfo_class_DateTimeZone___serialize, ZEND_ACC_PUBLIC) ZEND_ME(DateTimeZone, __unserialize, arginfo_class_DateTimeZone___unserialize, ZEND_ACC_PUBLIC) - ZEND_ME(DateTimeZone, __wakeup, arginfo_class_DateTimeZone___wakeup, ZEND_ACC_PUBLIC) + ZEND_ME(DateTimeZone, __wakeup, arginfo_class_DateTimeZone___wakeup, ZEND_ACC_PUBLIC|ZEND_ACC_DEPRECATED) ZEND_ME(DateTimeZone, __set_state, arginfo_class_DateTimeZone___set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) ZEND_FE_END }; @@ -760,7 +760,7 @@ static const zend_function_entry class_DateInterval_methods[] = { ZEND_RAW_FENTRY("format", zif_date_interval_format, arginfo_class_DateInterval_format, ZEND_ACC_PUBLIC, NULL, NULL) ZEND_ME(DateInterval, __serialize, arginfo_class_DateInterval___serialize, ZEND_ACC_PUBLIC) ZEND_ME(DateInterval, __unserialize, arginfo_class_DateInterval___unserialize, ZEND_ACC_PUBLIC) - ZEND_ME(DateInterval, __wakeup, arginfo_class_DateInterval___wakeup, ZEND_ACC_PUBLIC) + ZEND_ME(DateInterval, __wakeup, arginfo_class_DateInterval___wakeup, ZEND_ACC_PUBLIC|ZEND_ACC_DEPRECATED) ZEND_ME(DateInterval, __set_state, arginfo_class_DateInterval___set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) ZEND_FE_END }; @@ -774,7 +774,7 @@ static const zend_function_entry class_DatePeriod_methods[] = { ZEND_ME(DatePeriod, getRecurrences, arginfo_class_DatePeriod_getRecurrences, ZEND_ACC_PUBLIC) ZEND_ME(DatePeriod, __serialize, arginfo_class_DatePeriod___serialize, ZEND_ACC_PUBLIC) ZEND_ME(DatePeriod, __unserialize, arginfo_class_DatePeriod___unserialize, ZEND_ACC_PUBLIC) - ZEND_ME(DatePeriod, __wakeup, arginfo_class_DatePeriod___wakeup, ZEND_ACC_PUBLIC) + ZEND_ME(DatePeriod, __wakeup, arginfo_class_DatePeriod___wakeup, ZEND_ACC_PUBLIC|ZEND_ACC_DEPRECATED) ZEND_ME(DatePeriod, __set_state, arginfo_class_DatePeriod___set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) ZEND_ME(DatePeriod, getIterator, arginfo_class_DatePeriod_getIterator, ZEND_ACC_PUBLIC) ZEND_FE_END @@ -979,6 +979,14 @@ static zend_class_entry *register_class_DateTimeInterface(void) ZVAL_STR(&attribute_Deprecated_const_RFC7231_0->args[1].value, attribute_Deprecated_const_RFC7231_0_arg1_str); attribute_Deprecated_const_RFC7231_0->args[1].name = ZSTR_KNOWN(ZEND_STR_MESSAGE); + + zend_attribute *attribute_Deprecated_func___wakeup_0 = zend_add_function_attribute(zend_hash_str_find_ptr(&class_entry->function_table, "__wakeup", sizeof("__wakeup") - 1), ZSTR_KNOWN(ZEND_STR_DEPRECATED_CAPITALIZED), 2); + ZVAL_STR(&attribute_Deprecated_func___wakeup_0->args[0].value, ZSTR_KNOWN(ZEND_STR_8_DOT_5)); + attribute_Deprecated_func___wakeup_0->args[0].name = ZSTR_KNOWN(ZEND_STR_SINCE); + zend_string *attribute_Deprecated_func___wakeup_0_arg1_str = zend_string_init("this method is obsolete, as serialization hooks are provided by __unserialize() and __serialize()", strlen("this method is obsolete, as serialization hooks are provided by __unserialize() and __serialize()"), 1); + ZVAL_STR(&attribute_Deprecated_func___wakeup_0->args[1].value, attribute_Deprecated_func___wakeup_0_arg1_str); + attribute_Deprecated_func___wakeup_0->args[1].name = ZSTR_KNOWN(ZEND_STR_MESSAGE); + return class_entry; } @@ -990,6 +998,14 @@ static zend_class_entry *register_class_DateTime(zend_class_entry *class_entry_D class_entry = zend_register_internal_class_with_flags(&ce, NULL, 0); zend_class_implements(class_entry, 1, class_entry_DateTimeInterface); + + zend_attribute *attribute_Deprecated_func___wakeup_0 = zend_add_function_attribute(zend_hash_str_find_ptr(&class_entry->function_table, "__wakeup", sizeof("__wakeup") - 1), ZSTR_KNOWN(ZEND_STR_DEPRECATED_CAPITALIZED), 2); + ZVAL_STR(&attribute_Deprecated_func___wakeup_0->args[0].value, ZSTR_KNOWN(ZEND_STR_8_DOT_5)); + attribute_Deprecated_func___wakeup_0->args[0].name = ZSTR_KNOWN(ZEND_STR_SINCE); + zend_string *attribute_Deprecated_func___wakeup_0_arg1_str = zend_string_init("this method is obsolete, as serialization hooks are provided by __unserialize() and __serialize()", strlen("this method is obsolete, as serialization hooks are provided by __unserialize() and __serialize()"), 1); + ZVAL_STR(&attribute_Deprecated_func___wakeup_0->args[1].value, attribute_Deprecated_func___wakeup_0_arg1_str); + attribute_Deprecated_func___wakeup_0->args[1].name = ZSTR_KNOWN(ZEND_STR_MESSAGE); + return class_entry; } @@ -1002,6 +1018,13 @@ static zend_class_entry *register_class_DateTimeImmutable(zend_class_entry *clas zend_class_implements(class_entry, 1, class_entry_DateTimeInterface); + zend_attribute *attribute_Deprecated_func___wakeup_0 = zend_add_function_attribute(zend_hash_str_find_ptr(&class_entry->function_table, "__wakeup", sizeof("__wakeup") - 1), ZSTR_KNOWN(ZEND_STR_DEPRECATED_CAPITALIZED), 2); + ZVAL_STR(&attribute_Deprecated_func___wakeup_0->args[0].value, ZSTR_KNOWN(ZEND_STR_8_DOT_5)); + attribute_Deprecated_func___wakeup_0->args[0].name = ZSTR_KNOWN(ZEND_STR_SINCE); + zend_string *attribute_Deprecated_func___wakeup_0_arg1_str = zend_string_init("this method is obsolete, as serialization hooks are provided by __unserialize() and __serialize()", strlen("this method is obsolete, as serialization hooks are provided by __unserialize() and __serialize()"), 1); + ZVAL_STR(&attribute_Deprecated_func___wakeup_0->args[1].value, attribute_Deprecated_func___wakeup_0_arg1_str); + attribute_Deprecated_func___wakeup_0->args[1].name = ZSTR_KNOWN(ZEND_STR_MESSAGE); + zend_string *attribute_name_NoDiscard_func_modify_0 = zend_string_init_interned("NoDiscard", sizeof("NoDiscard") - 1, 1); zend_attribute *attribute_NoDiscard_func_modify_0 = zend_add_function_attribute(zend_hash_str_find_ptr(&class_entry->function_table, "modify", sizeof("modify") - 1), attribute_name_NoDiscard_func_modify_0, 1); zend_string_release(attribute_name_NoDiscard_func_modify_0); @@ -1159,6 +1182,14 @@ static zend_class_entry *register_class_DateTimeZone(void) zend_declare_typed_class_constant(class_entry, const_PER_COUNTRY_name, &const_PER_COUNTRY_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_LONG)); zend_string_release(const_PER_COUNTRY_name); + + zend_attribute *attribute_Deprecated_func___wakeup_0 = zend_add_function_attribute(zend_hash_str_find_ptr(&class_entry->function_table, "__wakeup", sizeof("__wakeup") - 1), ZSTR_KNOWN(ZEND_STR_DEPRECATED_CAPITALIZED), 2); + ZVAL_STR(&attribute_Deprecated_func___wakeup_0->args[0].value, ZSTR_KNOWN(ZEND_STR_8_DOT_5)); + attribute_Deprecated_func___wakeup_0->args[0].name = ZSTR_KNOWN(ZEND_STR_SINCE); + zend_string *attribute_Deprecated_func___wakeup_0_arg1_str = zend_string_init("this method is obsolete, as serialization hooks are provided by __unserialize() and __serialize()", strlen("this method is obsolete, as serialization hooks are provided by __unserialize() and __serialize()"), 1); + ZVAL_STR(&attribute_Deprecated_func___wakeup_0->args[1].value, attribute_Deprecated_func___wakeup_0_arg1_str); + attribute_Deprecated_func___wakeup_0->args[1].name = ZSTR_KNOWN(ZEND_STR_MESSAGE); + return class_entry; } @@ -1169,6 +1200,14 @@ static zend_class_entry *register_class_DateInterval(void) INIT_CLASS_ENTRY(ce, "DateInterval", class_DateInterval_methods); class_entry = zend_register_internal_class_with_flags(&ce, NULL, 0); + + zend_attribute *attribute_Deprecated_func___wakeup_0 = zend_add_function_attribute(zend_hash_str_find_ptr(&class_entry->function_table, "__wakeup", sizeof("__wakeup") - 1), ZSTR_KNOWN(ZEND_STR_DEPRECATED_CAPITALIZED), 2); + ZVAL_STR(&attribute_Deprecated_func___wakeup_0->args[0].value, ZSTR_KNOWN(ZEND_STR_8_DOT_5)); + attribute_Deprecated_func___wakeup_0->args[0].name = ZSTR_KNOWN(ZEND_STR_SINCE); + zend_string *attribute_Deprecated_func___wakeup_0_arg1_str = zend_string_init("this method is obsolete, as serialization hooks are provided by __unserialize() and __serialize()", strlen("this method is obsolete, as serialization hooks are provided by __unserialize() and __serialize()"), 1); + ZVAL_STR(&attribute_Deprecated_func___wakeup_0->args[1].value, attribute_Deprecated_func___wakeup_0_arg1_str); + attribute_Deprecated_func___wakeup_0->args[1].name = ZSTR_KNOWN(ZEND_STR_MESSAGE); + return class_entry; } @@ -1238,6 +1277,14 @@ static zend_class_entry *register_class_DatePeriod(zend_class_entry *class_entry zend_declare_typed_property(class_entry, property_include_end_date_name, &property_include_end_date_default_value, ZEND_ACC_PUBLIC|ZEND_ACC_VIRTUAL, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_BOOL)); zend_string_release(property_include_end_date_name); + + zend_attribute *attribute_Deprecated_func___wakeup_0 = zend_add_function_attribute(zend_hash_str_find_ptr(&class_entry->function_table, "__wakeup", sizeof("__wakeup") - 1), ZSTR_KNOWN(ZEND_STR_DEPRECATED_CAPITALIZED), 2); + ZVAL_STR(&attribute_Deprecated_func___wakeup_0->args[0].value, ZSTR_KNOWN(ZEND_STR_8_DOT_5)); + attribute_Deprecated_func___wakeup_0->args[0].name = ZSTR_KNOWN(ZEND_STR_SINCE); + zend_string *attribute_Deprecated_func___wakeup_0_arg1_str = zend_string_init("this method is obsolete, as serialization hooks are provided by __unserialize() and __serialize()", strlen("this method is obsolete, as serialization hooks are provided by __unserialize() and __serialize()"), 1); + ZVAL_STR(&attribute_Deprecated_func___wakeup_0->args[1].value, attribute_Deprecated_func___wakeup_0_arg1_str); + attribute_Deprecated_func___wakeup_0->args[1].name = ZSTR_KNOWN(ZEND_STR_MESSAGE); + return class_entry; } From 4bc060c0f3f60d6436ad8d3d9ee5078d142cadcd Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Mon, 22 Sep 2025 00:10:19 +0100 Subject: [PATCH 10/10] Update NEWS and UPGRADING for __wakeup() deprecation of date classes --- NEWS | 3 +++ UPGRADING | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/NEWS b/NEWS index 4798f3e407b2b..42ce461a4e19d 100644 --- a/NEWS +++ b/NEWS @@ -25,6 +25,9 @@ PHP NEWS - Date: . Fixed GH-17159: "P" format for ::createFromFormat swallows string literals. (nielsdos) + . The __wakeup() magic method of DateTimeInterface, DateTime, + DateTimeImmutable, DateTimeZone, DateInterval, and DatePeriod has been + deprecated in favour of the __unserialize() magic method. (Girgias) - Exif: . Fix OSS-Fuzz #442954659 (zero-size box in HEIF file causes infinite loop). diff --git a/UPGRADING b/UPGRADING index c84a373d857b5..fc6000686c4eb 100644 --- a/UPGRADING +++ b/UPGRADING @@ -417,6 +417,10 @@ PHP 8.5 UPGRADE NOTES deprecated. This is because the associated timezone is ignored and always uses GMT. RFC: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_date_rfc7231_and_datetimeinterfacerfc7231 + . The __wakeup() magic method of DateTimeInterface, DateTime, + DateTimeImmutable, DateTimeZone, DateInterval, and DatePeriod has been + deprecated in favour of the __unserialize() magic method. + Related to RFC: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_the_sleep_and_wakeup_magic_methods - FileInfo: . The finfo_close() function has been deprecated.