Commit 9796a036 authored by Jeromy's avatar Jeromy

update HashOnRead validation to properly support cids

License: MIT
Signed-off-by: default avatarJeromy <why@ipfs.io>
parent 8ce99632
......@@ -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)
}
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment