diff options
author | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2020-10-04 18:33:21 -0400 |
---|---|---|
committer | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2020-10-05 18:18:14 -0400 |
commit | 8bd38863e61800ece97d88e4d1543d007a5055a6 (patch) | |
tree | 9f29309376a26d7f807fc9ee5ac423505ea985b0 | |
parent | da5bd45e5a8166119a396cdd8d6a39d309a944c5 (diff) | |
download | rneovim-8bd38863e61800ece97d88e4d1543d007a5055a6.tar.gz rneovim-8bd38863e61800ece97d88e4d1543d007a5055a6.tar.bz2 rneovim-8bd38863e61800ece97d88e4d1543d007a5055a6.zip |
vim-patch:8.1.1812: reading a truncted undo file hangs Vim
Problem: Reading a truncted undo file hangs Vim.
Solution: Check for reading EOF. (closes vim/vim#4769)
https://github.com/vim/vim/commit/fb06d767a8d76eead5391302fc88115d6e3879d8
-rw-r--r-- | src/nvim/testdir/test_undo.vim | 19 | ||||
-rw-r--r-- | src/nvim/undo.c | 7 |
2 files changed, 25 insertions, 1 deletions
diff --git a/src/nvim/testdir/test_undo.vim b/src/nvim/testdir/test_undo.vim index adcdcb1cd9..4a5825a08f 100644 --- a/src/nvim/testdir/test_undo.vim +++ b/src/nvim/testdir/test_undo.vim @@ -364,6 +364,25 @@ func Test_wundo_errors() bwipe! endfunc +" Check that reading a truncted undo file doesn't hang. +func Test_undofile_truncated() + throw 'skipped: TODO: ' + new + call setline(1, 'hello') + set ul=100 + wundo Xundofile + let contents = readfile('Xundofile', 'B') + + " try several sizes + for size in range(20, 500, 33) + call writefile(contents[0:size], 'Xundofile') + call assert_fails('rundo Xundofile', 'E825:') + endfor + + bwipe! +" call delete('Xundofile') +endfunc + func Test_rundo_errors() call assert_fails('rundo XfileDoesNotExist', 'E822:') diff --git a/src/nvim/undo.c b/src/nvim/undo.c index 903e57732f..6c5a6cdb46 100644 --- a/src/nvim/undo.c +++ b/src/nvim/undo.c @@ -878,7 +878,12 @@ static u_header_T *unserialize_uhp(bufinfo_T *bi, for (;; ) { int len = undo_read_byte(bi); - if (len == 0 || len == EOF) { + if (len == EOF) { + corruption_error("truncated", file_name); + u_free_uhp(uhp); + return NULL; + } + if (len == 0) { break; } int what = undo_read_byte(bi); |