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

Disallow composing more than 32 objects at once #1254

Merged
merged 1 commit into from
Jul 30, 2023
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
8 changes: 8 additions & 0 deletions fakestorage/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,14 @@ func (s *Server) composeObject(r *http.Request) jsonResponse {
}
}

const maxComposeObjects = 32
if len(composeRequest.SourceObjects) > maxComposeObjects {
return jsonResponse{
status: http.StatusBadRequest,
errorMessage: fmt.Sprintf("The number of source components provided (%d) exceeds the maximum (%d)", len(composeRequest.SourceObjects), maxComposeObjects),
}
}

sourceNames := make([]string, 0, len(composeRequest.SourceObjects))
for _, n := range composeRequest.SourceObjects {
sourceNames = append(sourceNames, n.Name)
Expand Down
15 changes: 15 additions & 0 deletions fakestorage/object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1992,27 +1992,39 @@ func TestServiceClientComposeObject(t *testing.T) {
destObjectName string
sourceObjectNames []string
expectedContent string
expectedError string
}{
{
"destination file doesn't exist",
"first-bucket",
"files/some-file.txt",
[]string{"files/source1.txt", "files/source2.txt"},
source1Content + source2Content,
"",
},
{
"destination file already exists",
"first-bucket",
"files/destination.txt",
[]string{"files/source1.txt", "files/source2.txt"},
source1Content + source2Content,
"",
},
{
"destination is a source",
"first-bucket",
"files/source3.txt",
[]string{"files/source2.txt", "files/source3.txt"},
source2Content + source3Content,
"",
},
{
"too many objects at once",
"first-bucket",
"files/destination.txt",
[]string{"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33"},
"",
"googleapi: Error 400: The number of source components provided (33) exceeds the maximum (32)",
},
}
for _, test := range tests {
Expand All @@ -2033,6 +2045,9 @@ func TestServiceClientComposeObject(t *testing.T) {
composer.Metadata = map[string]string{"baz": "qux"}
attrs, err := composer.Run(context.TODO())
if err != nil {
if err.Error() == test.expectedError {
return
}
t.Fatal(err)
}

Expand Down