Blame SOURCES/0001-patch-8.2.4247-stack-corruption-when-looking-for-spe.patch

da4393
diff --git a/src/spellsuggest.c b/src/spellsuggest.c
da4393
index 3de9ff2..5462583 100644
da4393
--- a/src/spellsuggest.c
da4393
+++ b/src/spellsuggest.c
da4393
@@ -1200,7 +1200,7 @@ suggest_try_change(suginfo_T *su)
da4393
 
da4393
 // Check the maximum score, if we go over it we won't try this change.
da4393
 #define TRY_DEEPER(su, stack, depth, add) \
da4393
-		(stack[depth].ts_score + (add) < su->su_maxscore)
da4393
+       (depth < MAXWLEN - 1 && stack[depth].ts_score + (add) < su->su_maxscore)
da4393
 
da4393
 /*
da4393
  * Try finding suggestions by adding/removing/swapping letters.
da4393
@@ -1272,6 +1272,9 @@ suggest_trie_walk(
da4393
     char_u	changename[MAXWLEN][80];
da4393
 #endif
da4393
     int		breakcheckcount = 1000;
da4393
+#ifdef FEAT_RELTIME
da4393
+    proftime_T	time_limit;
da4393
+#endif
da4393
     int		compound_ok;
da4393
 
da4393
     // Go through the whole case-fold tree, try changes at each node.
da4393
@@ -1316,6 +1319,11 @@ suggest_trie_walk(
da4393
 	    sp->ts_state = STATE_START;
da4393
 	}
da4393
     }
da4393
+#ifdef FEAT_RELTIME
da4393
+    // The loop may take an indefinite amount of time. Break out after five
da4393
+    // sectonds. TODO: add an option for the time limit.
da4393
+    profile_setlimit(5000, &time_limit);
da4393
+#endif
da4393
 
da4393
     // Loop to find all suggestions.  At each round we either:
da4393
     // - For the current state try one operation, advance "ts_curi",
da4393
@@ -1350,7 +1358,8 @@ suggest_trie_walk(
da4393
 
da4393
 		// At end of a prefix or at start of prefixtree: check for
da4393
 		// following word.
da4393
-		if (byts[arridx] == 0 || n == (int)STATE_NOPREFIX)
da4393
+		if (depth < MAXWLEN - 1
da4393
+			    && (byts[arridx] == 0 || n == (int)STATE_NOPREFIX))
da4393
 		{
da4393
 		    // Set su->su_badflags to the caps type at this position.
da4393
 		    // Use the caps type until here for the prefix itself.
da4393
@@ -2644,6 +2653,10 @@ suggest_trie_walk(
da4393
 	    {
da4393
 		ui_breakcheck();
da4393
 		breakcheckcount = 1000;
da4393
+#ifdef FEAT_RELTIME
da4393
+		if (profile_passed_limit(&time_limit))
da4393
+		    got_int = TRUE;
da4393
+#endif
da4393
 	    }
da4393
 	}
da4393
     }
da4393
diff --git a/src/testdir/test_spell.vim b/src/testdir/test_spell.vim
da4393
index a3a9621..35035a2 100644
da4393
--- a/src/testdir/test_spell.vim
da4393
+++ b/src/testdir/test_spell.vim
da4393
@@ -768,6 +768,14 @@ func Test_spell_long_word()
da4393
   set nospell
da4393
 endfunc
da4393
 
da4393
+func Test_spellsuggest_too_deep()
da4393
+  " This was incrementing "depth" over MAXWLEN.
da4393
+  new
da4393
+  norm ?s000G00ý000000000000
da4393
+  sil norm ..vzG................vvzG0     v z=
da4393
+  bwipe!
da4393
+endfunc
da4393
+
da4393
 func LoadAffAndDic(aff_contents, dic_contents)
da4393
   set enc=latin1
da4393
   set spellfile=