Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid IncompleteRead on completed partial reads #1827

Merged
merged 2 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fakestorage/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ func (s *Server) handleRange(obj StreamingObject, r *http.Request) (ranged bool,
// Length: 40, Range: bytes=50-
case start >= obj.Size:
// This IS a ranged request, but it ISN'T satisfiable.
return true, 0, 0, false
return true, 0, -1, false
// Negative range, ignore range and return all content.
// Examples:
// Length: 40, Range: bytes=30-20
Expand Down
28 changes: 28 additions & 0 deletions fakestorage/object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,34 @@ func TestServerClientObjectRangeReader(t *testing.T) {
})
}

func TestServerClientObjectRangeReaderInvalid(t *testing.T) {
const (
bucketName = "some-bucket"
objectName = "items/data.txt"
content = "some really nice but long content stored in my object"
contentType = "text/plain; charset=iso-8859"
)
objs := []Object{
{
ObjectAttrs: ObjectAttrs{
BucketName: bucketName,
Name: objectName,
ContentType: contentType,
},
Content: []byte(content),
},
}

runServersTest(t, runServersOptions{objs: objs}, func(t *testing.T, server *Server) {
client := server.Client()
objHandle := client.Bucket(bucketName).Object(objectName)
_, err := objHandle.NewRangeReader(context.TODO(), 500, 10)
if err == nil {
t.Fatal("unexpected <nil> error")
}
})
}

func TestServerClientObjectReaderAfterCreateObject(t *testing.T) {
const (
bucketName = "staging-bucket"
Expand Down
Loading