Skip to content

Commit

Permalink
fix: Fixes #245, Fixed exceeding range error for UploadPartCopy action
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaustin09 committed Sep 19, 2023
1 parent 48798c9 commit c9653cf
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion backend/posix/posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ func (p *Posix) UploadPartCopy(_ context.Context, upi *s3.UploadPartCopyInput) (
}

if startOffset+length > fi.Size()+1 {
return s3response.CopyObjectResult{}, s3err.GetAPIError(s3err.ErrInvalidRequest)
return s3response.CopyObjectResult{}, s3err.GetAPIError(s3err.ErrInvalidRange)
}

f, err := openTmpFile(filepath.Join(*upi.Bucket, objdir),
Expand Down
1 change: 1 addition & 0 deletions integration/action-tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ func TestUploadPartCopy(s *S3Conf) {
UploadPartCopy_non_existing_source_object_key(s)
UploadPartCopy_success(s)
UploadPartCopy_by_range_invalid_range(s)
UploadPartCopy_greater_range_than_obj_size(s)
UploadPartCopy_by_range_success(s)
}

Expand Down
40 changes: 40 additions & 0 deletions integration/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -2426,6 +2426,46 @@ func UploadPartCopy_by_range_invalid_range(s *S3Conf) {
})
}

func UploadPartCopy_greater_range_than_obj_size(s *S3Conf) {
testName := "UploadPartCopy_greater_range_than_obj_size"
actionHandler(s, testName, func(s3client *s3.Client, bucket string) error {
obj, srcBucket, srcObj := "my-obj", getBucketName(), "src-obj"
err := setup(s, srcBucket)
if err != nil {
return err
}
srcObjSize := 5 * 1024 * 1024
_, _, err = putObjectWithData(int64(srcObjSize), &s3.PutObjectInput{
Bucket: &srcBucket,
Key: &srcObj,
}, s3client)
if err != nil {
return err
}

out, err := CreateMp(s3client, bucket, obj)
if err != nil {
return err
}

ctx, cancel := context.WithTimeout(context.Background(), shortTimeout)
_, err = s3client.UploadPartCopy(ctx, &s3.UploadPartCopyInput{
Bucket: &bucket,
CopySource: getPtr(srcBucket + "/" + srcObj),
UploadId: out.UploadId,
Key: &obj,
CopySourceRange: getPtr(fmt.Sprintf("bytes=0-%v", srcObjSize+50)), // The specified range is greater than the actual object size
PartNumber: 1,
})
cancel()
if err := checkApiErr(err, s3err.GetAPIError(s3err.ErrInvalidRange)); err != nil {
return err
}

return nil
})
}

func UploadPartCopy_by_range_success(s *S3Conf) {
testName := "UploadPartCopy_by_range_success"
actionHandler(s, testName, func(s3client *s3.Client, bucket string) error {
Expand Down

0 comments on commit c9653cf

Please sign in to comment.