]> granicus.if.org Git - vim/commitdiff
patch 8.2.4919: can add invalid bytes with :spellgood v8.2.4919
authorBram Moolenaar <Bram@vim.org>
Sun, 8 May 2022 21:32:58 +0000 (22:32 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 8 May 2022 21:32:58 +0000 (22:32 +0100)
Problem:    Can add invalid bytes with :spellgood.
Solution:   Check for a valid word string.

src/errors.h
src/mbyte.c
src/spellfile.c
src/testdir/test_spell_utf8.vim
src/version.c

index 1e9be6c3e350ecb8c8b4058d4ed7516c528f1c58..087f49753df3c2458bfd63bf009f4cee067e892f 100644 (file)
@@ -3273,3 +3273,7 @@ EXTERN char e_stray_closing_curly_str[]
 EXTERN char e_missing_close_curly_str[]
        INIT(= N_("E1279: Missing '}': %s"));
 #endif
+#ifdef FEAT_SPELL
+EXTERN char e_illegal_character_in_word[]
+       INIT(= N_("E1280: Illegal character in word"));
+#endif
index 2b7f9991ae147747023b68d3419bf86366397400..a01a05140207477974bc52573a8b10d94970b97c 100644 (file)
@@ -4226,7 +4226,7 @@ theend:
     convert_setup(&vimconv, NULL, NULL);
 }
 
-#if defined(FEAT_GUI_GTK) || defined(PROTO)
+#if defined(FEAT_GUI_GTK) || defined(FEAT_SPELL) || defined(PROTO)
 /*
  * Return TRUE if string "s" is a valid utf-8 string.
  * When "end" is NULL stop at the first NUL.
index 22cf82da0872e58843b0884007a71ef69538da13..f0d6d96a47f02c92c1615d428cb767c31c3e9282 100644 (file)
@@ -4390,6 +4390,10 @@ store_word(
     int                res = OK;
     char_u     *p;
 
+    // Avoid adding illegal bytes to the word tree.
+    if (enc_utf8 && !utf_valid_string(word, NULL))
+       return FAIL;
+
     (void)spell_casefold(curwin, word, len, foldword, MAXWLEN);
     for (p = pfxlist; res == OK; ++p)
     {
@@ -6190,6 +6194,12 @@ spell_add_word(
     int                i;
     char_u     *spf;
 
+    if (enc_utf8 && !utf_valid_string(word, NULL))
+    {
+       emsg(_(e_illegal_character_in_word));
+       return;
+    }
+
     if (idx == 0)          // use internal wordlist
     {
        if (int_wordlist == NULL)
index 79dc3e4a4a620041e204bdfd70dfc4396673c022..17fa23555818baad0819a0c455fd833c3e7dc3b4 100644 (file)
@@ -780,5 +780,10 @@ func Test_no_crash_with_weird_text()
   bwipe!
 endfunc
 
+" Invalid bytes may cause trouble when creating the word list.
+func Test_check_for_valid_word()
+  call assert_fails("spellgood! 0\ 2\xac", 'E1280:')
+endfunc
+
 
 " vim: shiftwidth=2 sts=2 expandtab
index f949dd6d7ed0917fb2e771eb975955bff4c5fdaa..c4f5655bf6c2cbfe23aa65e3e39765c2819bcd1b 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4919,
 /**/
     4918,
 /**/