Commit: patch 9.1.1260: Hang when filtering buffer with NUL bytes

1 view
Skip to first unread message

Christian Brabandt

unread,
Mar 30, 2025, 9:11:44 AM3/30/25
to vim...@googlegroups.com
patch 9.1.1260: Hang when filtering buffer with NUL bytes

Commit: https://github.com/vim/vim/commit/53fed23cb7bd59d9400961b44c6c8dca0029c929
Author: zeertzjq <zeer...@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 <zeer...@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,
/**/
Reply all
Reply to author
Forward
0 new messages