Documentation
¶
Overview ¶
Package imagelimit bounds the decoded size of untrusted images before a full decode allocates memory for them. A few kilobytes of compressed data can declare billions of pixels; reading only the header keeps the check cheap and lets callers refuse the image before paying for it.
Index ¶
Constants ¶
const MaxPixels = 50_000_000
MaxPixels is the largest decoded pixel count accepted for any image the server decodes itself: EXIF stripping on upload and thumbnail generation on read. 50 megapixels decodes to about 200 MiB of RGBA.
Variables ¶
var ErrTooLarge = errors.Errorf("image dimensions exceed maximum of %d pixels", MaxPixels)
ErrTooLarge reports an image whose declared dimensions exceed MaxPixels.
Functions ¶
func CheckDimensions ¶
CheckDimensions reports whether width×height fits within MaxPixels.
func CheckReader ¶
CheckReader reads the image header from r and reports whether the declared dimensions fit within MaxPixels. Formats that the image registry cannot size are allowed through so the full decoder decides; the caller must then be prepared for that decode to fail. The reader is consumed; rewind it before decoding.
Types ¶
This section is empty.