@cryptotaxi247 / kubo / commits / 9796a0362

update HashOnRead validation to properly support cids

License: MIT Signed-off-by: Jeromy <why@ipfs.io>

Jeromy committed Oct 18, 2016 at 16:03 UTC 9796a03624fa55e7756e95c350de86da8497d6cc
2 files changed +13 -4
blocks/blockstore/blockstore.go
+8 -4
@@ -100,12 +100,16 @@ func (bs *blockstore) Get(k *cid.Cid) (blocks.Block, error) {
100 }
101
102 if bs.rehash {
103 - rb := blocks.NewBlock(bdata)
104 - if !rb.Cid().Equals(k) {
103 + rbcid, err := k.Prefix().Sum(bdata)
104 + if err != nil {
105 + return nil, err
106 + }
107 +
108 + if !rbcid.Equals(k) {
109 return nil, ErrHashMismatch
106 - } else {
107 - return rb, nil
110 }
111 +
112 + return blocks.NewBlockWithCid(bdata, rbcid)
113 } else {
114 return blocks.NewBlockWithCid(bdata, k)
115 }
test/sharness/t0084-repo-read-rehash.sh
+5
@@ -43,6 +43,11 @@ test_check_bad_blocks() {
43
44 test_check_bad_blocks
45
46 +test_expect_success "can add and cat a raw-leaf file" '
47 + HASH=$(echo "stuff" | ipfs add -q --raw-leaves) &&
48 + ipfs cat $HASH > /dev/null
49 +'
50 +
51 test_launch_ipfs_daemon
52 test_check_bad_blocks
53 test_kill_ipfs_daemon