LocalStore::addToStore(): Check info.narSize
It allowed the client to specify bogus narSize values. In particular, Downloader::downloadCached wasn't setting narSize at all.
This commit is contained in:
parent
1fd59447d5
commit
45d7b1a9e9
2 changed files with 7 additions and 2 deletions
|
@ -652,6 +652,7 @@ Path Downloader::downloadCached(ref<Store> store, const string & url_, bool unpa
|
|||
Hash hash = hashString(expectedHash ? expectedHash.type : htSHA256, *res.data);
|
||||
info.path = store->makeFixedOutputPath(false, hash, name);
|
||||
info.narHash = hashString(htSHA256, *sink.s);
|
||||
info.narSize = sink.s->size();
|
||||
info.ca = makeFixedOutputCA(false, hash);
|
||||
store->addToStore(info, sink.s, false, true);
|
||||
storePath = info.path;
|
||||
|
|
|
@ -919,8 +919,12 @@ void LocalStore::addToStore(const ValidPathInfo & info, const ref<std::string> &
|
|||
|
||||
Hash h = hashString(htSHA256, *nar);
|
||||
if (h != info.narHash)
|
||||
throw Error(format("hash mismatch importing path ‘%s’; expected hash ‘%s’, got ‘%s’") %
|
||||
info.path % info.narHash.to_string() % h.to_string());
|
||||
throw Error("hash mismatch importing path ‘%s’; expected hash ‘%s’, got ‘%s’",
|
||||
info.path, info.narHash.to_string(), h.to_string());
|
||||
|
||||
if (nar->size() != info.narSize)
|
||||
throw Error("szie mismatch importing path ‘%s’; expected %s, got %s",
|
||||
info.path, info.narSize, nar->size());
|
||||
|
||||
if (requireSigs && !dontCheckSigs && !info.checkSignatures(*this, publicKeys))
|
||||
throw Error("cannot add path ‘%s’ because it lacks a valid signature", info.path);
|
||||
|
|
Loading…
Reference in a new issue