fix(downloader): in-process SHA-256 + per-candidate integrity fallback#321
Merged
Conversation
Two defects found by mcpp's macos-14 fresh-install lane (mcpp PR #123): 1. sha256 verification shelled out to `sha256sum` — a GNU coreutils tool absent on stock macOS (only `shasum` exists). On hosts without coreutils every sha256-pinned download failed as 'SHA256 mismatch' regardless of payload integrity (macos-14 runner image; macos-15 happens to carry it transitively). Replaced both call sites with an in-process FIPS 180-4 implementation (xlings.libs.sha256) — no host tool dependency on any platform. 2. Integrity was checked AFTER the multi-candidate download loop: a mirror that wins the adaptive latency race but serves corrupted bytes failed the whole download with the remaining candidates (including the author URL) untried. download_file now takes an onVerify per-candidate acceptance hook — a rejected candidate is removed, penalized (mirror::adaptive), and the next URL is tried. Unit tests: NIST vectors + padding boundaries + file digests for sha256; candidate-fallback behavior via a transferOverride test seam.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
mcpp's new macos-14 fresh-install CI lane (mcpp-community/mcpp PR #123) caught
mcpplibs.cmdline@0.0.1failing withSHA256 mismatchon every attempt — including with the author URL first and bytes proven intact via curl (shasummatched the declared sha256).Root causes
sha256sumshell-out: stock macOS has nosha256sum(coreutils; onlyshasumships).run_command_capturefails → treated as mismatch → every sha256-pinned download fails on such hosts, irrespective of content. The macos-14 runner image lacks it; macos-15 happens to have it transitively, masking the bug there.download_filereturned, so a fast-but-corrupt mirror (adaptive ordering may put mirrors before the author URL when bytes are sha-pinned) failed the whole download with the remaining candidates untried.Fix
xlings.libs.sha256: in-process FIPS 180-4 SHA-256 (streaming hasher +hex/hex_file); both downloader call sites switched — no host-tool dependency on any platform.download_filegains anonVerifyper-candidate acceptance hook: rejected candidate → file removed,onUrlAttemptFailedfires (host penalized viamirror::adaptive), next URL tried. Wired to the sha check; behavior unchanged when no hook is set.Tests
test_sha256.cpp: NIST vectors (empty/abc/two-block/million-a), padding boundaries (55/56/63/64 + split updates), file digest, missing file.DownloadVerify.*: rejected candidate falls through to next URL; all-rejected fails with file removed; no-hook keeps prior behavior (via atransferOverridetest seam — same pattern as the exportedStallDetector).Extract.ZipUtf8PathRoundTrip, which fails identically on clean main (local host zip/locale issue, green on CI).