From 674dbade27040c0d8e8cbfbd9313afd4866e3e13 Mon Sep 17 00:00:00 2001 From: Kane York Date: Fri, 31 Jul 2020 17:37:15 -0700 Subject: fix(3p/nix/hash): param of Unknown allows any hash type Fixes a crash in the self-hosting instantiate test: NIX_REMOTE="$(mktemp -d)" nix-instantiate -E 'let depot = import ./default.nix {}; in depot.third_party.nix.outPath' Change-Id: If99494aa07ec248d3894d4709ab0fde7fa81aff3 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1508 Reviewed-by: tazjin Tested-by: BuildkiteCI --- third_party/nix/src/libutil/hash.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/third_party/nix/src/libutil/hash.cc b/third_party/nix/src/libutil/hash.cc index 44fc4323b337..0d5a1de07ce7 100644 --- a/third_party/nix/src/libutil/hash.cc +++ b/third_party/nix/src/libutil/hash.cc @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -182,6 +183,7 @@ Hash::Hash(std::string_view s, HashType type) : type(type) { *this = unwrap_throw(result); } +// TODO(riking): change ht to an optional absl::StatusOr Hash::deserialize(std::string_view s, HashType type) { size_t pos = 0; bool isSRI = false; @@ -201,7 +203,7 @@ absl::StatusOr Hash::deserialize(std::string_view s, HashType type) { if (sep != std::string::npos) { std::string hts = std::string(s, 0, sep); parsedType = parseHashType(hts); - if (parsedType != type) { + if (type != htUnknown && parsedType != type) { return absl::InvalidArgumentError( absl::StrCat("hash '", s, "' should have type '", printHashType(type), "', found '", printHashType(parsedType), "'")); @@ -432,7 +434,10 @@ std::string printHashType(HashType ht) { return "sha256"; } else if (ht == htSHA512) { return "sha512"; + } else if (ht == htUnknown) { + return ""; } else { + LOG(FATAL) << "Unrecognized hash type: " << static_cast(ht); abort(); } } -- cgit 1.4.1