From: Cameron Dale Date: Fri, 11 Apr 2008 06:33:30 +0000 (-0700) Subject: Fix a bug in the Hash checker when updating exactly to a piece boundary. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=caa90b0abf3be1ca8b4788bf18d26f9d3858bffd;p=quix0rs-apt-p2p.git Fix a bug in the Hash checker when updating exactly to a piece boundary. --- 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)