mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-12-23 22:11:10 +02:00
28 lines
772 B
Go
28 lines
772 B
Go
package security
|
|
|
|
// Security options (part of processing options)
|
|
type Options struct {
|
|
MaxSrcResolution int
|
|
MaxSrcFileSize int
|
|
MaxAnimationFrames int
|
|
MaxAnimationFrameResolution int
|
|
MaxResultDimension int
|
|
}
|
|
|
|
// CheckDimensions checks if the given dimensions are within the allowed limits
|
|
func (o *Options) CheckDimensions(width, height, frames int) error {
|
|
frames = max(frames, 1)
|
|
|
|
if frames > 1 && o.MaxAnimationFrameResolution > 0 {
|
|
if width*height > o.MaxAnimationFrameResolution {
|
|
return newImageResolutionError("Source image frame resolution is too big")
|
|
}
|
|
} else {
|
|
if width*height*frames > o.MaxSrcResolution {
|
|
return newImageResolutionError("Source image resolution is too big")
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|