]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1260: Hang when filtering buffer with NUL bytes v9.1.1260
authorzeertzjq <zeertzjq@outlook.com>
Sun, 30 Mar 2025 13:01:56 +0000 (15:01 +0200)
committerChristian Brabandt <cb@256bit.org>
Sun, 30 Mar 2025 13:01:56 +0000 (15:01 +0200)
Problem:  Hang when filtering buffer with NUL bytes (after 9.1.1050).
Solution: Don't subtract "written" from "lplen" repeatedly (zeertzjq).

related: neovim/neovim#33173
closes: #17011

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

index 95b21d297dc4f7625db2017949319ea5427496a7..dc08408de686a7fe0c469fdd8af6b1dbe74b9dee 100644 (file)
@@ -5260,14 +5260,13 @@ mch_call_shell_fork(
                    else if (wpid == 0) // child
                    {
                        linenr_T    lnum = curbuf->b_op_start.lnum;
-                       int         written = 0;
+                       size_t      written = 0;
                        char_u      *lp = ml_get(lnum);
                        size_t      lplen = (size_t)ml_get_len(lnum);
 
                        close(fromshell_fd);
                        for (;;)
                        {
-                           lplen -= written;
                            if (lplen == 0)
                                len = 0;
                            else if (lp[written] == NL)
@@ -5278,10 +5277,10 @@ mch_call_shell_fork(
                                char_u  *s = vim_strchr(lp + written, NL);
 
                                len = write(toshell_fd, (char *)lp + written,
-                                          s == NULL ? lplen
+                                          s == NULL ? lplen - written
                                              : (size_t)(s - (lp + written)));
                            }
-                           if (len == (int)lplen)
+                           if (len == (int)(lplen - written))
                            {
                                // Finished a line, add a NL, unless this line
                                // should not have one.
@@ -5305,7 +5304,7 @@ mch_call_shell_fork(
                                written = 0;
                            }
                            else if (len > 0)
-                               written += len;
+                               written += (size_t)len;
                        }
                        _exit(0);
                    }
index 2ac559676f07eeeaa95cf782b5756804fc82e06f..667b158ce8fd57bd2c84f0b2776a71a6540bc604 100644 (file)
@@ -299,4 +299,18 @@ func Test_shell_no_prevcmd()
   call delete('Xtestdone')
 endfunc
 
+func Test_shell_filter_buffer_with_nul_bytes()
+  CheckUnix
+  new
+  set noshelltemp
+  " \n is a NUL byte
+  let lines = ["aaa\nbbb\nccc\nddd\neee", "fff\nggg\nhhh\niii\njjj"]
+  call setline(1, lines)
+  %!cat
+  call assert_equal(lines, getline(1, '$'))
+
+  set shelltemp&
+  bwipe!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index e28782b3a47ebf824da08faa858c7a52cd798e9e..d0fdb652897e2ab6075809eb5b85f07f172d7f6b 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1260,
 /**/
     1259,
 /**/