]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.2112: long statusline may crash if using singlebyte encoding v9.1.2112
authorzeertzjq <zeertzjq@outlook.com>
Wed, 28 Jan 2026 21:36:51 +0000 (21:36 +0000)
committerChristian Brabandt <cb@256bit.org>
Wed, 28 Jan 2026 21:42:40 +0000 (21:42 +0000)
Problem:  long statusline may crash if using singlebyte encoding
          (fizz-is-on-the-way)
Solution: Drop the non-mbyte codepath and always use the mbyte code
          (zeertzjq)

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/buffer.c
src/testdir/test_statusline.vim
src/version.c

index 62f236ff0b6b2f4a14fe7c8fa129512209a15772..86b784023058c2bb41bf50b3c284fa537a164d38 100644 (file)
@@ -5264,17 +5264,12 @@ build_stl_str_hl(
        {
            char_u  *end = out + outputlen;
 
-           if (has_mbyte)
+           n = 0;
+           while (width >= maxwidth)
            {
-               n = 0;
-               while (width >= maxwidth)
-               {
-                   width -= ptr2cells(s + n);
-                   n += (*mb_ptr2len)(s + n);
-               }
+               width -= ptr2cells(s + n);
+               n += (*mb_ptr2len)(s + n);
            }
-           else
-               n = width - maxwidth + 1;
            p = s + n;
            mch_memmove(s + 1, p, (size_t)(end - p) + 1);       // +1 for NUL
            end -= (size_t)(p - (s + 1));
index 4899bd0a05fb79f9c86561120c060ac36b34370f..174c1a4754abfd4be3fa3cc3713f4a996f6e4990 100644 (file)
@@ -707,4 +707,18 @@ func Test_statusline_in_sandbox()
   delfunc Check_statusline_in_sandbox
 endfunc
 
+" This used to call memmove with a negative size and crash Vim
+func Test_statusline_singlebyte_negative()
+  let [_columns, _ls, _stl, _enc]  = [&columns, &ls, &stl, &enc]
+  set encoding=latin1
+  set laststatus=2 columns=15
+  setl stl=%#ErrorMsg#abcdtàØ\7f?}}o@`s`ÿæ\ 3Cú\x\ 5E%#Normal#
+  vsp
+  setl stl=%#ErrorMsg#abcdtàØ\7f?}}o@`s`ÿæ\ 3Cú\x\ 5E%#Normal#
+  redraw!
+  redrawstatus
+  bw!
+  let [&columns, &ls, &stl, &enc] = [_columns, _ls, _stl, _enc]
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index de16a77a482f4c0b623976eed8d4e623d8a1a6a2..f989c2ae4ce39f0662e99a1f124d516d365fcec9 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2112,
 /**/
     2111,
 /**/