Skip to content

Commit

Permalink
Validate the written chunks when using a seed (#214)
Browse files Browse the repository at this point in the history
The seed values are validated at the beginning when we create the
extraction "plan".

However a seed might point to a location where is possible to read and
write data. In that case, even if at the beginning we validated the seed
data, the assumption that when we use `WriteInto()` the seed data is
still valid might not be true anymore.

For this reason we should also re-validate the written data to ensure
that what ended up in the destination is exactly what we were expecting.

Signed-off-by: Ludovico de Nittis <ludovico.denittis@collabora.com>
  • Loading branch information
RyuzakiKK authored Feb 25, 2022
1 parent b565693 commit 16ddd74
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions assemble.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,22 @@ func AssembleFile(ctx context.Context, name string, idx Index, s Store, seeds []
if err != nil {
return err
}

// Validate that the written chunks are exactly what we were expecting.
// Because the seed might point to a RW location, if the data changed
// while we were extracting an index, we might end up writing to the
// destination some unexpected values.
for _, c := range job.segment.chunks() {
b := make([]byte, c.Size)
if _, err := f.ReadAt(b, int64(c.Start)); err != nil {
return err
}
sum := Digest.Sum(b)
if sum != c.ID {
return fmt.Errorf("written data in %s doesn't match its expected hash value, seed may have changed during processing", name)
}
}

stats.addBytesCopied(copied)
stats.addBytesCloned(cloned)
// Record this segment's been written in the self-seed to make it
Expand Down

0 comments on commit 16ddd74

Please sign in to comment.