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..64d8e1a7c41 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 and wrapped leaves fails without crashing" ' + ipfs add --hash poseidon-bls12_381-a2-fc1 --raw-leaves=false -r mountdir/planets + ' + } # should work offline