options.go 772 B

123456789101112131415161718192021222324252627
  1. package security
  2. // Security options (part of processing options)
  3. type Options struct {
  4. MaxSrcResolution int
  5. MaxSrcFileSize int
  6. MaxAnimationFrames int
  7. MaxAnimationFrameResolution int
  8. MaxResultDimension int
  9. }
  10. // CheckDimensions checks if the given dimensions are within the allowed limits
  11. func (o *Options) CheckDimensions(width, height, frames int) error {
  12. frames = max(frames, 1)
  13. if frames > 1 && o.MaxAnimationFrameResolution > 0 {
  14. if width*height > o.MaxAnimationFrameResolution {
  15. return newImageResolutionError("Source image frame resolution is too big")
  16. }
  17. } else {
  18. if width*height*frames > o.MaxSrcResolution {
  19. return newImageResolutionError("Source image resolution is too big")
  20. }
  21. }
  22. return nil
  23. }