[php-src] master: Merge branch 'PHP-8.6'
| From: | Jakub Zelenka | Date: | Fri, 30 Oct 2026 21:27:53 +0000 |
| Subject: | [php-src] master: Merge branch 'PHP-8.6' | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-143044@lists.php.net to get a copy of this message | ||
Author: Jakub Zelenka (bukka)
Date: 2026-10-30T22:27:20+01:00
Commit: https://github.com/php/php-src/commit/d4f79e2ee86a5dfd3b12f34d75af6d5bd0a0f9ab
Raw diff: https://github.com/php/php-src/commit/d4f79e2ee86a5dfd3b12f34d75af6d5bd0a0f9ab.diff
Merge branch 'PHP-8.6'
* PHP-8.6:
Fix json_encode() depth range check before narrowing
Changed paths:
A ext/json/tests/json_encode_depth.phpt
M ext/json/json.c
Diff:
diff --git a/ext/json/json.c b/ext/json/json.c
index dbae11c98f40..9aea6b02c789 100644
--- a/ext/json/json.c
+++ b/ext/json/json.c
@@ -249,6 +249,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