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"
|
2022-11-29 14:25:38 +02:00
|
|
|
"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")
|
2022-11-29 14:25:38 +02:00
|
|
|
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 {
|
2022-11-29 14:25:38 +02:00
|
|
|
frames = imath.Max(frames, 1)
|
|
|
|
|
2023-02-23 20:11:44 +02:00
|
|
|
if frames > 1 && opts.MaxAnimationFrameResolution > 0 {
|
|
|
|
if width*height > opts.MaxAnimationFrameResolution {
|
2022-11-29 14:25:38 +02:00
|
|
|
return ErrSourceFrameResolutionTooBig
|
|
|
|
}
|
|
|
|
} else {
|
2023-02-23 20:11:44 +02:00
|
|
|
if width*height*frames > opts.MaxSrcResolution {
|
2022-11-29 14:25:38 +02:00
|
|
|
return ErrSourceResolutionTooBig
|
|
|
|
}
|
2021-04-26 13:52:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|