com php-src: Fixed bug #72787 (json_decode reads out of bounds): NEWS ext/json/json.c ext/json/tests/b ug72787.phpt
| From: | Jakub Zelenka | Date: | Sun, 14 Aug 2016 12:52:59 +0000 |
| Subject: | com php-src: Fixed bug #72787 (json_decode reads out of bounds): NEWS ext/json/json.c ext/json/tests/b ug72787.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-93773@lists.php.net to get a copy of this message | ||
Commit: 9f1d962ed6057a3996f1b5aa82467a3172e41e8f
Author: Jakub Zelenka <bukka@php.net> Sun, 14 Aug 2016 13:52:59 +0100
Parents: dfadc5a427b548cab2b7c037c05f65684e08a248
Branches: PHP-5.6
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=9f1d962ed6057a3996f1b5aa82467a3172e41e8f
Log:
Fixed bug #72787 (json_decode reads out of bounds)
Bugs:
https://bugs.php.net/72787
Changed paths:
M NEWS
M ext/json/json.c
A ext/json/tests/bug72787.phpt
Diff:
diff --git a/NEWS b/NEWS
index ccafb63..6a4fa50 100644
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,9 @@ PHP NEWS
. Fixed bug #70195 (Cannot upload file using ftp_put to FTPES with
require_ssl_reuse). (Benedict Singer)
+- JSON:
+ . Fixed bug #72787 (json_decode reads out of bounds). (Jakub Zelenka)
+
- MSSQL:
. Fixed bug #72039 (Use of uninitialised value on mssql_guid_string). (Kalle)
diff --git a/ext/json/json.c b/ext/json/json.c
index 634d6e5..8c4d20f 100644
--- a/ext/json/json.c
+++ b/ext/json/json.c
@@ -704,6 +704,12 @@ PHP_JSON_API void php_json_decode_ex(zval *return_value, char *str, int
str_len,
RETURN_NULL();
}
+ if (depth > INT_MAX) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Depth must be lower than %d", INT_MAX);
+ efree(utf16);
+ RETURN_NULL();
+ }
+
ALLOC_INIT_ZVAL(z);
jp = new_JSON_parser(depth);
if (parse_JSON_ex(jp, z, utf16, utf16_len, options TSRMLS_CC)) {
diff --git a/ext/json/tests/bug72787.phpt b/ext/json/tests/bug72787.phpt
new file mode 100644
index 0000000..c9820fa
--- /dev/null
+++ b/ext/json/tests/bug72787.phpt
@@ -0,0 +1,15 @@
+--TEST--
+Bug #72787 (json_decode reads out of bounds)
+--SKIPIF--
+<?php if (!extension_loaded("json")) print "skip"; ?>
+<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); ?>
+--FILE--
+<?php
+
+var_dump(json_decode('[]', false, 0x100000000));
+
+?>
+--EXPECTF--
+
+Warning: json_decode(): Depth must be lower than %d in %s on line %d
+NULL