From d0d9662ea15e672835a8fee430b1743bc9ca5213 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 4 May 2023 13:49:19 +0800 Subject: [PATCH] vim-patch:9.0.0240: crash when using ":mkspell" with an empty .dic file Problem: Crash when using ":mkspell" with an empty .dic file. Solution: Check for an empty word tree. https://github.com/vim/vim/commit/6669de1b235843968e88844ca6d3c8dec4b01a9e Co-authored-by: Bram Moolenaar (cherry picked from commit 7ddf235d7e71ee8373b11baa6a49381311f5d61d) --- src/nvim/spellfile.c | 5 ++++- test/old/testdir/test_spellfile.vim | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index d553910ece..e66b9027f7 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -4971,9 +4971,12 @@ static int sug_filltree(spellinfo_T *spin, slang_T *slang) spin->si_sugtree = true; // Go through the whole case-folded tree, soundfold each word and put it - // in the trie. + // in the trie. Bail out if the tree is empty. byts = slang->sl_fbyts; idxs = slang->sl_fidxs; + if (byts == NULL || idxs == NULL) { + return FAIL; + } arridx[0] = 0; curi[0] = 1; diff --git a/test/old/testdir/test_spellfile.vim b/test/old/testdir/test_spellfile.vim index 639ebc1c34..4d2a6cf35f 100644 --- a/test/old/testdir/test_spellfile.vim +++ b/test/old/testdir/test_spellfile.vim @@ -1071,4 +1071,16 @@ func Test_spellfile_allow_at_character() call delete('Xtest', 'rf') endfunc +" this was using a NULL pointer +func Test_mkspell_empty_dic() + call writefile(['1'], 'XtestEmpty.dic') + call writefile(['SOFOFROM abcd', 'SOFOTO ABCD', 'SAL CIA X'], 'XtestEmpty.aff') + mkspell! XtestEmpty.spl XtestEmpty + + call delete('XtestEmpty.dic') + call delete('XtestEmpty.aff') + call delete('XtestEmpty.spl') +endfunc + + " vim: shiftwidth=2 sts=2 expandtab