Skip to content

Commit 625f0c1

Browse files
committed
patch 8.0.1602: crash in parsing JSON
Problem: Crash in parsing JSON. Solution: Fail when using array or dict as dict key. (Damien)
1 parent ff1e879 commit 625f0c1

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

src/json.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,9 @@ json_decode_item(js_read_T *reader, typval_T *res, int options)
621621
if (top_item != NULL && top_item->jd_type == JSON_OBJECT_KEY
622622
&& (options & JSON_JS)
623623
&& reader->js_buf[reader->js_used] != '"'
624-
&& reader->js_buf[reader->js_used] != '\'')
624+
&& reader->js_buf[reader->js_used] != '\''
625+
&& reader->js_buf[reader->js_used] != '['
626+
&& reader->js_buf[reader->js_used] != '{')
625627
{
626628
char_u *key;
627629

@@ -642,6 +644,11 @@ json_decode_item(js_read_T *reader, typval_T *res, int options)
642644
switch (*p)
643645
{
644646
case '[': /* start of array */
647+
if (top_item && top_item->jd_type == JSON_OBJECT_KEY)
648+
{
649+
retval = FAIL;
650+
break;
651+
}
645652
if (ga_grow(&stack, 1) == FAIL)
646653
{
647654
retval = FAIL;
@@ -668,6 +675,11 @@ json_decode_item(js_read_T *reader, typval_T *res, int options)
668675
continue;
669676

670677
case '{': /* start of object */
678+
if (top_item && top_item->jd_type == JSON_OBJECT_KEY)
679+
{
680+
retval = FAIL;
681+
break;
682+
}
671683
if (ga_grow(&stack, 1) == FAIL)
672684
{
673685
retval = FAIL;

src/testdir/test_json.vim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ func Test_json_decode()
179179
call assert_fails('call json_decode("[1 2]")', "E474:")
180180

181181
call assert_fails('call json_decode("[1,,2]")', "E474:")
182+
183+
call assert_fails('call json_decode("{{}:42}")', "E474:")
184+
call assert_fails('call json_decode("{[]:42}")', "E474:")
182185
endfunc
183186

184187
let s:jsl5 = '[7,,,]'

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,8 @@ static char *(features[]) =
766766

767767
static int included_patches[] =
768768
{ /* Add new patch number below this line */
769+
/**/
770+
1602,
769771
/**/
770772
1601,
771773
/**/

0 commit comments

Comments
 (0)