@@ -277,15 +277,28 @@ try {
277277
278278# Validate the zip namespace before extraction. Windows paths are
279279# case-insensitive, so two entries that differ only in case are ambiguous and
280- # must never be allowed to overwrite each other. The official five entries are
280+ # must never be allowed to overwrite each other. The official four entries are
281281# required at the archive root with their exact release names.
282+ #
283+ # Two failure classes are reported differently (both still exit 1; nothing is
284+ # relaxed). An unsafe entry path or a duplicate/case-conflicting entry is a
285+ # hostile archive shape. A well-formed archive whose root file SET differs from
286+ # $WindowsArchiveNames already passed checksum verification above, so it is
287+ # the published artifact for $BaseUrl -- the usual cause is this script being
288+ # newer or older than that release (e.g. install.ps1 run from main ahead of
289+ # the latest release, #1218). Calling that "unsafe" sends the user hunting for
290+ # tampering that is not there. Every entry is screened for the hostile class
291+ # BEFORE any layout verdict, so a bad path can never hide behind a layout
292+ # message just because an unexpected entry happened to come first.
293+ $LayoutMismatch = $false
282294try {
283295 Add-Type - AssemblyName System.IO.Compression.FileSystem
284296 $zip = [System.IO.Compression.ZipFile ]::OpenRead(" $TmpDir \$Archive " )
285297 try {
286298 $seen = New-Object ' System.Collections.Generic.HashSet[string]' ([System.StringComparer ]::OrdinalIgnoreCase)
287299 $archiveCounts = @ {}
288300 foreach ($archiveName in $WindowsArchiveNames ) { $archiveCounts [$archiveName ] = 0 }
301+ $layoutProblem = $null
289302 foreach ($entry in $zip.Entries ) {
290303 $entryName = $entry.FullName.Replace (' \' , ' /' )
291304 $isDirectory = $entryName.EndsWith (' /' )
@@ -304,10 +317,16 @@ try {
304317 throw " duplicate or case-conflicting zip entry: $ ( $entry.FullName ) "
305318 }
306319 if (-not ($WindowsArchiveNames -ccontains $entryName ) -or $isDirectory ) {
307- throw " archive contains an unexpected root entry: $ ( $entry.FullName ) "
320+ if ($null -eq $layoutProblem ) {
321+ $layoutProblem = " archive contains an unexpected root entry: $ ( $entry.FullName ) "
322+ }
323+ continue
308324 }
309325 $archiveCounts [$entryName ] = $archiveCounts [$entryName ] + 1
310326 }
327+ # Every entry passed the hostile-shape checks; only now judge the layout.
328+ $LayoutMismatch = $true
329+ if ($null -ne $layoutProblem ) { throw $layoutProblem }
311330 foreach ($archiveName in $WindowsArchiveNames ) {
312331 if ($archiveCounts [$archiveName ] -ne 1 ) {
313332 throw " archive must contain exactly one $archiveName "
@@ -316,11 +335,21 @@ try {
316335 if ($seen.Count -ne $WindowsArchiveNames.Count ) {
317336 throw " archive does not match the exact Windows release allowlist"
318337 }
338+ $LayoutMismatch = $false
319339 } finally {
320340 $zip.Dispose ()
321341 }
322342} catch {
323- Write-Host " error: unsafe or incomplete release archive: $_ " - ForegroundColor Red
343+ if ($LayoutMismatch ) {
344+ Write-Host " error: release archive layout does not match this installer: $_ " - ForegroundColor Red
345+ Write-Host " The archive matched the checksum published with it at $BaseUrl , so it is"
346+ Write-Host " the genuine release artifact, built for a different installer version."
347+ Write-Host " This installer expects: $ ( $WindowsArchiveNames -join ' , ' ) "
348+ Write-Host " Fix: run the install.ps1 shipped inside that same release archive, or"
349+ Write-Host " re-run this script after the next release is published."
350+ } else {
351+ Write-Host " error: unsafe release archive: $_ " - ForegroundColor Red
352+ }
324353 Remove-Item - Recurse - Force $TmpDir - ErrorAction SilentlyContinue
325354 exit 1
326355}
0 commit comments