crw icon indicating copy to clipboard operation
crw copied to clipboard

Windows: first-run binary download fails to extract when GNU tar (Git for Windows) shadows bsdtar

Open magicprinc opened this issue 4 weeks ago • 2 comments

Summary

On Windows, the first-run download of the native binary fails to extract whenever the tar resolved from PATH is GNU tar (the one Git for Windows puts in C:\Program Files\Git\usr\bin) instead of Windows' bundled bsdtar. The launcher passes an absolute C:\... path to tar, which GNU tar interprets as a remote host, and GNU tar cannot read .zip archives at all.

Result: crw-mcp is unusable on a clean machine until the binary is placed by hand.

Environment

  • Windows 11 x64, Node v26.13.0
  • crw-mcp 0.42.1 (both npx -y crw-mcp and a global npm install behave the same)
  • Git for Windows installed; PATH order puts ${GIT}\usr\bin before C:\Windows\system32, so tar resolves to GNU tar 1.35
  • C:\Windows\System32\tar.exe (bsdtar) is present, just shadowed

Reproduction

With no cached binary (%LOCALAPPDATA%\crw-mcp\v0.42.1\crw-mcp.exe absent), just run the server:

node "$(npm root -g)/crw-mcp/bin/crw-mcp.js" --version

Actual behaviour

crw-mcp: downloading crw-mcp-win32-x64.zip (v0.42.1)...
tar: Cannot connect to C: resolve failed
crw-mcp: could not locate or download the win32-x64 binary.
  failed to extract crw-mcp-win32-x64.zip (tar exit 128)
  Manual install: download crw-mcp-win32-x64.zip from
  https://github.com/fastcrw/crw/releases/tag/v0.42.1, check it against SHA256SUMS,
  and put crw-mcp.exe in C:\Users\<user>\AppData\Local\crw-mcp\v0.42.1
  (or set CRW_MCP_BINARY=/path/to/crw-mcp.exe). HTTPS_PROXY is honoured.

Expected: binary extracted to the cache dir and crw-mcp 0.42.1 printed.

Root cause

In bin/crw-mcp.js (fromDownload):

const tarArgs = plat.asset.endsWith(".zip")
  ? ["-xf", archive, "-C", stage]
  : ["-xzf", archive, "-C", stage];
const x = spawnSync("tar", tarArgs, { stdio: "inherit" });

Two Windows-specific problems combine:

  1. tar is resolved through PATH. With Git for Windows installed, that is GNU tar, which parses C:\Users\...\archive.zip as host:path and tries to connect to the host C: → tar: Cannot connect to C: resolve failed (exit 128).
  2. The .zip branch relies on bsdtar's auto-detection. GNU tar cannot read ZIP at all, so even a relative path only changes the error (This does not look like a tar archive), it does not fix it.

Same archive, same arguments, only a different tar:

$ C:\Windows\System32\tar.exe -xf 'C:\TMP\tartest\crw-mcp-win32-x64.zip' -C 'C:\TMP\tartest'
# -> crw-mcp.exe, 28 MB, OK

$ C:\Program Files\Git\usr\bin\tar.exe -xf 'C:\TMP\tartest\crw-mcp-win32-x64.zip' -C 'C:\TMP\tartest'
tar: Cannot connect to C: resolve failed

Suggested fix

On win32, don't rely on PATH for ZIP extraction:

  1. Prefer the system bsdtar explicitly: path.join(process.env.SystemRoot, "System32", "tar.exe") (present on Windows 10 17063+), falling back to PATH only if that file is missing.
  2. Or extract .zip without an external binary, e.g. PowerShell -NoProfile -Command Expand-Archive -Force -LiteralPath ... — powershell.exe is always available on Windows.
  3. Passing a relative archive name with cwd: stage is worth doing anyway (it makes GNU tar usable for the .tar.gz platforms), but it is not sufficient for .zip on Windows.

Also worth adding to the failure message: the currently resolved tar path and tar --version first line, so this is diagnosable without digging into PATH.

Workaround (what I did)

Download the matching release asset, verify it against SHA256SUMS, and drop crw-mcp.exe into %LOCALAPPDATA%\crw-mcp\v<version>\ (or point CRW_MCP_BINARY at it). Everything else works normally afterwards.

Found while working around #702 (related only in that both are Windows/local-Chrome papercuts, different root causes).

magicprinc avatar Nov 08 '26 12:11 magicprinc

thanks, great diagnosis. confirmed: the launcher spawns whatever tar is first on PATH with an absolute archive path, so git for windows' gnu tar reads C: as a host and can't open the zip anyway. fixing it to use the system bsdtar on windows and a relative archive name everywhere. will link the pr here.

us avatar Nov 09 '26 02:11 us

fixed in #704: on windows the launcher now extracts with the system bsdtar (%SystemRoot%\System32\tar.exe) and passes the archive by its bare name, and a failed extraction says which tar ran. it ships with the next crw-mcp release; until then your manual install keeps working. thanks again for tracking it down.

us avatar Nov 09 '26 02:11 us