meta_dimensions.go 834 B

12345678910111213141516171819202122232425262728
  1. package security
  2. import (
  3. "github.com/imgproxy/imgproxy/v3/imagemeta"
  4. "github.com/imgproxy/imgproxy/v3/imath"
  5. )
  6. // CheckDimensions checks the given dimensions against the security options
  7. func CheckDimensions(width, height, frames int, opts Options) error {
  8. frames = imath.Max(frames, 1)
  9. if frames > 1 && opts.MaxAnimationFrameResolution > 0 {
  10. if width*height > opts.MaxAnimationFrameResolution {
  11. return newImageResolutionError("Source image frame resolution is too big")
  12. }
  13. } else {
  14. if width*height*frames > opts.MaxSrcResolution {
  15. return newImageResolutionError("Source image resolution is too big")
  16. }
  17. }
  18. return nil
  19. }
  20. // CheckMeta checks the image metadata against the security options
  21. func CheckMeta(meta imagemeta.Meta, opts Options) error {
  22. return CheckDimensions(meta.Width(), meta.Height(), 1, opts)
  23. }