]> granicus.if.org Git - vim/commitdiff
patch 8.2.4359: crash when repeatedly using :retab v8.2.4359
authorBram Moolenaar <Bram@vim.org>
Sat, 12 Feb 2022 15:42:18 +0000 (15:42 +0000)
committerBram Moolenaar <Bram@vim.org>
Sat, 12 Feb 2022 15:42:18 +0000 (15:42 +0000)
Problem:    crash when repeatedly using :retab.
Solution:   Bail out when the line is getting too long.

src/indent.c
src/testdir/test_retab.vim
src/version.c

index 9b137b0b425a942506e96cc75a4077e95a183c09..232c534973af6b94a2e2f725ca1b27c5d8e46518 100644 (file)
@@ -1750,6 +1750,11 @@ ex_retab(exarg_T *eap)
            if (ptr[col] == NUL)
                break;
            vcol += chartabsize(ptr + col, (colnr_T)vcol);
+           if (vcol >= MAXCOL)
+           {
+               emsg(_(e_resulting_text_too_long));
+               break;
+           }
            if (has_mbyte)
                col += (*mb_ptr2len)(ptr + col);
            else
index c7190aaa6699d9119de84a6ee79908f63622e39d..6133e8fb4abcafcf122eae223a7b403fdfda50b6 100644 (file)
@@ -70,6 +70,8 @@ func Test_retab()
   call assert_equal("    a       b        c    ",         Retab('!', 3))
   call assert_equal("    a       b        c    ",         Retab('',  5))
   call assert_equal("    a       b        c    ",         Retab('!', 5))
+
+  set tabstop& expandtab&
 endfunc
 
 func Test_retab_error()
@@ -80,4 +82,21 @@ func Test_retab_error()
   call assert_fails('ret 80000000000000000000', 'E475:')
 endfunc
 
+func Test_retab_endless()
+  new
+  call setline(1, "\t0\t")
+  let caught = 'no'
+  try
+    while 1
+      set ts=4000
+      retab 4
+    endwhile
+  catch /E1240/
+    let caught = 'yes'
+  endtry
+  bwipe!
+  set tabstop&
+endfunc
+
+
 " vim: shiftwidth=2 sts=2 expandtab
index 636757c3b6a61cc9cdc235f12d5a8275e00b32f6..aaafadf89de709ef80da6aa11646434b1b7c94a1 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4359,
 /**/
     4358,
 /**/