com php-src: Fix bug #68567 (JSON_PARTIAL_OUTPUT_ON_E RROR can result in JSON with null key): NEW S ext/json/json_encoder.c ext/json/tests/bug685
67.phpt
| From: | Jakub Zelenka | Date: | Sun, 15 Oct 2017 18:36:15 +0000 |
| Subject: | com php-src: Fix bug #68567 (JSON_PARTIAL_OUTPUT_ON_E RROR can result in JSON with null key): NEW S ext/json/json_encoder.c ext/json/tests/bug685 67.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-99751@lists.php.net to get a copy of this message | ||
Commit: 7c556c44a10bfc53c37295626e61bd99dc4f550c
Author: Jakub Zelenka <bukka@php.net> Sun, 15 Oct 2017 19:36:15 +0100
Parents: 46d87c1f104261331a3fa33208f2da4d92c59225
Branches: PHP-7.2
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=7c556c44a10bfc53c37295626e61bd99dc4f550c
Log:
Fix bug #68567 (JSON_PARTIAL_OUTPUT_ON_ERROR can result in JSON with null key)
Bugs:
https://bugs.php.net/68567
Changed paths:
M NEWS
M ext/json/json_encoder.c
A ext/json/tests/bug68567.phpt
Diff:
diff --git a/NEWS b/NEWS
index bc73ef5..8c03208 100644
--- a/NEWS
+++ b/NEWS
@@ -22,6 +22,10 @@ PHP NEWS
- Fileinfo:
. Upgrade bundled libmagic to 5.31. (Anatol)
+- JSON:
+ . Fixed bug #68567 (JSON_PARTIAL_OUTPUT_ON_ERROR can result in JSON with null
+ key). (Jakub Zelenka)
+
- Opcache:
. Fixed bug #75370 (Webserver hangs on valid PHP text). (Laruence)
. Fixed bug #75357 (segfault loading WordPress wp-admin). (Laruence)
diff --git a/ext/json/json_encoder.c b/ext/json/json_encoder.c
index 1fa2344..fcdb315 100644
--- a/ext/json/json_encoder.c
+++ b/ext/json/json_encoder.c
@@ -189,8 +189,13 @@ static int php_json_encode_array(smart_str *buf, zval *val, int options,
php_jso
php_json_pretty_print_char(buf, options, '\n');
php_json_pretty_print_indent(buf, options, encoder);
- php_json_escape_string(buf, ZSTR_VAL(key), ZSTR_LEN(key),
- options & ~PHP_JSON_NUMERIC_CHECK, encoder);
+ if (php_json_escape_string(buf, ZSTR_VAL(key), ZSTR_LEN(key),
+ options & ~PHP_JSON_NUMERIC_CHECK, encoder) == FAILURE &&
+ (options & PHP_JSON_PARTIAL_OUTPUT_ON_ERROR) &&
+ buf->s) {
+ ZSTR_LEN(buf->s) -= 4;
+ smart_str_appendl(buf, "\"\"", 2);
+ }
} else {
if (need_comma) {
smart_str_appendc(buf, ',');
diff --git a/ext/json/tests/bug68567.phpt b/ext/json/tests/bug68567.phpt
new file mode 100644
index 0000000..6d4082c
--- /dev/null
+++ b/ext/json/tests/bug68567.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Bug #68567 JSON_PARTIAL_OUTPUT_ON_ERROR can result in JSON with null key
+--SKIPIF--
+<?php if (!extension_loaded("json")) print "skip"; ?>
+--FILE--
+<?php
+
+var_dump(json_encode(array("\x80" => 1), JSON_PARTIAL_OUTPUT_ON_ERROR));
+
+?>
+===DONE===
+--EXPECTF--
+string(6) "{"":1}"
+===DONE===