Skip to content

Commit 0825f21

Browse files
committed
fix: pass powershell build arguments safely
Avoid Invoke-Expression and manual quoting so Windows wheel scripts can create venvs in absolute paths without corrupting drive-qualified paths.
1 parent a8ecd9d commit 0825f21

4 files changed

Lines changed: 36 additions & 15 deletions

File tree

native-wheels/scripts/build-diff-gaussian.ps1

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,25 @@ function Invoke-Python {
2525
[string]$WorkingDirectory
2626
)
2727

28-
$command = "$Python $($Arguments -join ' ')"
29-
Write-Host "[native-wheels] $command"
28+
$pythonParts = $Python -split ' '
29+
$pythonExe = $pythonParts[0]
30+
$pythonArgs = @()
31+
if ($pythonParts.Length -gt 1) {
32+
$pythonArgs = $pythonParts[1..($pythonParts.Length - 1)]
33+
}
34+
$allArgs = @($pythonArgs) + @($Arguments)
35+
Write-Host "[native-wheels] $pythonExe $($allArgs -join ' ')"
3036
if ($WorkingDirectory) {
3137
Push-Location $WorkingDirectory
3238
try {
33-
Invoke-Expression $command
39+
& $pythonExe @allArgs
3440
}
3541
finally {
3642
Pop-Location
3743
}
3844
return
3945
}
40-
Invoke-Expression $command
46+
& $pythonExe @allArgs
4147
}
4248

4349
function Ensure-Directory {
@@ -69,7 +75,7 @@ $env:CUDACXX = (Join-Path $CudaRoot 'bin\nvcc.exe')
6975
$env:TORCH_CUDA_ARCH_LIST = $TorchCudaArchList
7076
$env:DISTUTILS_USE_SDK = '1'
7177

72-
Invoke-Python -Arguments @('-m', 'venv', '"' + $venvDir + '"')
78+
Invoke-Python -Arguments @('-m', 'venv', $venvDir)
7379
$venvPython = Join-Path $venvDir 'Scripts\python.exe'
7480

7581
& $venvPython -m pip install --upgrade pip setuptools wheel ninja

native-wheels/scripts/build-nvdiffrast.ps1

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,25 @@ function Invoke-Python {
2424
[string]$WorkingDirectory
2525
)
2626

27-
$command = "$Python $($Arguments -join ' ')"
28-
Write-Host "[native-wheels] $command"
27+
$pythonParts = $Python -split ' '
28+
$pythonExe = $pythonParts[0]
29+
$pythonArgs = @()
30+
if ($pythonParts.Length -gt 1) {
31+
$pythonArgs = $pythonParts[1..($pythonParts.Length - 1)]
32+
}
33+
$allArgs = @($pythonArgs) + @($Arguments)
34+
Write-Host "[native-wheels] $pythonExe $($allArgs -join ' ')"
2935
if ($WorkingDirectory) {
3036
Push-Location $WorkingDirectory
3137
try {
32-
Invoke-Expression $command
38+
& $pythonExe @allArgs
3339
}
3440
finally {
3541
Pop-Location
3642
}
3743
return
3844
}
39-
Invoke-Expression $command
45+
& $pythonExe @allArgs
4046
}
4147

4248
function Ensure-Directory {
@@ -67,7 +73,7 @@ $env:CUDACXX = (Join-Path $CudaRoot 'bin\nvcc.exe')
6773
$env:TORCH_CUDA_ARCH_LIST = $TorchCudaArchList
6874
$env:DISTUTILS_USE_SDK = '1'
6975

70-
Invoke-Python -Arguments @('-m', 'venv', '"' + $venvDir + '"')
76+
Invoke-Python -Arguments @('-m', 'venv', $venvDir)
7177
$venvPython = Join-Path $venvDir 'Scripts\python.exe'
7278

7379
& $venvPython -m pip install --upgrade pip setuptools wheel ninja

native-wheels/scripts/smoke-test.ps1

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,25 @@ function Invoke-Python {
1818
[string]$WorkingDirectory
1919
)
2020

21-
$command = "$Python $($Arguments -join ' ')"
22-
Write-Host "[native-wheels] $command"
21+
$pythonParts = $Python -split ' '
22+
$pythonExe = $pythonParts[0]
23+
$pythonArgs = @()
24+
if ($pythonParts.Length -gt 1) {
25+
$pythonArgs = $pythonParts[1..($pythonParts.Length - 1)]
26+
}
27+
$allArgs = @($pythonArgs) + @($Arguments)
28+
Write-Host "[native-wheels] $pythonExe $($allArgs -join ' ')"
2329
if ($WorkingDirectory) {
2430
Push-Location $WorkingDirectory
2531
try {
26-
Invoke-Expression $command
32+
& $pythonExe @allArgs
2733
}
2834
finally {
2935
Pop-Location
3036
}
3137
return
3238
}
33-
Invoke-Expression $command
39+
& $pythonExe @allArgs
3440
}
3541

3642
$resolvedWheelDir = [System.IO.Path]::GetFullPath($WheelDir)
@@ -51,7 +57,7 @@ if (-not $diffGaussianWheel) {
5157
$tempRoot = Join-Path ([System.IO.Path]::GetTempPath()) ('modly-trellis-text-native-smoke-' + [System.Guid]::NewGuid().ToString('N'))
5258
$venvDir = Join-Path $tempRoot 'venv'
5359

54-
Invoke-Python -Arguments @('-m', 'venv', '"' + $venvDir + '"')
60+
Invoke-Python -Arguments @('-m', 'venv', $venvDir)
5561
$venvPython = Join-Path $venvDir 'Scripts\python.exe'
5662

5763
try {

validate_text_only_setup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,18 +154,21 @@ def validate_native_wheels_tooling() -> None:
154154
build_nvdiffrast = (ROOT / "native-wheels" / "scripts" / "build-nvdiffrast.ps1").read_text(encoding="utf-8")
155155
require("Set-StrictMode -Version Latest" in build_nvdiffrast, "build-nvdiffrast.ps1 must enable strict mode")
156156
require("$ErrorActionPreference = 'Stop'" in build_nvdiffrast, "build-nvdiffrast.ps1 must stop on errors")
157+
require("Invoke-Expression" not in build_nvdiffrast, "build-nvdiffrast.ps1 must not construct commands via Invoke-Expression")
157158
require("pip wheel" in build_nvdiffrast and "--no-build-isolation" in build_nvdiffrast, "build-nvdiffrast.ps1 must build wheels via pip wheel --no-build-isolation")
158159
require("https://github.com/NVlabs/nvdiffrast.git" in build_nvdiffrast and "v0.4.0" in build_nvdiffrast, "build-nvdiffrast.ps1 must pin nvdiffrast source")
159160

160161
build_diff = (ROOT / "native-wheels" / "scripts" / "build-diff-gaussian.ps1").read_text(encoding="utf-8")
161162
require("Set-StrictMode -Version Latest" in build_diff, "build-diff-gaussian.ps1 must enable strict mode")
162163
require("$ErrorActionPreference = 'Stop'" in build_diff, "build-diff-gaussian.ps1 must stop on errors")
164+
require("Invoke-Expression" not in build_diff, "build-diff-gaussian.ps1 must not construct commands via Invoke-Expression")
163165
require("pip wheel" in build_diff and "--no-build-isolation" in build_diff, "build-diff-gaussian.ps1 must build wheels via pip wheel --no-build-isolation")
164166
require("https://github.com/autonomousvision/mip-splatting.git" in build_diff and "dda02ab5ecf45d6edb8c540d9bb65c7e451345a9" in build_diff, "build-diff-gaussian.ps1 must pin mip-splatting source")
165167
require("submodules/diff-gaussian-rasterization" in build_diff, "build-diff-gaussian.ps1 must build the diff-gaussian subdirectory")
166168
require("submodule update --init --recursive" in build_diff, "build-diff-gaussian.ps1 must initialize recursive submodules")
167169

168170
smoke_test = (ROOT / "native-wheels" / "scripts" / "smoke-test.ps1").read_text(encoding="utf-8")
171+
require("Invoke-Expression" not in smoke_test, "smoke-test.ps1 must not construct commands via Invoke-Expression")
169172
require("import torch; import nvdiffrast.torch; import diff_gaussian_rasterization" in smoke_test, "smoke-test.ps1 must validate torch and native imports")
170173

171174
nvdiffrast_license = (ROOT / "native-wheels" / "licenses" / "nvdiffrast-LICENSE.txt").read_text(encoding="utf-8")

0 commit comments

Comments
 (0)