From 898c3efaa04db4d138dabab78f8e79e0cce15bca Mon Sep 17 00:00:00 2001 From: jonaustin09 Date: Fri, 28 Jul 2023 18:20:07 +0400 Subject: [PATCH] fix: Fixes #153. Fixed CompleteMultipartUpload invalid ETag error case, fixed UploadPart xattr.Set error --- backend/posix/posix.go | 9 ++++++--- backend/scoutfs/scoutfs.go | 4 +++- integration/tests.go | 26 +++++++++++++++++++++++++- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/backend/posix/posix.go b/backend/posix/posix.go index b42c3ba..a00c6b5 100644 --- a/backend/posix/posix.go +++ b/backend/posix/posix.go @@ -295,7 +295,9 @@ func (p *Posix) CompleteMultipartUpload(_ context.Context, input *s3.CompleteMul if err != nil { etag = "" } - parts[i].ETag = &etag + if etag != *parts[i].ETag { + return nil, s3err.GetAPIError(s3err.ErrInvalidPart) + } } f, err := openTmpFile(filepath.Join(bucket, metaTmpDir), bucket, object, totalsize) @@ -752,7 +754,6 @@ func (p *Posix) UploadPart(_ context.Context, input *s3.UploadPartInput) (string if err != nil { return "", fmt.Errorf("open temp file: %w", err) } - defer f.cleanup() hash := md5.New() tr := io.TeeReader(r, hash) @@ -766,9 +767,11 @@ func (p *Posix) UploadPart(_ context.Context, input *s3.UploadPartInput) (string return "", fmt.Errorf("link object in namespace: %w", err) } + f.cleanup() + dataSum := hash.Sum(nil) etag := hex.EncodeToString(dataSum) - xattr.Set(partPath, etagkey, []byte(etag)) + xattr.Set(filepath.Join(bucket, partPath), etagkey, []byte(etag)) return etag, nil } diff --git a/backend/scoutfs/scoutfs.go b/backend/scoutfs/scoutfs.go index 99c2e53..0935ebb 100644 --- a/backend/scoutfs/scoutfs.go +++ b/backend/scoutfs/scoutfs.go @@ -166,7 +166,9 @@ func (s *ScoutFS) CompleteMultipartUpload(_ context.Context, input *s3.CompleteM if err != nil { etag = "" } - parts[i].ETag = &etag + if etag != *parts[i].ETag { + return nil, s3err.GetAPIError(s3err.ErrInvalidPart) + } } // use totalsize=0 because we wont be writing to the file, only moving diff --git a/integration/tests.go b/integration/tests.go index 16cd71a..164cb0f 100644 --- a/integration/tests.go +++ b/integration/tests.go @@ -777,6 +777,30 @@ func TestIncorrectMultiParts(s *S3Conf) { return } + ctx, cancel = context.WithTimeout(context.Background(), shortTimeout) + _, err = s3client.CompleteMultipartUpload(ctx, &s3.CompleteMultipartUploadInput{ + Bucket: &bucket, + Key: &obj, + UploadId: mpu.UploadId, + MultipartUpload: &types.CompletedMultipartUpload{ + Parts: []types.CompletedPart{ + { + ETag: mp2.ETag, + PartNumber: 96, + }, + { + ETag: mp1.ETag, + PartNumber: 99, + }, + }, + }, + }) + cancel() + if err == nil { + failF("%v: complete multipart expected err", testname) + return + } + badEtag := "bogusEtagValue" ctx, cancel = context.WithTimeout(context.Background(), shortTimeout) @@ -792,7 +816,7 @@ func TestIncorrectMultiParts(s *S3Conf) { }, { ETag: &badEtag, - PartNumber: 99, + PartNumber: 42, }, }, },