mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
https://mattermost.atlassian.net/browse/MM-36271 ```release-note We bump the major version to 6.0 ```
33 lines
825 B
Go
33 lines
825 B
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package app
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
|
|
"github.com/mattermost/mattermost-server/v6/app/imaging"
|
|
)
|
|
|
|
func checkImageResolutionLimit(w, h int) error {
|
|
// 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)
|
|
imageRes := int64(w) * int64(h)
|
|
if imageRes > maxImageRes {
|
|
return fmt.Errorf("image resolution is too high: %d, max allowed is %d", imageRes, maxImageRes)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func checkImageLimits(imageData io.Reader) error {
|
|
w, h, err := imaging.GetDimensions(imageData)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to get image dimensions: %w", err)
|
|
}
|
|
|
|
return checkImageResolutionLimit(w, h)
|
|
}
|