From ff39b162a6d3bbfc5a9f46097f7d6e7a224fe2fb Mon Sep 17 00:00:00 2001 From: Andy Asp Date: Wed, 20 Sep 2023 12:31:49 -0400 Subject: [PATCH] S3: clone putUserMetadata map to prevent concurrent modification Signed-off-by: Andy Asp --- providers/s3/s3.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/providers/s3/s3.go b/providers/s3/s3.go index f92d3973..83e3a2de 100644 --- a/providers/s3/s3.go +++ b/providers/s3/s3.go @@ -492,6 +492,13 @@ func (b *Bucket) Upload(ctx context.Context, name string, r io.Reader) error { if size < int64(partSize) { partSize = 0 } + + // Cloning map since minio may modify it + userMetadata := make(map[string]string, len(b.putUserMetadata)) + for k, v := range b.putUserMetadata { + userMetadata[k] = v + } + if _, err := b.client.PutObject( ctx, b.name, @@ -501,7 +508,7 @@ func (b *Bucket) Upload(ctx context.Context, name string, r io.Reader) error { minio.PutObjectOptions{ PartSize: partSize, ServerSideEncryption: sse, - UserMetadata: b.putUserMetadata, + UserMetadata: userMetadata, StorageClass: b.storageClass, // 4 is what minio-go have as the default. To be certain we do micro benchmark before any changes we // ensure we pin this number to four.