[php-src] PHP-8.4: Fix json_decode() and json_validate() depth upper bound messages (#25468)

From: Date: Mon, 16 Nov 2026 17:27:31 +0000
Subject: [php-src] PHP-8.4: Fix json_decode() and json_validate() depth upper bound messages (#25468)
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-143745@lists.php.net to get a copy of this message
Author: lacatoire (lacatoire) Committer: Weilin Du (LamentXU123) Date: 2026-11-17T01:19:13+08:00 Commit: https://github.com/php/php-src/commit/d5facaf88761737052beca2c988f33e16faa6f97 Raw diff: https://github.com/php/php-src/commit/d5facaf88761737052beca2c988f33e16faa6f97.diff Fix json_decode() and json_validate() depth upper bound messages (#25468) Both functions accept a depth of INT_MAX, but rejected larger values with "must be less than 2147483647". Report "less than or equal to" instead so the error messages describe the inclusive upper bound correctly. Update the corresponding test expectations. Closes #25468 Changed paths: M NEWS M ext/json/json.c M ext/json/tests/bug72787.phpt M ext/json/tests/json_validate_003.phpt Diff: diff --git a/NEWS b/NEWS index a6555ac871c9..d98e18da8d42 100644 --- a/NEWS +++ b/NEWS @@ -176,6 +176,7 @@ PHP NEWS INT_MIN. (Marc Bennewitz) - JSON: + . Fixed json_decode() and json_validate() error messages. (lacatoire) . Fixed json_encode() leaving the recursion guard set on objects with hooked properties after running out of memory while escaping a property name. (adapik) diff --git a/ext/json/json.c b/ext/json/json.c index 0b42187491ff..3ff83e9009ba 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -296,7 +296,7 @@ PHP_FUNCTION(json_decode) } if (depth > INT_MAX) { - zend_argument_value_error(3, "must be less than %d", INT_MAX); + zend_argument_value_error(3, "must be less than or equal to %d", INT_MAX); RETURN_THROWS(); } @@ -347,7 +347,7 @@ PHP_FUNCTION(json_validate) } if (depth > INT_MAX) { - zend_argument_value_error(2, "must be less than %d", INT_MAX); + zend_argument_value_error(2, "must be less than or equal to %d", INT_MAX); RETURN_THROWS(); } diff --git a/ext/json/tests/bug72787.phpt b/ext/json/tests/bug72787.phpt index c08bd18ec9b1..4c2f8d62c5db 100644 --- a/ext/json/tests/bug72787.phpt +++ b/ext/json/tests/bug72787.phpt @@ -13,4 +13,4 @@ try { ?> --EXPECTF-- -json_decode(): Argument #3 ($depth) must be less than %d +json_decode(): Argument #3 ($depth) must be less than or equal to %d diff --git a/ext/json/tests/json_validate_003.phpt b/ext/json/tests/json_validate_003.phpt index cd0545b9a7f9..faad350b4e93 100644 --- a/ext/json/tests/json_validate_003.phpt +++ b/ext/json/tests/json_validate_003.phpt @@ -14,6 +14,6 @@ try { ?> --EXPECTF-- -json_validate(): Argument #2 ($depth) must be less than %d +json_validate(): Argument #2 ($depth) must be less than or equal to %d int(0) string(8) "No error"

« previous php.cvs (#143745) next »