diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index 143f7f20ca..466aaf4578 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -1339,8 +1339,6 @@ static int read_sofo_section(FILE *fd, slang_T *slang) int cnt; int res; - slang->sl_sofo = true; - // char *from = read_cnt_string(fd, 2, &cnt); if (cnt < 0) { @@ -1552,6 +1550,7 @@ static int set_sofo(slang_T *lp, const char *from, const char *to) ga_grow(gap, 256); memset(gap->ga_data, 0, sizeof(int *) * 256); gap->ga_len = 256; + lp->sl_sofo = true; // First count the number of items for each list. Temporarily use // sl_sal_first[] for this. diff --git a/test/old/testdir/test_spellfile.vim b/test/old/testdir/test_spellfile.vim index 3bf19cd183..0938e4cfd1 100644 --- a/test/old/testdir/test_spellfile.vim +++ b/test/old/testdir/test_spellfile.vim @@ -1326,4 +1326,31 @@ func Test_soundfold_overflow() let &enc = _enc endfunc +func Test_spell_sal_sofo_truncated() + call mkdir('Xspelldir/spell', 'pR') + + " "VIMspell" + " SN_SAL(5) flags=0 len=7 : <0><1>a<1>a + " SN_SOFO(6) flags=0 len=0 : truncated, no body -> EOF in reader + " (28 bytes total) + let bytes = 0z56494d7370656c6c.3205000000000700.000101610161060000.000000 + call writefile(bytes, 'Xspelldir/spell/Xx.utf-8.spl', 'b') + + let save_rtp = &rtp + set rtp=./Xspelldir + try + set spelllang=Xx + silent! set spell + catch + " an error message is fine; a crash is not + endtry + + " Reaching this point means Vim did not crash on the crafted file. + call assert_true(v:true) + + set nospell + set spelllang& + let &rtp = save_rtp +endfunc + " vim: shiftwidth=2 sts=2 expandtab