Skip to content

Commit 07e73a3

Browse files
authored
Merge pull request DeusData#2766 from RithvikReddy0-0/install-ps1-layout-mismatch
install.ps1: report a checksum-verified layout mismatch separately from an unsafe archive
2 parents 4ad22bf + 2809f88 commit 07e73a3

2 files changed

Lines changed: 58 additions & 3 deletions

File tree

‎install.ps1‎

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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
282294
try {
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
}

‎tests/test_windows_bundle_contract.sh‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,32 @@ for relative, needles in exact_archive_guards.items():
335335
"allowlist",
336336
)
337337
338+
# install.ps1 reports two different archive failures differently (#1218). A
339+
# checksum-verified archive whose root file set differs from the allowlist is a
340+
# release/installer version skew, not tampering, and must say so; a hostile
341+
# entry (unsafe path, duplicate or case conflict) stays "unsafe". Both exit 1.
342+
# The layout verdict may only be reached after EVERY entry cleared the hostile
343+
# checks, or an unexpected entry listed first would mask a later "../" entry.
344+
installer_archive = read("install.ps1")
345+
require(
346+
"unsafe or incomplete release archive" not in installer_archive
347+
and "error: unsafe release archive: " in installer_archive
348+
and "error: release archive layout does not match this installer: " in installer_archive,
349+
"install.ps1 must report a checksum-verified layout mismatch separately from an unsafe "
350+
"archive (#1218)",
351+
)
352+
hostile_last = max(
353+
installer_archive.find('throw "unsafe zip entry path:'),
354+
installer_archive.find('throw "duplicate or case-conflicting zip entry:'),
355+
)
356+
layout_verdict = installer_archive.find("$LayoutMismatch = $true")
357+
require(
358+
hostile_last != -1 and layout_verdict > hostile_last
359+
and installer_archive.count("$LayoutMismatch = $true") == 1,
360+
"install.ps1 must screen every zip entry for unsafe paths and duplicates before it "
361+
"classifies an archive as a layout mismatch (#1218)",
362+
)
363+
338364
# A portable mutation refusal must point to the owning package manager.
339365
guidance_contracts = {
340366
"pkg/npm/bin.js": (

0 commit comments

Comments
 (0)