Skip to content

Commit 2c2a0d8

Browse files
committed
Git fetcher: Don't compute revCount if it's already specified
We don't care if the user (or more likely the lock file) specifies an incorrect value for revCount, since it doesn't matter for security (unlikely content hashes like narHash).
1 parent 72dbd43 commit 2c2a0d8

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

src/libfetchers/fetchers.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,6 @@ void Input::checkLocks(Input specified, Input & result)
282282
if (result.getRev() != prevRev)
283283
throw Error("'rev' attribute mismatch in input '%s', expected %s", result.to_string(), prevRev->gitRev());
284284
}
285-
286-
if (auto prevRevCount = specified.getRevCount()) {
287-
if (result.getRevCount() != prevRevCount)
288-
throw Error("'revCount' attribute mismatch in input '%s', expected %d", result.to_string(), *prevRevCount);
289-
}
290285
}
291286

292287
std::pair<ref<SourceAccessor>, Input> Input::getAccessor(const Settings & settings, Store & store) const

src/libfetchers/git.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,8 +891,13 @@ struct GitInputScheme : InputScheme
891891

892892
input.attrs.insert_or_assign("lastModified", getLastModified(settings, repoInfo, repoDir, rev));
893893

894-
if (!getShallowAttr(input))
895-
input.attrs.insert_or_assign("revCount", getRevCount(settings, repoInfo, repoDir, rev));
894+
if (!getShallowAttr(input)) {
895+
/* Skip revCount computation if it's already supplied by the caller.
896+
We don't care if they specify an incorrect value; it doesn't
897+
matter for security, unlike narHash. */
898+
if (!input.attrs.contains("revCount"))
899+
input.attrs.insert_or_assign("revCount", getRevCount(settings, repoInfo, repoDir, rev));
900+
}
896901

897902
printTalkative("using revision %s of repo '%s'", rev.gitRev(), repoInfo.locationToArg());
898903

tests/nixos/tarball-flakes.nix

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ in
9999
100100
# Check that fetching fails if we provide incorrect attributes.
101101
machine.fail("nix flake metadata --json http://localhost/tags/latest.tar.gz?rev=493300eb13ae6fb387fbd47bf54a85915acc31c0")
102-
machine.fail("nix flake metadata --json http://localhost/tags/latest.tar.gz?revCount=789")
103102
machine.fail("nix flake metadata --json http://localhost/tags/latest.tar.gz?narHash=sha256-tbudgBSg+bHWHiHnlteNzN8TUvI80ygS9IULh4rklEw=")
104103
'';
105104

0 commit comments

Comments
 (0)