1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2024-12-04 09:42:31 +02:00
imgproxy/security/image_size.go

26 lines
726 B
Go
Raw Normal View History

2021-04-26 13:52:50 +02:00
package security
import (
2021-09-30 16:23:30 +02:00
"github.com/imgproxy/imgproxy/v3/ierrors"
"github.com/imgproxy/imgproxy/v3/imath"
2021-04-26 13:52:50 +02:00
)
var ErrSourceResolutionTooBig = ierrors.New(422, "Source image resolution is too big", "Invalid source image")
var ErrSourceFrameResolutionTooBig = ierrors.New(422, "Source image frame resolution is too big", "Invalid source image")
2021-04-26 13:52:50 +02:00
2023-02-23 20:11:44 +02:00
func CheckDimensions(width, height, frames int, opts Options) error {
frames = imath.Max(frames, 1)
2023-02-23 20:11:44 +02:00
if frames > 1 && opts.MaxAnimationFrameResolution > 0 {
if width*height > opts.MaxAnimationFrameResolution {
return ErrSourceFrameResolutionTooBig
}
} else {
2023-02-23 20:11:44 +02:00
if width*height*frames > opts.MaxSrcResolution {
return ErrSourceResolutionTooBig
}
2021-04-26 13:52:50 +02:00
}
return nil
}