Blame SOURCES/0001-patch-8.2.4919-can-add-invalid-bytes-with-spellgood.patch

af580a
diff -up vim82/src/errors.h.cve1621 vim82/src/errors.h
af580a
--- vim82/src/errors.h.cve1621	2022-05-24 13:36:23.883370040 +0200
af580a
+++ vim82/src/errors.h	2022-05-24 13:36:47.665487703 +0200
af580a
@@ -387,3 +387,7 @@ EXTERN char e_resulting_text_too_long[]
af580a
 EXTERN char e_string_or_function_required_for_arrow_parens_expr[]
af580a
 	INIT(= N_("E1275: String or function required for ->(expr)"));
af580a
 #endif
af580a
+#ifdef FEAT_SPELL
af580a
+EXTERN char e_illegal_character_in_word[]
af580a
+	INIT(= N_("E1280: Illegal character in word"));
af580a
+#endif
af580a
diff -up vim82/src/mbyte.c.cve1621 vim82/src/mbyte.c
af580a
--- vim82/src/mbyte.c.cve1621	2021-03-22 10:02:42.000000000 +0100
af580a
+++ vim82/src/mbyte.c	2022-05-24 13:36:23.884370045 +0200
af580a
@@ -4181,7 +4181,7 @@ theend:
af580a
     convert_setup(&vimconv, NULL, NULL);
af580a
 }
af580a
 
af580a
-#if defined(FEAT_GUI_GTK) || defined(PROTO)
af580a
+#if defined(FEAT_GUI_GTK) || defined(FEAT_SPELL) || defined(PROTO)
af580a
 /*
af580a
  * Return TRUE if string "s" is a valid utf-8 string.
af580a
  * When "end" is NULL stop at the first NUL.
af580a
diff -up vim82/src/spellfile.c.cve1621 vim82/src/spellfile.c
af580a
--- vim82/src/spellfile.c.cve1621	2021-03-22 10:02:42.000000000 +0100
af580a
+++ vim82/src/spellfile.c	2022-05-24 13:36:23.885370049 +0200
af580a
@@ -4391,6 +4391,10 @@ store_word(
af580a
     int		res = OK;
af580a
     char_u	*p;
af580a
 
af580a
+    // Avoid adding illegal bytes to the word tree.
af580a
+    if (enc_utf8 && !utf_valid_string(word, NULL))
af580a
+	return FAIL;
af580a
+
af580a
     (void)spell_casefold(word, len, foldword, MAXWLEN);
af580a
     for (p = pfxlist; res == OK; ++p)
af580a
     {
af580a
@@ -6191,6 +6195,12 @@ spell_add_word(
af580a
     int		i;
af580a
     char_u	*spf;
af580a
 
af580a
+    if (enc_utf8 && !utf_valid_string(word, NULL))
af580a
+    {
af580a
+	emsg(_(e_illegal_character_in_word));
af580a
+	return;
af580a
+    }
af580a
+
af580a
     if (idx == 0)	    // use internal wordlist
af580a
     {
af580a
 	if (int_wordlist == NULL)