[vim] Trying to dump deeply nested list with jsonencode() crashes (#588)

20 views
Skip to first unread message

Nikolai Aleksandrovich Pavlov

unread,
Jan 23, 2016, 8:06:40 PM1/23/16
to vim/vim

Consider the following code:

vim -u NONE --cmd 'let l=[]' --cmd 'call map(range(1024*1024), "extend(g:, {\"l\": [g:l]})")' --cmd 'echo jsonencode(l)'

This crashes with stack full of json_encode_item() calls.

One may be interested in code from neovim/neovim#3365 because it is not using recursion for dumping values.


Reply to this email directly or view it on GitHub.

Bram Moolenaar

unread,
Jan 24, 2016, 11:54:09 AM1/24/16
to vim/vim

Nikolai Pavlov wrote:

> Consider the following code:
>
> vim -u NONE --cmd 'let l=[]' --cmd 'call map(range(1024*1024), "extend(g:, {\"l\": [g:l]})")' --cmd 'echo jsonencode(l)'
>
> This crashes with stack full of json_encode_item() calls.
>
> One may be interested in code from neovim/neovim#3365 because it is
> not using recursion for dumping values.

The current implementation wasn't really made for large JSON files.
But if someone makes a patch it might get included.
Besides the recursiveness, using the growarray probably also is quite
inefficient. list_join_inner() has a better solution, but it takes
quite a bit of code.

--
hundred-and-one symptoms of being an internet addict:
36. You miss more than five meals a week downloading the latest games from
Apogee.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Nikolay Aleksandrovich Pavlov

unread,
Jan 24, 2016, 2:47:05 PM1/24/16
to vim_dev, reply+00b1d1986323cd5497d628b40081a1b0db57e6d...@reply.github.com, vim/vim
2016-01-24 19:53 GMT+03:00 Bram Moolenaar <vim-dev...@256bit.org>:

Nikolai Pavlov wrote:

> Consider the following code:
>
> vim -u NONE --cmd 'let l=[]' --cmd 'call map(range(1024*1024), "extend(g:, {\"l\": [g:l]})")' --cmd 'echo jsonencode(l)'
>
> This crashes with stack full of json_encode_item() calls.
>
> One may be interested in code from neovim/neovim#3365 because it is
> not using recursion for dumping values.

The current implementation wasn't really made for large JSON files.
But if someone makes a patch it might get included.
Besides the recursiveness, using the growarray probably also is quite
inefficient. list_join_inner() has a better solution, but it takes
quite a bit of code.

If one takes implementation from Neovim it is not a problem to make it first compute length and then dump. The problem is that json_encode_item should have at least stack overflow protection common for other recursive calls: I mean, a counter.

 


--
hundred-and-one symptoms of being an internet addict:
36. You miss more than five meals a week downloading the latest games from
Apogee.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///


Reply to this email directly or view it on GitHub.

--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Christian Brabandt

unread,
3:32 PM (8 hours ago) 3:32 PM
to vim/vim, vim-dev ML, Comment

Closed #588 as completed via abd2d7d.


Reply to this email directly, view it on GitHub.
You are receiving this because you commented.Message ID: <vim/vim/issue/588/issue_event/23864912243@github.com>

Reply all
Reply to author
Forward
0 new messages