mirror of
https://github.com/pbakaus/impeccable.git
synced 2026-09-20 18:16:30 +03:00
Fix: report removed launcher downloads accurately (#741)
* Fix: distinguish removed launcher downloads from checksum failures Related to #740; keep the antivirus investigation open. Add executable launcher regressions and a native Windows CI lane. AI assistance: prepared with Codex under Paul Bakaus direction. * Fix: diagnose downloads removed during cache placement Cover removal and truncation around rename and preserve fail-closed behavior through cache placement. AI-assisted under maintainer direction. * Test Windows launcher hash and placement failures Inject failures at command boundaries in a staged test copy while retaining real launcher control flow. Cover both platforms with the same assertions. AI-assisted under maintainer direction.
This commit is contained in:
@@ -82,6 +82,8 @@ curl.exe -fsSL -o "%cached%.part" "%url%" >nul 2>nul
|
||||
if errorlevel 1 goto fail
|
||||
|
||||
:verify
|
||||
call :check_download
|
||||
if errorlevel 1 exit /b 127
|
||||
rem Mirrors the sh launcher and fails closed: a freshly downloaded binary
|
||||
rem runs only after verifying against its .sha256 sidecar. A sidecar that
|
||||
rem cannot be fetched, or an empty certutil result, refuses the download
|
||||
@@ -91,8 +93,16 @@ if errorlevel 1 goto verify_refuse
|
||||
set "expected="
|
||||
set /p expected=<"%cached%.sha256"
|
||||
for /f "tokens=1" %%h in ("%expected%") do set "expected=%%h"
|
||||
call :check_download
|
||||
if errorlevel 1 exit /b 127
|
||||
set "actual="
|
||||
for /f "skip=1 delims=" %%h in ('certutil -hashfile "%cached%.part" SHA256 2^>nul') do if not defined actual set "actual=%%h"
|
||||
rem Reuse the sidecar staging file after reading expected. Check certutil's
|
||||
rem status before parsing: its error text on stdout is not a digest.
|
||||
certutil -hashfile "%cached%.part" SHA256 >"%cached%.sha256" 2>nul
|
||||
if errorlevel 1 goto verify_refuse
|
||||
call :check_download
|
||||
if errorlevel 1 exit /b 127
|
||||
for /f "usebackq skip=1 delims=" %%h in ("%cached%.sha256") do if not defined actual set "actual=%%h"
|
||||
del "%cached%.sha256" >nul 2>nul
|
||||
if not defined expected goto verify_refuse
|
||||
if not defined actual goto verify_refuse
|
||||
@@ -103,17 +113,48 @@ echo impeccable: checksum mismatch downloading %url% 1>&2
|
||||
exit /b 127
|
||||
|
||||
:verify_refuse
|
||||
call :check_download
|
||||
if errorlevel 1 exit /b 127
|
||||
del "%cached%.part" >nul 2>nul
|
||||
del "%cached%.sha256" >nul 2>nul
|
||||
echo impeccable: cannot verify %url% against %url%.sha256; refusing the unverified download 1>&2
|
||||
exit /b 127
|
||||
|
||||
:check_download
|
||||
set "download_file=%~1"
|
||||
if not defined download_file set "download_file=%cached%.part"
|
||||
if not exist "%download_file%" goto download_missing
|
||||
for %%f in ("%download_file%") do if %%~zf==0 goto download_empty
|
||||
exit /b 0
|
||||
|
||||
:download_missing
|
||||
del "%cached%.sha256" >nul 2>nul
|
||||
echo impeccable: download completed but the file was removed before execution: %url%; check your antivirus quarantine or logs. Refusing to continue; do not disable protection. 1>&2
|
||||
exit /b 127
|
||||
|
||||
:download_empty
|
||||
del "%download_file%" >nul 2>nul
|
||||
del "%cached%.sha256" >nul 2>nul
|
||||
echo impeccable: downloaded file is empty: %url%; refusing the unverified download 1>&2
|
||||
exit /b 127
|
||||
|
||||
:place
|
||||
call :check_download
|
||||
if errorlevel 1 exit /b 127
|
||||
move /y "%cached%.part" "%cached%" >nul 2>nul
|
||||
if not exist "%cached%" goto fail
|
||||
if errorlevel 1 goto place_failed
|
||||
call :check_download "%cached%"
|
||||
if errorlevel 1 exit /b 127
|
||||
set "run=%cached%"
|
||||
goto run
|
||||
|
||||
:place_failed
|
||||
call :check_download
|
||||
if errorlevel 1 exit /b 127
|
||||
del "%cached%.part" >nul 2>nul
|
||||
echo impeccable: could not cache the verified download: %url% 1>&2
|
||||
exit /b 127
|
||||
|
||||
:run
|
||||
"%run%" %*
|
||||
exit /b
|
||||
|
||||
Reference in New Issue
Block a user