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 удалений

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

@@ -38,7 +38,10 @@ func (a *App) SaveBrandImage(imageData *multipart.FileHeader) *model.AppError {
return model.NewAppError("SaveBrandImage", "brand.save_brand_image.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("SaveBrandImage", "brand.save_brand_image.too_large.app_error", nil, "", http.StatusBadRequest)
}

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

@@ -55,7 +55,7 @@ const (
RotatedCCWMirrored = 7
RotatedCW = 8
MaxImageSize = 6048 * 4032 // 24 megapixels, roughly 36MB as a raw image
MaxImageSize = int64(6048 * 4032) // 24 megapixels, roughly 36MB as a raw image
ImageThumbnailWidth = 120
ImageThumbnailHeight = 100
ImageThumbnailRatio = float64(ImageThumbnailHeight) / float64(ImageThumbnailWidth)
@@ -728,7 +728,10 @@ func (t *UploadFileTask) preprocessImage() *model.AppError {
t.fileinfo.Height = config.Height
// Check dimensions before loading the whole thing into memory later on.
if t.fileinfo.Width*t.fileinfo.Height > 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(t.fileinfo.Width)*int64(t.fileinfo.Height) > MaxImageSize {
return t.newAppError("api.file.upload_file.large_image_detailed.app_error",
"", http.StatusBadRequest)
}
@@ -911,7 +914,10 @@ func (a *App) DoUploadFileExpectModification(now time.Time, rawTeamId string, ra
if info.IsImage() {
// Check dimensions before loading the whole thing into memory later on
if info.Width*info.Height > 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(info.Width)*int64(info.Height) > MaxImageSize {
err := model.NewAppError("uploadFile", "api.file.upload_file.large_image.app_error", map[string]interface{}{"Filename": filename}, "", http.StatusBadRequest)
return nil, data, err
}

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

@@ -1510,7 +1510,11 @@ func (a *App) SetTeamIconFromMultiPartFile(teamId string, file multipart.File) *
if err != nil {
return model.NewAppError("SetTeamIcon", "api.team.set_team_icon.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("SetTeamIcon", "api.team.set_team_icon.too_large.app_error", nil, "", http.StatusBadRequest)
}

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

@@ -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)
}

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

@@ -9,7 +9,7 @@ import (
)
const (
MaxImageSize = 6048 * 4032 // 24 megapixels, roughly 36MB as a raw image
MaxImageSize = int64(6048 * 4032) // 24 megapixels, roughly 36MB as a raw image
)
var (