Skip to content

Commit

Permalink
fix: Removed exceeding invalid range error when calling GetObject action
Browse files Browse the repository at this point in the history
  • Loading branch information
0x180 committed Jun 4, 2024
1 parent dde3094 commit 0fb6bf6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion backend/posix/posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -1569,7 +1569,7 @@ func (p *Posix) GetObject(_ context.Context, input *s3.GetObjectInput, writer io
}

if startOffset+length > objSize+1 {
return nil, s3err.GetAPIError(s3err.ErrInvalidRange)
length = objSize - startOffset + 1
}

var contentRange string
Expand Down
10 changes: 7 additions & 3 deletions tests/integration/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -3031,16 +3031,20 @@ func GetObject_invalid_ranges(s *S3Conf) error {
}

ctx, cancel = context.WithTimeout(context.Background(), shortTimeout)
_, err = s3client.GetObject(ctx, &s3.GetObjectInput{
resp, err := s3client.GetObject(ctx, &s3.GetObjectInput{
Bucket: &bucket,
Key: &obj,
Range: getPtr("bytes=1000000000-999999999999"),
Range: getPtr("bytes=1500-999999999999"),
})
cancel()
if err := checkApiErr(err, s3err.GetAPIError(s3err.ErrInvalidRange)); err != nil {
if err != nil {
return err
}

if *resp.ContentLength != dataLength-1500 {
return fmt.Errorf("expected content-length to be %v, instead got %v", dataLength-1500, *resp.ContentLength)
}

ctx, cancel = context.WithTimeout(context.Background(), shortTimeout)
_, err = s3client.GetObject(ctx, &s3.GetObjectInput{
Bucket: &bucket,
Expand Down

0 comments on commit 0fb6bf6

Please sign in to comment.