From 9796a03624fa55e7756e95c350de86da8497d6cc Mon Sep 17 00:00:00 2001
From: Jeromy <why@ipfs.io>
Date: Tue, 18 Oct 2016 16:03:26 -0700
Subject: [PATCH] update HashOnRead validation to properly support cids

License: MIT
Signed-off-by: Jeromy <why@ipfs.io>
---
 blocks/blockstore/blockstore.go         | 12 ++++++++----
 test/sharness/t0084-repo-read-rehash.sh |  5 +++++
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/blocks/blockstore/blockstore.go b/blocks/blockstore/blockstore.go
index dfa35ec41..fb8a0f067 100644
--- a/blocks/blockstore/blockstore.go
+++ b/blocks/blockstore/blockstore.go
@@ -100,12 +100,16 @@ func (bs *blockstore) Get(k *cid.Cid) (blocks.Block, error) {
 	}
 
 	if bs.rehash {
-		rb := blocks.NewBlock(bdata)
-		if !rb.Cid().Equals(k) {
+		rbcid, err := k.Prefix().Sum(bdata)
+		if err != nil {
+			return nil, err
+		}
+
+		if !rbcid.Equals(k) {
 			return nil, ErrHashMismatch
-		} else {
-			return rb, nil
 		}
+
+		return blocks.NewBlockWithCid(bdata, rbcid)
 	} else {
 		return blocks.NewBlockWithCid(bdata, k)
 	}
diff --git a/test/sharness/t0084-repo-read-rehash.sh b/test/sharness/t0084-repo-read-rehash.sh
index 9be2e95cf..7a1faa4bd 100755
--- a/test/sharness/t0084-repo-read-rehash.sh
+++ b/test/sharness/t0084-repo-read-rehash.sh
@@ -43,6 +43,11 @@ test_check_bad_blocks() {
 
 test_check_bad_blocks
 
+test_expect_success "can add and cat a raw-leaf file" '
+	HASH=$(echo "stuff" | ipfs add -q --raw-leaves) &&
+	ipfs cat $HASH > /dev/null
+'
+
 test_launch_ipfs_daemon
 test_check_bad_blocks
 test_kill_ipfs_daemon
-- 
GitLab