The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(install): stage pinned git without tar/bzip2 (PortableGit SFX)
finn7636d9ae2da6f18
diff --git a/pm/lock.json b/pm/lock.jsonindex 5e60c845287..6a40a170477 100644--- a/pm/lock.json+++ b/pm/lock.json@@ -190,12 +190,12 @@"git": {"artifacts": {"win32-arm64": {- "sha256": "4015f05a68bd2bcf3cc6c426e8d44b65d670fbb879225bb7b7c347cfc3a2758a",- "url": "https://github.com/git-for-windows/git/releases/download/v2.53.0.windows.3/Git-2.53.0.3-arm64.tar.bz2"+ "sha256": "0db54010054c01f35501cf69e1e32d3710138ecb934d188bd77093afed24300e",+ "url": "https://github.com/git-for-windows/git/releases/download/v2.53.0.windows.3/PortableGit-2.53.0.3-arm64.7z.exe"},"win32-x64": {- "sha256": "1661f02e85a7901ad7920e2a358ee3772ed9066b00d8590bf2d9046ef10aa8b2",- "url": "https://github.com/git-for-windows/git/releases/download/v2.53.0.windows.3/Git-2.53.0.3-64-bit.tar.bz2"+ "sha256": "b365da794b1d2225eb24d5f5e09ef7792cfd5fa26c3a3586210280c80dff3a2a",+ "url": "https://github.com/git-for-windows/git/releases/download/v2.53.0.windows.3/PortableGit-2.53.0.3-64-bit.7z.exe"}},"version": "2.53.0+3"diff --git a/pm/packages.py b/pm/packages.pyindex 0938012788a..d2fc2a79c6a 100644--- a/pm/packages.py+++ b/pm/packages.py@@ -617,8 +617,10 @@ class Npm(BinaryPackage):@registerclass Git(BinaryPackage):"""Windows only: Git for Windows carries the bash.exe contract. POSIX- uses the system git — a deliberate gap, not an oversight. The tar.bz2- release asset extracts with stdlib tarfile: no self-extractor, no GUI."""+ uses the system git - a deliberate gap, not an oversight. The pinned+ PortableGit asset is a self-extracting 7z: it carries its own extractor,+ so no tar bzip2 filter and no bzip2.exe are needed on the machine+ (#122512), and no GUI."""name = "git"optional = True@@ -638,7 +640,7 @@ class Git(BinaryPackage):arch = "arm64" if target.endswith("arm64") else "64-bit"return (f"https://github.com/git-for-windows/git/releases/download/"- f"v{tag}.windows.{build}/Git-{tag}.{build}-{arch}.tar.bz2"+ f"v{tag}.windows.{build}/PortableGit-{tag}.{build}-{arch}.7z.exe")def latest_versions(self, target: str, locked=None) -> list[str]:@@ -651,9 +653,23 @@ class Git(BinaryPackage):return outdef unpack(self, archive: Path, staged: Path, target: str) -> None:- from pm.store import extract_tar+ import subprocess- extract_tar(archive, staged, git_msys=True)+ # The self-extracting 7z carries its own extractor: running it needs+ # no tar bzip2 filter and no bzip2.exe (#122512). Download bytes are+ # sha256-pinned before this runs, same as every other artifact.+ staged.mkdir(parents=True, exist_ok=True)+ proc = subprocess.run(+ [str(archive), f"-o{staged}", "-y"],+ capture_output=True,+ text=True,+ timeout=600,+ )+ if proc.returncode:+ raise RuntimeError(+ f"PortableGit self-extractor failed ({proc.returncode}): "+ f"{(proc.stderr or proc.stdout).strip()[-500:]}"+ )def env(self, entry: Path, target: str) -> dict:return {"PATH": [str(entry / "cmd"), str(entry / "usr" / "bin")]}diff --git a/pm/store.py b/pm/store.pyindex f52e76e6a40..2cb6dff48c3 100644--- a/pm/store.py+++ b/pm/store.py@@ -210,13 +210,10 @@ def _tar_filter(member, dest: str):return member.replace(deep=False, uid=None, gid=None, uname=None, gname=None, mode=None)return tarfile.data_filter(member, dest)-def extract_tar(archive: Path | IO[bytes], dest: Path, *, git_msys: bool = False) -> None:+def extract_tar(archive: Path | IO[bytes], dest: Path) -> None:"""Extract a tarball (a path, or an open stream such as a .deb's data.tar)with the one containment policy every PM tar consumer shares. Unsafemembers raise tarfile.FilterError.-- MSYS Git ships dev/fd links and etc/mtab into /proc; those aren't usable- on Windows. Skip only those known links, never a filter error or failed file write."""import tarfile@@ -224,15 +221,7 @@ def extract_tar(archive: Path | IO[bytes], dest: Path, *, git_msys: bool = Falsereal_dest = os.path.realpath(dest)opened = tarfile.open(archive) if isinstance(archive, (str, os.PathLike)) else tarfile.open(fileobj=archive)with opened as tf:- if git_msys:- members = (m for m in tf if not (m.issym() and (- (m.name.lstrip("./").startswith("dev/") and m.linkname.startswith("/proc/"))- or (m.name == "etc/mtab" and m.linkname == "/proc/mounts")- )))- for member in members:- tf.extract(member, dest, filter=lambda item, path: _tar_filter(item, real_dest))- else:- tf.extractall(dest, filter=lambda member, path: _tar_filter(member, real_dest))+ tf.extractall(dest, filter=lambda member, path: _tar_filter(member, real_dest))def extract(archive: Path, dest: Path) -> None:diff --git a/scripts/install.ps1 b/scripts/install.ps1index 079ad0f76e7..d670f5ca324 100644--- a/scripts/install.ps1+++ b/scripts/install.ps1@@ -89,14 +89,14 @@ $script:UvPinFiles = @{$script:GitPinVersion = "2.53.0+3"$script:GitPinFiles = @{"win32-x64" = @{- Url = "https://github.com/git-for-windows/git/releases/download/v2.53.0.windows.3/Git-2.53.0.3-64-bit.tar.bz2"- MirrorUrl = "https://hermes-assets.nousresearch.com/upstream/sha256/1661f02e85a7901ad7920e2a358ee3772ed9066b00d8590bf2d9046ef10aa8b2"- Sha256 = "1661f02e85a7901ad7920e2a358ee3772ed9066b00d8590bf2d9046ef10aa8b2"+ Url = "https://github.com/git-for-windows/git/releases/download/v2.53.0.windows.3/PortableGit-2.53.0.3-64-bit.7z.exe"+ MirrorUrl = "https://hermes-assets.nousresearch.com/upstream/sha256/b365da794b1d2225eb24d5f5e09ef7792cfd5fa26c3a3586210280c80dff3a2a"+ Sha256 = "b365da794b1d2225eb24d5f5e09ef7792cfd5fa26c3a3586210280c80dff3a2a"}"win32-arm64" = @{- Url = "https://github.com/git-for-windows/git/releases/download/v2.53.0.windows.3/Git-2.53.0.3-arm64.tar.bz2"- MirrorUrl = "https://hermes-assets.nousresearch.com/upstream/sha256/4015f05a68bd2bcf3cc6c426e8d44b65d670fbb879225bb7b7c347cfc3a2758a"- Sha256 = "4015f05a68bd2bcf3cc6c426e8d44b65d670fbb879225bb7b7c347cfc3a2758a"+ Url = "https://github.com/git-for-windows/git/releases/download/v2.53.0.windows.3/PortableGit-2.53.0.3-arm64.7z.exe"+ MirrorUrl = "https://hermes-assets.nousresearch.com/upstream/sha256/0db54010054c01f35501cf69e1e32d3710138ecb934d188bd77093afed24300e"+ Sha256 = "0db54010054c01f35501cf69e1e32d3710138ecb934d188bd77093afed24300e"}}# --- END GENERATED: bootstrap pins ---@@ -547,25 +547,23 @@ function Get-PinnedGit {$tmpDir = Join-Path ([IO.Path]::GetTempPath()) "hermes-git-bootstrap-$PID"try {New-Item -ItemType Directory -Force -Path $tmpDir | Out-Null- $tarPath = Join-Path $tmpDir "git.tar.bz2"- Invoke-VerifiedDownload -Url $pin.Url -MirrorUrl $pin.MirrorUrl -Sha256 $pin.Sha256 -OutFile $tarPath+ $sfxPath = Join-Path $tmpDir "portable-git.7z.exe"+ Invoke-VerifiedDownload -Url $pin.Url -MirrorUrl $pin.MirrorUrl -Sha256 $pin.Sha256 -OutFile $sfxPath$extractDir = Join-Path $tmpDir "unpacked"New-Item -ItemType Directory -Force -Path $extractDir | Out-Null- # The pinned artifact is a git-for-windows tar.bz2 (the same one pm- # itself extracts). Windows 10+ ships bsdtar with bzip2 support in- # System32; a GNU tar earlier on PATH (Cygwin/MSYS) reads C:\ as a- # remote host, so never resolve it from PATH.- $inboxTar = Join-Path $env:SystemRoot 'System32\tar.exe'- # MSYS ships these as symlinks into /proc. Without symlink rights (not- # elevated, no Developer Mode) tar cannot create them and fails the- # whole extract. Skip exactly the links pm's own extractor skips- # (pm/store.py extract_tar git_msys) so any other failure still fails.- # '^' anchors bsdtar's otherwise any-path-component match.- $msysProcLinks = @('dev/fd', 'dev/stdin', 'dev/stdout', 'dev/stderr', 'etc/mtab')- $excludes = foreach ($link in $msysProcLinks) { '--exclude'; "^$link" }- Invoke-Native { & $inboxTar @excludes -xf $tarPath -C $extractDir }- if ($LASTEXITCODE) { Fail "failed to extract pinned git archive" }- # Layout: Git-<ver>/cmd\git.exe — flatten the single wrapper dir.+ # The pinned artifact is git-for-windows' PortableGit self-extracting+ # 7z archive. It carries its own extractor, so extraction needs no tar+ # bzip2 filter and no bzip2.exe on the machine: the old .tar.bz2 pin+ # died on Windows 10 boxes whose System32 tar cannot run the bzip2+ # filter ("unable to run program bzip2 -d", issue #122512).+ Unblock-File -Path $sfxPath -ErrorAction SilentlyContinue+ # The SFX stub is a GUI-subsystem exe: PowerShell's `&` would not wait+ # for it, so drive it explicitly and wait for its exit code.+ $sfx = [System.Diagnostics.Process]::Start($sfxPath, "-o`"$extractDir`" -y")+ $sfx.WaitForExit()+ if ($sfx.ExitCode) { Fail "failed to extract pinned git archive" }+ # PortableGit roots cmd\git.exe directly; still flatten a single+ # wrapper dir if a layout ever arrives wrapped.$inner = @(Get-ChildItem $extractDir)$src = $extractDirif ($inner.Count -eq 1 -and $inner[0].PSIsContainer) { $src = $inner[0].FullName }diff --git a/tests/pm/test_store_extract.py b/tests/pm/test_store_extract.pyindex d4ec65d7ba3..ea0870f47f7 100644--- a/tests/pm/test_store_extract.py+++ b/tests/pm/test_store_extract.py@@ -42,81 +42,28 @@ def test_symlinks_escaping_the_destination_are_rejected(tmp_path, linkname):extract(archive, tmp_path / "out")assert not (tmp_path / "out" / "python/bin/evil").is_symlink()-def test_git_tar_ignores_msys_mount_table_link(tmp_path):- from pm.packages import Git-- archive = tmp_path / "git.tar.bz2"- with tarfile.open(archive, "w:bz2") as tf:- mtab = tarfile.TarInfo("etc/mtab")- mtab.type, mtab.linkname = tarfile.SYMTYPE, "/proc/mounts"- tf.addfile(mtab)- binary = tarfile.TarInfo("cmd/git.exe")- binary.size = 1- tf.addfile(binary, io.BytesIO(b"x"))- dest = tmp_path / "out"- Git().unpack(archive, dest, "win32-x64")- assert (dest / "cmd/git.exe").read_bytes() == b"x"- assert not (dest / "etc/mtab").is_symlink()---def test_git_tar_rejects_unrelated_mount_table_links(tmp_path):- from pm.packages import Git-- archive = tmp_path / "git.tar.bz2"- with tarfile.open(archive, "w:bz2") as tf:- mtab = tarfile.TarInfo("etc/mtab")- mtab.type, mtab.linkname = tarfile.SYMTYPE, "/etc/passwd"- tf.addfile(mtab)- with pytest.raises(tarfile.FilterError):- Git().unpack(archive, tmp_path / "out", "win32-x64")+def test_git_staging_needs_no_external_decompressor(tmp_path):+ """Git staging on either side must not route through tar/bzip2 (#122512).--def test_git_tar_skips_only_msys_proc_links_and_rejects_other_unsafe_entries(tmp_path):- from pm.packages import Git-- archive = tmp_path / "git.tar.bz2"- with tarfile.open(archive, "w:bz2") as tf:- proc = tarfile.TarInfo("dev/fd")- proc.type, proc.linkname = tarfile.SYMTYPE, "/proc/self/fd"- tf.addfile(proc)- good = tarfile.TarInfo("cmd/git.exe")- good.size = 1- tf.addfile(good, io.BytesIO(b"x"))- escape = tarfile.TarInfo("../../escaped")- escape.size = 1- tf.addfile(escape, io.BytesIO(b"z"))- with pytest.raises(tarfile.FilterError):- Git().unpack(archive, tmp_path / "out", "win32-x64")- assert (tmp_path / "out/cmd/git.exe").read_bytes() == b"x"- assert not (tmp_path / "out/dev/fd").exists()- assert not (tmp_path / "escaped").exists()---def test_install_ps1_bootstrap_skips_the_same_msys_links_as_pm(tmp_path):- """The pre-PM bootstrap's tar.exe excludes must stay the links PM skips."""- import re+ The old .tar.bz2 pin died on Windows 10 boxes whose System32 tar.exe+ cannot run the bzip2 filter ("unable to run program bzip2 -d").+ """from pathlib import Pathfrom pm.packages import Git+ # pm pins the self-extracting PortableGit archive for every Windows target.+ for target in ("win32-x64", "win32-arm64"):+ assert Git().fetch_url("2.53.0+3", target).endswith(".7z.exe")+ # The pre-PM bootstrap stages the same pin and never shells to tar.exe.installer = Path(__file__).resolve().parents[2] / "scripts" / "install.ps1"- listed = re.search(r"\$msysProcLinks = @\(([^)]*)\)", installer.read_text(encoding="utf-8")).group(1)- excluded = set(re.findall(r"'([^']+)'", listed))- # The pinned Git-for-Windows archives' symlinks (tar -tvf, 2.53.0.windows.3).- links = {"dev/fd": "/proc/self/fd", "dev/stdin": "/proc/self/fd/0", "dev/stdout": "/proc/self/fd/1",- "dev/stderr": "/proc/self/fd/2", "etc/mtab": "/proc/mounts"}- archive = tmp_path / "git.tar.bz2"- with tarfile.open(archive, "w:bz2") as tf:- for name, target in links.items():- info = tarfile.TarInfo(name)- info.type, info.linkname = tarfile.SYMTYPE, target- tf.addfile(info)- binary = tarfile.TarInfo("cmd/git.exe")- binary.size = 1- tf.addfile(binary, io.BytesIO(b"x"))- dest = tmp_path / "out"- Git().unpack(archive, dest, "win32-x64")- skipped = {name for name in links if not os.path.lexists(dest / name)}- assert excluded == skipped == set(links)+ text = installer.read_text(encoding="utf-8-sig")+ assert "$inboxTar" not in text+ assert "System32\\tar.exe" not in text+ # A corrupt payload fails loudly instead of being silently unpacked.+ junk = tmp_path / "git.7z.exe"+ junk.write_bytes(b"not an archive")+ with pytest.raises(OSError):+ Git().unpack(junk, tmp_path / "out", "win32-x64")def test_target_uses_shared_native_arch(monkeypatch):diff --git a/tests/scripts/install/test_install_ps1_pinned_git_extract.py b/tests/scripts/install/test_install_ps1_pinned_git_extract.pynew file mode 100644index 00000000000..c686c1affe6--- /dev/null+++ b/tests/scripts/install/test_install_ps1_pinned_git_extract.py@@ -0,0 +1,82 @@+"""Pinned git staging must not need a bzip2-capable tar (#122512).++The reported Windows 10 box has no bzip2.exe on PATH, and its System32+tar.exe cannot run the bzip2 filter+("tar.exe: Error opening archive: Can't initialize filter; unable to run+program \"bzip2 -d\""), so extracting the pinned .tar.bz2 fails and+bootstrap dies at stage=prerequisites with "failed to extract pinned git+archive".++The driver below reproduces that machine deterministically: PATH carries+no bzip2, and the installer's own Invoke-Native seam resolves $inboxTar+to a stub System32 tar.exe that only prints the reported error. Then it+runs the real Get-PinnedGit against the real pinned archive and demands+a working git.exe plus the bundled bash contract pm/shell.py relies on.+"""+import os+import subprocess+import textwrap+from pathlib import Path++import pytest++ROOT = Path(__file__).resolve().parents[3]+INSTALLER = ROOT / "scripts" / "install.ps1"+CSC = (+ Path(os.environ.get("SystemRoot", r"C:\Windows"))+ / "Microsoft.NET" / "Framework64" / "v4.0.30319" / "csc.exe"+)++[email protected]("windows")+def test_pinned_git_extracts_without_a_bzip2_capable_tar(tmp_path):+ assert CSC.is_file(), f"missing C# compiler: {CSC}"++ # The reporter's System32 tar.exe: it exists, but has no bzip2 filter.+ stub_src = tmp_path / "bzip2less_tar.cs"+ stub_src.write_text(+ "using System; class Stub { static int Main(string[] a) { "+ 'System.Console.Error.WriteLine("tar.exe: Error opening archive: '+ "Can't initialize filter; unable to run program \\\"bzip2 -d\\\"\"); "+ "return 1; } }",+ encoding="ascii",+ )+ fake_root = tmp_path / "sysroot"+ stub_tar = fake_root / "System32" / "tar.exe"+ stub_tar.parent.mkdir(parents=True)+ compiled = subprocess.run(+ [str(CSC), "/nologo", f"/out:{stub_tar}", str(stub_src)],+ capture_output=True, text=True, timeout=120,+ )+ assert compiled.returncode == 0, compiled.stdout + compiled.stderr++ driver = tmp_path / "driver.ps1"+ driver.write_text(+ textwrap.dedent(f"""+ . '{INSTALLER}' -HermesHome '{tmp_path / "home"}'+ $env:HERMES_RUNTIME_DIR = '{tmp_path / "tools"}'+ # This machine has no bzip2 (and nothing else to fall back on).+ $env:PATH = "$env:SystemRoot\\System32;$env:SystemRoot"+ function Invoke-Native {{+ param([scriptblock]$Command)+ # Dynamic scope: bind the installer's $inboxTar to the+ # bzip2-less stub before running its extraction command.+ $inboxTar = '{stub_tar}'+ & $Command+ }}+ $git = Get-PinnedGit+ if (-not $git) {{ exit 9 }}+ & $git --version 2>$null | Out-Null+ if ($LASTEXITCODE) {{ exit 9 }}+ $entry = Split-Path (Split-Path $git)+ if (-not (Test-Path (Join-Path $entry 'usr\\bin\\bash.exe'))) {{ exit 9 }}+ """),+ encoding="ascii",+ )+ result = subprocess.run(+ ["powershell", "-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass",+ "-File", str(driver)],+ capture_output=True, timeout=900,+ )+ out = (result.stdout + result.stderr).decode("utf-8", errors="replace")+ assert result.returncode == 0, out