Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/libstore/local-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1060,20 +1060,20 @@ void LocalStore::doAddToStore(const ValidPathInfo & info, Source & source, Repai

auto hashResult = hashSink.finish();

if (hashResult.hash != info.narHash)
throw Error(
"hash mismatch importing path '%s';\n specified: %s\n got: %s",
printStorePath(info.path),
info.narHash.to_string(HashFormat::SRI, true),
hashResult.hash.to_string(HashFormat::SRI, true));

if (hashResult.numBytesDigested != info.narSize)
throw Error(
"size mismatch importing path '%s';\n specified: %s\n got: %s",
printStorePath(info.path),
info.narSize,
hashResult.numBytesDigested);

if (hashResult.hash != info.narHash)
throw Error(
"hash mismatch importing path '%s';\n specified: %s\n got: %s",
printStorePath(info.path),
info.narHash.to_string(HashFormat::SRI, true),
hashResult.hash.to_string(HashFormat::SRI, true));

if (info.ca) {
auto & specified = *info.ca;
auto actualHash = ({
Expand Down
15 changes: 14 additions & 1 deletion tests/functional/binary-cache.sh
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,27 @@ wait "$pid2"
[[ $(cat "$TEST_ROOT/log1" "$TEST_ROOT/log2" | grep -c "downloading.*nar'") -eq 1 ]]


# Test whether Nix notices if the NAR doesn't match the hash in the NAR info.
# Test whether Nix notices if the NAR doesn't match the file size in the NAR info.
clearStore

nar=$cacheDir/$(nix path-info --json --store "file://$cacheDir" "$depPath" | jq -r .[].url)
mv "$nar" "$nar".good
mkdir -p "$TEST_ROOT/empty"
nix-store --dump "$TEST_ROOT/empty" | xz > "$nar"

expect 1 nix-build --substituters "$httpBinaryCacheUrl" --no-require-sigs dependencies.nix -o "$TEST_ROOT/result" 2>&1 | tee "$TEST_ROOT/log"
grepQuiet "size mismatch" "$TEST_ROOT/log"

mv "$nar".good "$nar"


# Test whether Nix notices if the NAR doesn't match the hash in the NAR info.
clearStore

nar=$cacheDir/$(nix path-info --json --store "file://$cacheDir" "$depPath" | jq -r .[].url)
mv "$nar" "$nar".good
xz -cd <"$nar".good | sed 's/foo/Foo/' | xz -c >"$nar"

expect 1 nix-build --substituters "$httpBinaryCacheUrl" --no-require-sigs dependencies.nix -o "$TEST_ROOT/result" 2>&1 | tee "$TEST_ROOT/log"
grepQuiet "hash mismatch" "$TEST_ROOT/log"

Expand Down
Loading