Skip to content

Commit

Permalink
Fix bug #68567 (JSON_PARTIAL_OUTPUT_ON_ERROR can result in JSON with …
Browse files Browse the repository at this point in the history
…null key)
  • Loading branch information
bukka committed Oct 15, 2017
1 parent 46d87c1 commit 7c556c4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 7 additions & 2 deletions ext/json/json_encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, ',');
Expand Down
14 changes: 14 additions & 0 deletions ext/json/tests/bug68567.phpt
Original file line number Diff line number Diff line change
@@ -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===

0 comments on commit 7c556c4

Please sign in to comment.