imagelimit

package
v0.31.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 19, 2026 License: MIT Imports: 6 Imported by: 0

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

View Source
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

View Source
var ErrTooLarge = errors.Errorf("image dimensions exceed maximum of %d pixels", MaxPixels)

ErrTooLarge reports an image whose declared dimensions exceed MaxPixels.

Functions

func CheckDimensions

func CheckDimensions(width, height int) error

CheckDimensions reports whether width×height fits within MaxPixels.

func CheckReader

func CheckReader(r io.Reader) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL