From: zeertzjq Date: Sun, 30 Mar 2025 13:01:56 +0000 (+0200) Subject: patch 9.1.1260: Hang when filtering buffer with NUL bytes X-Git-Tag: v9.1.1260^0 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=53fed23cb7bd59d9400961b44c6c8dca0029c929;p=thirdparty%2Fvim.git 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 Signed-off-by: Christian Brabandt --- diff --git a/src/os_unix.c b/src/os_unix.c index 95b21d297d..dc08408de6 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 2ac559676f..667b158ce8 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 + " \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 diff --git a/src/version.c b/src/version.c index e28782b3a4..d0fdb65289 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, /**/