From d351cd7674ebe3ccbeceedb32a62c564b01d8faf Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Thu, 12 Apr 2007 15:18:46 -0700 Subject: [PATCH] download: always validate the blockhash, and don't let the bucket trick us into not validating hashes --- src/allmydata/download.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/allmydata/download.py b/src/allmydata/download.py index 57ba5645..a1b250c1 100644 --- a/src/allmydata/download.py +++ b/src/allmydata/download.py @@ -66,20 +66,26 @@ class ValidatedBucket: # validate from our share hash up to the hashroot if self.share_hash_tree.needed_hashes(leaves=[self.sharenum]): d3 = self.bucket.callRemote('get_share_hashes') + need_to_validate_sharehash = True else: d3 = defer.succeed(None) + need_to_validate_sharehash = False d = defer.gatherResults([d1, d2, d3]) - d.addCallback(self._got_data, blocknum) + d.addCallback(self._got_data, blocknum, need_to_validate_sharehash) return d - def _got_data(self, res, blocknum): + def _got_data(self, res, blocknum, need_to_validate_sharehash): blockdata, blockhashes, sharehashes = res blockhash = hashutil.tagged_hash("encoded subshare", blockdata) - if blockhashes: - bh = dict(enumerate(blockhashes)) - self.block_hash_tree.set_hashes(bh, {blocknum: blockhash}, - must_validate=True) - if sharehashes: + # we always validate the blockhash + if blockhashes is None: + blockhashes = [] + bh = dict(enumerate(blockhashes)) + self.block_hash_tree.set_hashes(bh, {blocknum: blockhash}, + must_validate=True) + if need_to_validate_sharehash: + # we only need to validate the sharehash once, the first time we + # fetch a block sh = dict(sharehashes) sharehash = self.block_hash_tree[0] self.share_hash_tree.set_hashes(sh, {self.sharenum: sharehash}, -- 2.45.2