]> granicus.if.org Git - vim/commitdiff
patch 8.2.3484: crash when going through spell suggestions v8.2.3484
authorBram Moolenaar <Bram@vim.org>
Wed, 6 Oct 2021 12:41:07 +0000 (13:41 +0100)
committerBram Moolenaar <Bram@vim.org>
Wed, 6 Oct 2021 12:41:07 +0000 (13:41 +0100)
Problem:    Crash when going through spell suggestions.
Solution:   Limit the text length for finding suggestions to the original
            length.  Do not update buffers when exiting. (closes #8965)

src/clipboard.c
src/spellsuggest.c
src/testdir/test_spell_utf8.vim
src/version.c

index b1da99bcbe4460fbe5ca1b94c5be1ab6c86aa422..c0c21aeb6d06adccbf57e9a01e878a1ce19558df 100644 (file)
@@ -199,7 +199,8 @@ clip_lose_selection(Clipboard_T *cbd)
                                            || get_real_state() == SELECTMODE)
                && (cbd == &clip_star ?
                                clip_isautosel_star() : clip_isautosel_plus())
-               && HL_ATTR(HLF_V) != HL_ATTR(HLF_VNC))
+               && HL_ATTR(HLF_V) != HL_ATTR(HLF_VNC)
+               && !exiting)
        {
            update_curbuf(INVERTED_ALL);
            setcursor();
index 2951eea2eaa2641585d66ca46c7b63fca1f42031..a6dbc78a46ab9db67d598385d44c489ebbec9ee0 100644 (file)
@@ -1178,6 +1178,11 @@ suggest_try_change(suginfo_T *su)
     p = su->su_badptr + su->su_badlen;
     (void)spell_casefold(curwin, p, (int)STRLEN(p), fword + n, MAXWLEN - n);
 
+    // Make sure the resulting text is not longer than the original text.
+    n = (int)STRLEN(su->su_badptr);
+    if (n < MAXWLEN)
+       fword[n] = NUL;
+
     for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi)
     {
        lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);
index 1f561e46a97b32826adc98e63aa9727804c8edec..79dc3e4a4a620041e204bdfd70dfc4396673c022 100644 (file)
@@ -765,4 +765,20 @@ func Test_spellfile_value()
   set spellfile=Xdir/Xtest.utf-8.add,Xtest_other.add
 endfunc
 
+func Test_no_crash_with_weird_text()
+  new
+  let lines =<< trim END
+      r<sfile>
+      \80
+
+
+      \80
+  END
+  call setline(1, lines)
+  exe "%norm \<C-v>ez=>\<C-v>wzG"
+
+  bwipe!
+endfunc
+
+
 " vim: shiftwidth=2 sts=2 expandtab
index 03b7022ad3c5a7e361ef77bdb7253acd2cfcfb8b..62c7f8f111ce2a37ab798286d9340ef822b1b30a 100644 (file)
@@ -757,6 +757,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3484,
 /**/
     3483,
 /**/