From 773c246232c1f3d7fc67d7ddf5b1cb172ece8fa1 Mon Sep 17 00:00:00 2001
From: Jorropo <jorropo.pgm@gmail.com>
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 9f686e14b..12a38aaeb 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 9da78163c..64d8e1a7c 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
-- 
GitLab