Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .github/workflows/scripts/windows/install-vsb.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,16 @@ function Invoke-WebRequestWithRetry {
}

# Verify file is not corrupted by checking if it's a valid PE executable
$fileBytes = [System.IO.File]::ReadAllBytes($OutFile)
if ($fileBytes.Length -lt 2 -or $fileBytes[0] -ne 0x4D -or $fileBytes[1] -ne 0x5A) {
# Read only the header; ReadAllBytes throws on files over 2 GB
$fileBytes = New-Object byte[] 2
$stream = [System.IO.File]::OpenRead($OutFile)
try {
$bytesRead = $stream.Read($fileBytes, 0, 2)
}
finally {
$stream.Dispose()
}
if ($bytesRead -lt 2 -or $fileBytes[0] -ne 0x4D -or $fileBytes[1] -ne 0x5A) {
throw "Downloaded file is not a valid executable (missing MZ header)"
}

Expand Down
12 changes: 10 additions & 2 deletions .github/workflows/scripts/windows/swift/install-swift.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,16 @@ function Invoke-WebRequestWithRetry {
}

# Verify file is not corrupted by checking if it's a valid PE executable
$fileBytes = [System.IO.File]::ReadAllBytes($OutFile)
if ($fileBytes.Length -lt 2 -or $fileBytes[0] -ne 0x4D -or $fileBytes[1] -ne 0x5A) {
# Read only the header; ReadAllBytes throws on files over 2 GB
$fileBytes = New-Object byte[] 2
$stream = [System.IO.File]::OpenRead($OutFile)
try {
$bytesRead = $stream.Read($fileBytes, 0, 2)
}
finally {
$stream.Dispose()
}
if ($bytesRead -lt 2 -or $fileBytes[0] -ne 0x4D -or $fileBytes[1] -ne 0x5A) {
throw "Downloaded file is not a valid executable (missing MZ header)"
}

Expand Down
Loading