mirror of
https://github.com/go-gitea/gitea
synced 2025-07-09 20:17:21 +00:00
Limit uploaded avatar image-size to 4096x3072 by default (#4353)
This commit is contained in:
committed by
Lauris BH
parent
69796ddd64
commit
cbee921c28
@ -433,6 +433,17 @@ func (u *User) IsPasswordSet() bool {
|
||||
// UploadAvatar saves custom avatar for user.
|
||||
// FIXME: split uploads to different subdirs in case we have massive users.
|
||||
func (u *User) UploadAvatar(data []byte) error {
|
||||
imgCfg, _, err := image.DecodeConfig(bytes.NewReader(data))
|
||||
if err != nil {
|
||||
return fmt.Errorf("DecodeConfig: %v", err)
|
||||
}
|
||||
if imgCfg.Width > setting.AvatarMaxWidth {
|
||||
return fmt.Errorf("Image width is to large: %d > %d", imgCfg.Width, setting.AvatarMaxWidth)
|
||||
}
|
||||
if imgCfg.Height > setting.AvatarMaxHeight {
|
||||
return fmt.Errorf("Image height is to large: %d > %d", imgCfg.Height, setting.AvatarMaxHeight)
|
||||
}
|
||||
|
||||
img, _, err := image.Decode(bytes.NewReader(data))
|
||||
if err != nil {
|
||||
return fmt.Errorf("Decode: %v", err)
|
||||
|
Reference in New Issue
Block a user