Merge pull request #171 from versity/fix/issue-153

Issue 153
This commit is contained in:
Ben McClelland
2023-07-28 21:23:22 -07:00
committed by GitHub
3 changed files with 34 additions and 5 deletions
+6 -3
View File
@@ -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
}
+3 -1
View File
@@ -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
+25 -1
View File
@@ -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,
},
},
},