From 44bd9ea879fb69bd90027c3d0b19dbb94e45ed1e Mon Sep 17 00:00:00 2001 From: Paul LeMarquand Date: Mon, 26 Oct 2026 11:45:27 -0400 Subject: [PATCH] Only read the PE header when verifying downloaded Windows installers The download check read the whole installer with ReadAllBytes just to look at the first two bytes. ReadAllBytes throws on files over 2 GB, and the nightly-main Windows toolchain installer is now 2087 MB, so every attempt fails with "The file is too long" and the Install Swift step gives up after 5 retries. Open the file and read only the two-byte MZ header instead. The same check in install-vsb.ps1 gets the same fix. --- .github/workflows/scripts/windows/install-vsb.ps1 | 12 ++++++++++-- .../scripts/windows/swift/install-swift.ps1 | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/.github/workflows/scripts/windows/install-vsb.ps1 b/.github/workflows/scripts/windows/install-vsb.ps1 index 439e4975..84cc59f7 100644 --- a/.github/workflows/scripts/windows/install-vsb.ps1 +++ b/.github/workflows/scripts/windows/install-vsb.ps1 @@ -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)" } diff --git a/.github/workflows/scripts/windows/swift/install-swift.ps1 b/.github/workflows/scripts/windows/swift/install-swift.ps1 index 63da0b72..51cdf80f 100644 --- a/.github/workflows/scripts/windows/swift/install-swift.ps1 +++ b/.github/workflows/scripts/windows/swift/install-swift.ps1 @@ -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)" }