提交 9796a036 作者: Jeromy

update HashOnRead validation to properly support cids

License: MIT
Signed-off-by: 's avatarJeromy <why@ipfs.io>
上级 8ce99632
...@@ -100,12 +100,16 @@ func (bs *blockstore) Get(k *cid.Cid) (blocks.Block, error) { ...@@ -100,12 +100,16 @@ func (bs *blockstore) Get(k *cid.Cid) (blocks.Block, error) {
} }
if bs.rehash { if bs.rehash {
rb := blocks.NewBlock(bdata) rbcid, err := k.Prefix().Sum(bdata)
if !rb.Cid().Equals(k) { if err != nil {
return nil, err
}
if !rbcid.Equals(k) {
return nil, ErrHashMismatch return nil, ErrHashMismatch
} else {
return rb, nil
} }
return blocks.NewBlockWithCid(bdata, rbcid)
} else { } else {
return blocks.NewBlockWithCid(bdata, k) return blocks.NewBlockWithCid(bdata, k)
} }
......
...@@ -43,6 +43,11 @@ test_check_bad_blocks() { ...@@ -43,6 +43,11 @@ test_check_bad_blocks() {
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_launch_ipfs_daemon
test_check_bad_blocks test_check_bad_blocks
test_kill_ipfs_daemon test_kill_ipfs_daemon
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论