From 406de4e7b9ded07ab7ad02945a5360bc934d61a7 Mon Sep 17 00:00:00 2001 From: Jorropo Date: Mon, 26 Sep 2022 06:55:37 +0200 Subject: [PATCH] fix: ensure hasher is registered when using a hashing function Fixes #9297 --- core/commands/add.go | 3 +++ test/sharness/t0042-add-skip.sh | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/core/commands/add.go b/core/commands/add.go index 9f686e14b9f..12a38aaebe7 100644 --- a/core/commands/add.go +++ b/core/commands/add.go @@ -210,6 +210,9 @@ See 'dag export' and 'dag import' for more information. if !ok { return fmt.Errorf("unrecognized hash function: %q", strings.ToLower(hashFunStr)) } + if _, err := mh.GetHasher(hashFunCode); err != nil { + return err + } enc, err := cmdenv.GetCidEncoder(req) if err != nil { diff --git a/test/sharness/t0042-add-skip.sh b/test/sharness/t0042-add-skip.sh index 9da78163c45..b20bb743a66 100755 --- a/test/sharness/t0042-add-skip.sh +++ b/test/sharness/t0042-add-skip.sh @@ -93,6 +93,10 @@ EOF test_cmp expected actual ' + test_expect_failure "'ipfs add' with an unregistered hash fails without crashing" ' + ipfs add --hash poseidon-bls12_381-a2-fc1 --raw-leaves=false -r planets/ + ' + } # should work offline