@@ -13,21 +13,32 @@ import (
1313
1414 repo_model "code.gitea.io/gitea/models/repo"
1515 "code.gitea.io/gitea/modules/git"
16+ "code.gitea.io/gitea/modules/setting"
1617 api "code.gitea.io/gitea/modules/structs"
1718 "code.gitea.io/gitea/modules/util"
1819)
1920
20- func GetContentsListFromTrees (ctx context.Context , repo * repo_model.Repository , branch string , treeNames []string ) []* api.ContentsResponse {
21+ func GetContentsListFromTrees (ctx context.Context , repo * repo_model.Repository , branch string , treeNames []string ) ( []* api.ContentsResponse , error ) {
2122 files := []* api.ContentsResponse {}
23+ var size int64 = 0
2224 for _ , file := range treeNames {
2325 fileContents , _ := GetContents (ctx , repo , file , branch , false ) // ok if fails, then will be nil
26+ if * fileContents .Content != "" {
27+ size += fileContents .Size // if content isn't empty (e. g. due to the single blob being too large), add file size to response size
28+ }
29+ if size > setting .API .DefaultMaxResponseSize {
30+ return nil , fmt .Errorf ("the combined size of the requested blobs exceeds the per-request limit set by the server administrator" )
31+ }
2432 files = append (files , fileContents )
2533 }
26- return files
34+ return files , nil
2735}
2836
2937func GetFilesResponseFromCommit (ctx context.Context , repo * repo_model.Repository , commit * git.Commit , branch string , treeNames []string ) (* api.FilesResponse , error ) {
30- files := GetContentsListFromTrees (ctx , repo , branch , treeNames )
38+ files , err := GetContentsListFromTrees (ctx , repo , branch , treeNames )
39+ if err != nil {
40+ return nil , err
41+ }
3142 fileCommitResponse , _ := GetFileCommitResponse (repo , commit ) // ok if fails, then will be nil
3243 verification := GetPayloadCommitVerification (ctx , commit )
3344 filesResponse := & api.FilesResponse {
0 commit comments