From caa90b0abf3be1ca8b4788bf18d26f9d3858bffd Mon Sep 17 00:00:00 2001 From: Cameron Dale Date: Thu, 10 Apr 2008 23:33:30 -0700 Subject: [PATCH] Fix a bug in the Hash checker when updating exactly to a piece boundary. --- apt_p2p/Hash.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/apt_p2p/Hash.py b/apt_p2p/Hash.py index 850f393..9fe1947 100644 --- a/apt_p2p/Hash.py +++ b/apt_p2p/Hash.py @@ -114,6 +114,7 @@ class HashObject: self.fileHasher.update(data[:(PIECE_SIZE - self.size)]) data = data[(PIECE_SIZE - self.size):] self.size = PIECE_SIZE + self.pieceSize = 0 # Save the first piece digest and initialize a new piece hasher self.pieceHash.append(self.fileHasher.digest()) @@ -121,21 +122,21 @@ class HashObject: if self.pieceHasher: # Loop in case the data contains multiple pieces - piece_size = self.size % PIECE_SIZE - while piece_size + len(data) > PIECE_SIZE: + while self.pieceSize + len(data) > PIECE_SIZE: # Save the piece hash and start a new one - self.pieceHasher.update(data[:(PIECE_SIZE - piece_size)]) + self.pieceHasher.update(data[:(PIECE_SIZE - self.pieceSize)]) self.pieceHash.append(self.pieceHasher.digest()) self.pieceHasher = self._new() # Don't forget to hash the data normally - self.fileHasher.update(data[:(PIECE_SIZE - piece_size)]) - data = data[(PIECE_SIZE - piece_size):] - self.size += PIECE_SIZE - piece_size - piece_size = self.size % PIECE_SIZE + self.fileHasher.update(data[:(PIECE_SIZE - self.pieceSize)]) + data = data[(PIECE_SIZE - self.pieceSize):] + self.size += PIECE_SIZE - self.pieceSize + self.pieceSize = 0 # Hash any remaining data self.pieceHasher.update(data) + self.pieceSize += len(data) self.fileHasher.update(data) self.size += len(data) -- 2.39.5