-
-
Notifications
You must be signed in to change notification settings - Fork 6.1k
fix attachment file size limit in server backend #35519
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
base: main
Are you sure you want to change the base?
Conversation
fix go-gitea#35512 Signed-off-by: a1012112796 <[email protected]>
CI fail is related:
Also, it's probably better to have a status 413 returned if the size is too large |
Signed-off-by: a1012112796 <[email protected]>
|
||
// Create a new attachment and save the file | ||
attach, err := attachment_service.UploadAttachment(ctx, content, setting.Repository.Release.AllowedTypes, size, &repo_model.Attachment{ | ||
attach, err := attachment_service.UploadAttachment(ctx, content, setting.Repository.Release.AllowedTypes, setting.Attachment.MaxSize<<20, size, &repo_model.Attachment{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are at least 2 "attachment max size" config options.
If you always use setting.Attachment.MaxSize
, at least one is wrong
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why? looks they are all same in curent design. hasn't found anything like setting.Repository.Release.MaxSize
.
ref:
gitea/services/context/upload/upload.go
Lines 90 to 114 in 0b706b0
// AddUploadContext renders template values for dropzone | |
func AddUploadContext(ctx *context.Context, uploadType string) { | |
switch uploadType { | |
case "release": | |
ctx.Data["UploadUrl"] = ctx.Repo.RepoLink + "/releases/attachments" | |
ctx.Data["UploadRemoveUrl"] = ctx.Repo.RepoLink + "/releases/attachments/remove" | |
ctx.Data["UploadLinkUrl"] = ctx.Repo.RepoLink + "/releases/attachments" | |
ctx.Data["UploadAccepts"] = strings.ReplaceAll(setting.Repository.Release.AllowedTypes, "|", ",") | |
ctx.Data["UploadMaxFiles"] = setting.Attachment.MaxFiles | |
ctx.Data["UploadMaxSize"] = setting.Attachment.MaxSize | |
case "comment": | |
ctx.Data["UploadUrl"] = ctx.Repo.RepoLink + "/issues/attachments" | |
ctx.Data["UploadRemoveUrl"] = ctx.Repo.RepoLink + "/issues/attachments/remove" | |
if len(ctx.PathParam("index")) > 0 { | |
ctx.Data["UploadLinkUrl"] = ctx.Repo.RepoLink + "/issues/" + url.PathEscape(ctx.PathParam("index")) + "/attachments" | |
} else { | |
ctx.Data["UploadLinkUrl"] = ctx.Repo.RepoLink + "/issues/attachments" | |
} | |
ctx.Data["UploadAccepts"] = strings.ReplaceAll(setting.Attachment.AllowedTypes, "|", ",") | |
ctx.Data["UploadMaxFiles"] = setting.Attachment.MaxFiles | |
ctx.Data["UploadMaxSize"] = setting.Attachment.MaxSize | |
default: | |
setting.PanicInDevOrTesting("Invalid upload type: %s", uploadType) | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh you are right, release upload shares the same attachment max size with comment attachment, but doesn't share some other settings .....
It seems to be another (unrelated) legacy problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update: the problem I mentioned "There are at least 2 "attachment max size" config options." is still there. See my latest comment for UploadFileToServer
, there is no limit check either.
last call @go-gitea/technical-oversight-committee |
Co-authored-by: 6543 <[email protected]> Signed-off-by: Lunny Xiao <[email protected]>
@6543 any proof? If no, revert |
I'll revert it for now as i did not have time to write one jet to test stuff |
Even if you have 100 years, there will be no proof. Golang HTTP packages's FormFile guarantees that the |
well did not know/read that docu jet but I should ... |
There are still problems:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
errors.Is dont work now
creating custom errors is fine and all but we should work with golangs error handling system witch means that we should cover unwrap and is interface
What do you mean by "errors.Is dont work now"? |
i will have time tomorrow, review via mobule is horrible |
fix #35512