summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2019-08-04 18:55:35 +0200
committerBram Moolenaar <Bram@vim.org>2019-08-04 18:55:35 +0200
commitfb06d767a8d76eead5391302fc88115d6e3879d8 (patch)
tree49fdbffa0db7d3623e78d89c4e4c36a968b9b097
parentc363fe1599655232e8bd6e279fbf70d4c1b7baf6 (diff)
patch 8.1.1812: reading a truncted undo file hangs Vimv8.1.1812
Problem: Reading a truncted undo file hangs Vim. Solution: Check for reading EOF. (closes #4769)
-rw-r--r--src/testdir/test_undo.vim18
-rw-r--r--src/undo.c6
-rw-r--r--src/version.c2
3 files changed, 26 insertions, 0 deletions
diff --git a/src/testdir/test_undo.vim b/src/testdir/test_undo.vim
index 1440660adf..5154b20b3b 100644
--- a/src/testdir/test_undo.vim
+++ b/src/testdir/test_undo.vim
@@ -335,6 +335,24 @@ func Test_undofile_earlier()
call delete('Xundofile')
endfunc
+" Check that reading a truncted undo file doesn't hang.
+func Test_undofile_truncated()
+ 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
+
" Test for undo working properly when executing commands from a register.
" Also test this in an empty buffer.
func Test_cmd_in_reg_undo()
diff --git a/src/undo.c b/src/undo.c
index 4a4a33cc1b..a23c2638f4 100644
--- a/src/undo.c
+++ b/src/undo.c
@@ -1317,6 +1317,12 @@ unserialize_uhp(bufinfo_T *bi, char_u *file_name)
int len = undo_read_byte(bi);
int what;
+ if (len == EOF)
+ {
+ corruption_error("truncated", file_name);
+ u_free_uhp(uhp);
+ return NULL;
+ }
if (len == 0)
break;
what = undo_read_byte(bi);
diff --git a/src/version.c b/src/version.c
index 32759b1709..71a14ad66b 100644
--- a/src/version.c
+++ b/src/version.c
@@ -774,6 +774,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1812,
+/**/
1811,
/**/
1810,