MM-20934: Fixing int overflow in 32 bits on MaxImageSize check (#14280)

* MM-20934: Fixing int overflow in 32 bits on MaxImageSize check

* Adding comments explaining the casting and the bug fixed there

* Apply suggestions from code review

Co-Authored-By: Juho Nurminen <juhonurm@gmail.com>

* Fixing store layers

Co-authored-by: Juho Nurminen <juhonurm@gmail.com>
Этот коммит содержится в:
Jesús Espino
2020-04-16 15:23:27 +02:00
коммит произвёл GitHub
родитель cd63c1153f
Коммит 7ea637be10
5 изменённых файлов: 23 добавлений и 7 удалений

Просмотреть файл

@@ -833,7 +833,10 @@ func (a *App) SetProfileImageFromMultiPartFile(userId string, file multipart.Fil
if err != nil {
return model.NewAppError("SetProfileImage", "api.user.upload_profile_user.decode_config.app_error", nil, err.Error(), http.StatusBadRequest)
}
if config.Width*config.Height > model.MaxImageSize {
// This casting is done to prevent overflow on 32 bit systems (not needed
// in 64 bits systems because images can't have more than 32 bits height or
// width)
if int64(config.Width)*int64(config.Height) > model.MaxImageSize {
return model.NewAppError("SetProfileImage", "api.user.upload_profile_user.too_large.app_error", nil, "", http.StatusBadRequest)
}