[php-src] PHP-8.6: Merge branch 'PHP-8.4' into PHP-8.5

From: Date: Fri, 30 Oct 2026 21:27:48 +0000
Subject: [php-src] PHP-8.6: Merge branch 'PHP-8.4' into PHP-8.5
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-143045@lists.php.net to get a copy of this message
Author: Jakub Zelenka (bukka) Date: 2026-10-30T22:24:35+01:00 Commit: https://github.com/php/php-src/commit/8dace271f0726c2a7fb00ae526e16b93e91632d0 Raw diff: https://github.com/php/php-src/commit/8dace271f0726c2a7fb00ae526e16b93e91632d0.diff Merge branch 'PHP-8.4' into PHP-8.5 * PHP-8.4: Fix json_encode() depth range check before narrowing Changed paths: A ext/json/tests/json_encode_depth.phpt M NEWS M ext/json/json.c Diff: diff --git a/NEWS b/NEWS index a0dc2c9db6e7..d764d7e175bd 100644 --- a/NEWS +++ b/NEWS @@ -90,6 +90,8 @@ PHP NEWS . Fixed json_encode() leaving the recursion guard set on objects with hooked properties after running out of memory while escaping a property name. (adapik) + . Fixed json_encode() silently narrowing $depth values outside the int range, + which wrapped to an unrelated depth. (cuishuang) - LDAP: . Fix crash in ldap_exop_sync() when $response_data is omitted. (lacatoire) diff --git a/ext/json/json.c b/ext/json/json.c index 9f91d39594ec..0b42187491ff 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -232,6 +232,11 @@ PHP_FUNCTION(json_encode) Z_PARAM_LONG(depth) ZEND_PARSE_PARAMETERS_END(); + if (ZEND_LONG_EXCEEDS_INT(depth)) { + zend_argument_value_error(3, "must be between %d and %d", INT_MIN, INT_MAX); + RETURN_THROWS(); + } + php_json_encode_init(&encoder); encoder.max_depth = (int)depth; php_json_encode_zval(&buf, parameter, (int)options, &encoder); diff --git a/ext/json/tests/json_encode_depth.phpt b/ext/json/tests/json_encode_depth.phpt new file mode 100644 index 000000000000..075228da472c --- /dev/null +++ b/ext/json/tests/json_encode_depth.phpt @@ -0,0 +1,19 @@ +--TEST-- +json_encode() rejects depth values outside the encoder range +--SKIPIF-- +<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); ?> +--FILE-- +<?php + +foreach ([2147483648, -2147483649] as $depth) { + try { + json_encode([], depth: $depth); + } catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; + } +} + +?> +--EXPECT-- +ValueError: json_encode(): Argument #3 ($depth) must be between -2147483648 and 2147483647 +ValueError: json_encode(): Argument #3 ($depth) must be between -2147483648 and 2147483647

« previous php.cvs (#143045) next »