2022-06-06 16:26:38 +02:00
|
|
|
package repository
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/restic/restic/internal/restic"
|
2025-10-08 22:36:04 +02:00
|
|
|
rtest "github.com/restic/restic/internal/test"
|
2022-06-06 16:26:38 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Test saving a blob and loading it again, with varying buffer sizes.
|
|
|
|
|
// Also a regression test for #3783.
|
|
|
|
|
func FuzzSaveLoadBlob(f *testing.F) {
|
|
|
|
|
f.Fuzz(func(t *testing.T, blob []byte, buflen uint) {
|
|
|
|
|
if buflen > 64<<20 {
|
|
|
|
|
// Don't allocate enormous buffers. We're not testing the allocator.
|
|
|
|
|
t.Skip()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
id := restic.Hash(blob)
|
2024-12-01 12:19:16 +01:00
|
|
|
repo, _, _ := TestRepositoryWithVersion(t, 2)
|
2022-06-06 16:26:38 +02:00
|
|
|
|
2025-10-13 21:56:42 +02:00
|
|
|
rtest.OK(t, repo.WithBlobUploader(context.TODO(), func(ctx context.Context, uploader restic.BlobSaverWithAsync) error {
|
2025-10-10 22:41:35 +02:00
|
|
|
_, _, _, err := uploader.SaveBlob(ctx, restic.DataBlob, blob, id, false)
|
2025-10-08 22:36:04 +02:00
|
|
|
return err
|
|
|
|
|
}))
|
2022-06-06 16:26:38 +02:00
|
|
|
|
|
|
|
|
buf, err := repo.LoadBlob(context.TODO(), restic.DataBlob, id, make([]byte, buflen))
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
if restic.Hash(buf) != id {
|
|
|
|
|
t.Fatal("mismatch")
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|