From 0fb6bf6267936b829ba9b7632f0ec6c4a77025a6 Mon Sep 17 00:00:00 2001 From: jonaustin09 Date: Tue, 4 Jun 2024 13:25:56 -0400 Subject: [PATCH] fix: Removed exceeding invalid range error when calling GetObject action --- backend/posix/posix.go | 2 +- tests/integration/tests.go | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/backend/posix/posix.go b/backend/posix/posix.go index 74fc824..199e8bd 100644 --- a/backend/posix/posix.go +++ b/backend/posix/posix.go @@ -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 diff --git a/tests/integration/tests.go b/tests/integration/tests.go index 093711c..c74f082 100644 --- a/tests/integration/tests.go +++ b/tests/integration/tests.go @@ -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,