Thanks to visit codestin.com
Credit goes to github.com

Skip to content

bug: S3 range requests where end < last return a 416, instead of returning the entire content. #9076

Closed
@sjperkins

Description

@sjperkins

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

When a "range: bytes=start-end" header is supplied where end < start, localstack's S3 implementation returns a 416 response.

begin, end = [int(i) if i else None for i in rspec.split("-")]
if begin is not None: # byte range
end = last if end is None else min(end, last)
elif end is not None: # suffix byte range
begin = object_size - min(end, object_size)
end = last
else:
# TODO, find exception here
raise Exception("TODO")
if begin < 0 or end > last or begin > min(end, last):
raise InvalidRange(
"The requested range is not satisfiable",
ActualObjectSize=str(object_size),
RangeRequested=range_header,
)

By contrast AWS returns the entire content.

Expected Behavior

AWS Behaviour returns the entire content if end < start:

$ echo "Hello World" > test.txt
$  aws s3 cp test.txt s3://ratt-public-data   # Permissions needed to upload, but I've left test.txt here
$ curl  -H "range: bytes=1-0" https://ratt-public-data.s3.af-south-1.amazonaws.com/test.txt
Hello World
$ curl  -H "range: bytes=15-1" https://ratt-public-data.s3.af-south-1.amazonaws.com/test.txt
Hello World

How are you starting LocalStack?

With the localstack script

Steps To Reproduce

Localstack behaviour for a "range: bytes=1-0" header returns a 416 response:

$ echo "Hello World" > test.txt
$ localstack start -d
$ awslocal s3api create-bucket --bucket sample-bucket --region=us-east-1
{
    "Location": "/sample-bucket"
}
$ awslocal s3api put-object --bucket sample-bucket --key test.txt --body test.txt --region=us-east-1
{
    "ETag": "\"e59ff97941044f85df5297e1c302d260\""
}
$ curl -H "range: bytes=1-0" http://localhost:4566/sample-bucket/test.txt
<?xml version='1.0' encoding='utf-8'?>
<Error><Code>InvalidRange</Code><Message>The requested range is not satisfiable</Message><RequestId>aa8a2346-5dc0-4728-971c-a74839b3f1b0</RequestId><ActualObjectSize>12</ActualObjectSize><RangeRequested>bytes=1-0</RangeRequested></Error>

Environment

- OS: Ubuntu 20.04
- LocalStack: 2.2.0

Anything else?

No response

Metadata

Metadata

Assignees

Labels

aws:s3Amazon Simple Storage Servicestatus: resolved/fixedResolved with a fix or an implementationtype: bugBug report

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions