Skip to content

Commit

Permalink
fix: mismatch digest peer task did not mark invalid (#903)
Browse files Browse the repository at this point in the history
Signed-off-by: Jim Ma <[email protected]>
  • Loading branch information
jim3ma authored Dec 9, 2021
1 parent 4343f62 commit 82aebc6
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion client/daemon/storage/local_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ func (t *localTaskStore) ValidateDigest(*PeerTaskMetadata) error {
t.Lock()
defer t.Unlock()
if t.persistentMetadata.PieceMd5Sign == "" {
t.invalid.Store(true)
return ErrDigestNotSet
}
if t.TotalPieces <= 0 {
Expand All @@ -184,13 +185,14 @@ func (t *localTaskStore) ValidateDigest(*PeerTaskMetadata) error {
}

var pieceDigests []string
for i := int32(0); i < int32(t.TotalPieces); i++ {
for i := int32(0); i < t.TotalPieces; i++ {
pieceDigests = append(pieceDigests, t.Pieces[i].Md5)
}

digest := digestutils.Sha256(pieceDigests...)
if digest != t.PieceMd5Sign {
t.Errorf("invalid digest, desired: %s, actual: %s", t.PieceMd5Sign, digest)
t.invalid.Store(true)
return ErrInvalidDigest
}
return nil
Expand Down

0 comments on commit 82aebc6

Please sign in to comment.