diff --git a/runtime/autoload/tar.vim b/runtime/autoload/tar.vim index 774623c107..b2187a7ebc 100644 --- a/runtime/autoload/tar.vim +++ b/runtime/autoload/tar.vim @@ -19,6 +19,7 @@ " 2025 Jul 13 by Vim Project: warn with path traversal attacks " 2026 Feb 06 by Vim Project: consider 'nowrapscan' (#19333) " 2026 Feb 07 by Vim Project: make the path traversal detection more robust (#19341) +" 2026 Apr 06 by Vim Project: fix bugs with lz4 support (#19925) " " Contains many ideas from Michael Toren's " @@ -703,7 +704,9 @@ fun! tar#Extract() endif elseif filereadable(tarbase.".tlz4") - let extractcmd= substitute(extractcmd,"-","-I lz4","") + if has("linux") + let extractcmd= substitute(extractcmd,"-","-I lz4 -","") + endif call system(extractcmd." ".shellescape(tarbase).".tlz4 ".shellescape(fname)) if v:shell_error != 0 call s:Msg('tar#Extract', 'error', $"{extractcmd} {tarbase}.tlz4 {fname}: failed!") @@ -712,8 +715,10 @@ fun! tar#Extract() endif elseif filereadable(tarbase.".tar.lz4") - let extractcmd= substitute(extractcmd,"-","-I lz4","") - call system(extractcmd." ".shellescape(tarbase).".tar.lz4".shellescape(fname)) + if has("linux") + let extractcmd= substitute(extractcmd,"-","-I lz4 -","") + endif + call system(extractcmd." ".shellescape(tarbase).".tar.lz4 ".shellescape(fname)) if v:shell_error != 0 call s:Msg('tar#Extract', 'error', $"{extractcmd} {tarbase}.tar.lz4 {fname}: failed!") else diff --git a/test/old/testdir/test_plugin_tar.vim b/test/old/testdir/test_plugin_tar.vim index 3bc3db6053..719487bda4 100644 --- a/test/old/testdir/test_plugin_tar.vim +++ b/test/old/testdir/test_plugin_tar.vim @@ -150,3 +150,57 @@ func Test_tar_path_traversal_with_nowrapscan() bw! endfunc + +func Test_tar_lz4_extract() + CheckExecutable lz4 + + call delete('X.txt') + call delete('Xarchive.tar') + call delete('Xarchive.tar.lz4') + call writefile(['hello'], 'X.txt') + call system('tar -cf Xarchive.tar X.txt') + call assert_equal(0, v:shell_error) + + call system('lz4 -z Xarchive.tar Xarchive.tar.lz4') + call assert_equal(0, v:shell_error) + + call delete('X.txt') + call delete('Xarchive.tar') + defer delete('Xarchive.tar.lz4') + + e Xarchive.tar.lz4 + call assert_match('X.txt', getline(5)) + :5 + normal x + call assert_true(filereadable('X.txt')) + call assert_equal(['hello'], readfile('X.txt')) + call delete('X.txt') + bw! +endfunc + +func Test_tlz4_extract() + CheckExecutable lz4 + + call delete('X.txt') + call delete('Xarchive.tar') + call delete('Xarchive.tlz4') + call writefile(['goodbye'], 'X.txt') + call system('tar -cf Xarchive.tar X.txt') + call assert_equal(0, v:shell_error) + + call system('lz4 -z Xarchive.tar Xarchive.tlz4') + call assert_equal(0, v:shell_error) + + call delete('X.txt') + call delete('Xarchive.tar') + defer delete('Xarchive.tlz4') + + e Xarchive.tlz4 + call assert_match('X.txt', getline(5)) + :5 + normal x + call assert_true(filereadable('X.txt')) + call assert_equal(['goodbye'], readfile('X.txt')) + call delete('X.txt') + bw! +endfunc