230230
231231local function containsTraversalSegment (value )
232232 local normalizedValue = string.gsub (value , " \\ " , " /" )
233+ local lowerValue = string.lower (normalizedValue )
234+ if string.find (lowerValue , " %%2e" , 1 , false ) then
235+ return true
236+ end
233237 for segment in string.gmatch (normalizedValue , " [^/]+" ) do
234- if segment == " .." then
238+ if string.sub ( segment , 1 , 2 ) == " .." then
235239 return true
236240 end
237241 end
@@ -256,17 +260,6 @@ local function shellQuote(value)
256260 return " '" .. string.gsub (value , " '" , " '\\ ''" ) .. " '"
257261end
258262
259- local function powershellQuote (value )
260- if string.find (value , " [\r\n %z]" ) then
261- error (" Path contains unsupported control character: " .. value )
262- end
263- if containsTraversalSegment (value ) then
264- error (" Path contains unsupported traversal segment: " .. value )
265- end
266-
267- return " '" .. string.gsub (value , " '" , " ''" ) .. " '"
268- end
269-
270263local function startsWith (value , prefix )
271264 return string.sub (value , 1 , string.len (prefix )) == prefix
272265end
@@ -479,9 +472,9 @@ local function verifyUvBuildArchive(path, sha256)
479472
480473 local status
481474 if RUNTIME .osType == " windows" or OS_TYPE == " windows" then
482- -- shellQuote quotes for cmd.exe; powershellQuote quotes the archive path inside the PowerShell command.
475+ os . setenv ( " VFOX_PYTHON_HASH_PATH " , path )
483476 local command = " powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command " ..
484- shellQuote (" (Get-FileHash -LiteralPath " .. powershellQuote ( path ) .. " -Algorithm SHA256).Hash" )
477+ shellQuote (" (Get-FileHash -LiteralPath $env:VFOX_PYTHON_HASH_PATH -Algorithm SHA256).Hash" )
485478 local handle = io.popen (command )
486479 if handle == nil then
487480 error (" Unable to verify uv-build archive sha256 for " .. path .. " : powershell Get-FileHash command could not be started" )
0 commit comments