2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-22 19:08:55 +00:00

archiver: Check that saved file does not have null IDs in content

Null IDs in the file content indicate that something went wrong. Thus
fails before saving the affected file.
This commit is contained in:
Michael Eischer 2022-11-05 13:42:17 +01:00
parent 24a2e5cab9
commit b1d1202b1d
3 changed files with 12 additions and 2 deletions

View File

@ -1969,7 +1969,7 @@ type failSaveRepo struct {
func (f *failSaveRepo) SaveBlob(ctx context.Context, t restic.BlobType, buf []byte, id restic.ID, storeDuplicate bool) (restic.ID, bool, int, error) { func (f *failSaveRepo) SaveBlob(ctx context.Context, t restic.BlobType, buf []byte, id restic.ID, storeDuplicate bool) (restic.ID, bool, int, error) {
val := atomic.AddInt32(&f.cnt, 1) val := atomic.AddInt32(&f.cnt, 1)
if val >= f.failAfter { if val >= f.failAfter {
return restic.ID{}, false, 0, f.err return restic.Hash(buf), false, 0, f.err
} }
return f.Repository.SaveBlob(ctx, t, buf, id, storeDuplicate) return f.Repository.SaveBlob(ctx, t, buf, id, storeDuplicate)

View File

@ -128,6 +128,11 @@ func (s *FileSaver) saveFile(ctx context.Context, chnker *chunker.Chunker, snPat
if isCompleted { if isCompleted {
panic("completed twice") panic("completed twice")
} }
for _, id := range fnr.node.Content {
if id.IsNull() {
panic("completed file with null ID")
}
}
isCompleted = true isCompleted = true
finish(fnr) finish(fnr)
} }

View File

@ -35,7 +35,12 @@ func startFileSaver(ctx context.Context, t testing.TB) (*FileSaver, context.Cont
wg, ctx := errgroup.WithContext(ctx) wg, ctx := errgroup.WithContext(ctx)
saveBlob := func(ctx context.Context, tpe restic.BlobType, buf *Buffer, cb func(SaveBlobResponse)) { saveBlob := func(ctx context.Context, tpe restic.BlobType, buf *Buffer, cb func(SaveBlobResponse)) {
cb(SaveBlobResponse{}) cb(SaveBlobResponse{
id: restic.Hash(buf.Data),
length: len(buf.Data),
sizeInRepo: len(buf.Data),
known: false,
})
} }
workers := uint(runtime.NumCPU()) workers := uint(runtime.NumCPU())