@@ -228,11 +228,21 @@ function useUvBuild()
228228 return value == " 1" or value == " true" or value == " yes" or value == " on"
229229end
230230
231+ local function containsTraversalSegment (value )
232+ local normalizedValue = string.gsub (value , " \\ " , " /" )
233+ for segment in string.gmatch (normalizedValue , " [^/]+" ) do
234+ if segment == " .." then
235+ return true
236+ end
237+ end
238+ return false
239+ end
240+
231241local function shellQuote (value )
232242 if string.find (value , " [\r\n %z]" ) then
233243 error (" Path contains unsupported control character: " .. value )
234244 end
235- if string.find (value , " %.%.%/ " ) or string.find ( value , " %.%. \\ " ) then
245+ if containsTraversalSegment (value ) then
236246 error (" Path contains unsupported traversal segment: " .. value )
237247 end
238248
@@ -250,7 +260,7 @@ local function powershellQuote(value)
250260 if string.find (value , " [\r\n %z]" ) then
251261 error (" Path contains unsupported control character: " .. value )
252262 end
253- if string.find (value , " %.%.%/ " ) or string.find ( value , " %.%. \\ " ) then
263+ if containsTraversalSegment (value ) then
254264 error (" Path contains unsupported traversal segment: " .. value )
255265 end
256266
@@ -469,6 +479,7 @@ local function verifyUvBuildArchive(path, sha256)
469479
470480 local status
471481 if RUNTIME .osType == " windows" or OS_TYPE == " windows" then
482+ -- shellQuote quotes for cmd.exe; powershellQuote quotes the archive path inside the PowerShell command.
472483 local command = " powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command " ..
473484 shellQuote (" (Get-FileHash -LiteralPath " .. powershellQuote (path ) .. " -Algorithm SHA256).Hash" )
474485 local handle = io.popen (command )
0 commit comments