patch 9.1.1260: Hang when filtering buffer with NUL bytes

Commit: 
https://github.com/vim/vim/commit/53fed23cb7bd59d9400961b44c6c8dca0029c929
Author: zeertzjq <zeert...@outlook.com>
Date:   Sun Mar 30 15:01:56 2025 +0200

    patch 9.1.1260: Hang when filtering buffer with NUL bytes
    
    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 <zeert...@outlook.com>
    Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/src/os_unix.c b/src/os_unix.c
index 95b21d297..dc08408de 100644
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -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);
                    }
diff --git a/src/testdir/test_shell.vim b/src/testdir/test_shell.vim
index 2ac559676..667b158ce 100644
--- a/src/testdir/test_shell.vim
+++ b/src/testdir/test_shell.vim
@@ -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
+  " 
 is a NUL byte
+  let lines = ["aaa
bbb
ccc
ddd
eee", "fff
ggg
hhh
iii
jjj"]
+  call setline(1, lines)
+  %!cat
+  call assert_equal(lines, getline(1, '$'))
+
+  set shelltemp&
+  bwipe!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/version.c b/src/version.c
index e28782b3a..d0fdb6528 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1260,
 /**/
     1259,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/vim_dev/E1tysRq-007OnF-0W%40256bit.org.

Raspunde prin e-mail lui