php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login

Patch 5.6series-patch for JSON related Bug #69792

Patch version 2015-06-10 12:44 UTC

Return to Bug #69792 | Download this patch
Patch Revisions:

Developer: ryat

diff --git a/php-5.6.9/ext/json/json.c b/php-5.6.9-fix/ext/json/json.c
index f016349..df7cf53 100644
--- a/php-5.6.9/ext/json/json.c
+++ b/php-5.6.9-fix/ext/json/json.c
@@ -606,6 +606,7 @@ static void json_encode_serializable_object(smart_str *buf, zval *val, int optio
 		/* Handle the case where jsonSerialize does: return $this; by going straight to encode array */
 		json_encode_array(buf, &retval, options TSRMLS_CC);
 	} else {
+		++JSON_G(encoder_depth);
 		/* All other types, encode as normal */
 		php_json_encode(buf, retval, options TSRMLS_CC);
 	}
@@ -661,6 +662,10 @@ PHP_JSON_API void php_json_encode(smart_str *buf, zval *val, int options TSRMLS_
 			break;
 
 		case IS_OBJECT:
+			if (JSON_G(encoder_depth) > JSON_G(encode_max_depth)) {
+				JSON_G(error_code) = PHP_JSON_ERROR_DEPTH;
+				break;
+			}
 			if (instanceof_function(Z_OBJCE_P(val), php_json_serializable_ce TSRMLS_CC)) {
 				json_encode_serializable_object(buf, val, options TSRMLS_CC);
 				break;
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 21:01:29 2024 UTC