apache/answer · warning

image size too large

Error message

image size too large

What it means

Raised at pkg/checker/file_type.go:107 when imageSizeTooLarge returns true, i.e. the decoded image header's Width*Height exceeds maxImageMegapixel. This is a resource-protection guard preventing memory-exhaustion (image bombing) from huge but valid images; full decode of a giant image would consume large amounts of RAM.

Source

Thrown at pkg/checker/file_type.go:107

// registered by transitive dependencies.
func formatSpecificConfigCheck(file io.Reader, ext string, maxImageMegapixel int) error {
	var config image.Config
	var err error
	switch ext {
	case "jpg", "jpeg":
		config, err = jpeg.DecodeConfig(file)
	case "png":
		config, err = png.DecodeConfig(file)
	case "gif":
		config, err = gif.DecodeConfig(file)
	default:
		return fmt.Errorf("unsupported image format: %s", ext)
	}
	if err != nil {
		return fmt.Errorf("decode image config error: %v", err)
	}
	if imageSizeTooLarge(config, maxImageMegapixel) {
		return fmt.Errorf("image size too large")
	}
	return nil
}

// formatSpecificImageCheck fully decodes the image using a format-specific decoder.
func formatSpecificImageCheck(file io.Reader, ext string, _ int) error {
	var err error
	switch ext {
	case "jpg", "jpeg":
		_, err = jpeg.Decode(file)
	case "png":
		_, err = png.Decode(file)
	case "gif":
		_, err = gif.Decode(file)
	default:
		return fmt.Errorf("unsupported image format: %s", ext)
	}
	if err != nil {

View on GitHub (pinned to 3b9f137061)

Solutions

  1. Resize the image client-side before upload (e.g. canvas/blob downsizing)
  2. Raise the maxImageMegapixel configuration if the limit is too strict
  3. Show the user a clear message that the image resolution exceeds the allowed maximum
  4. Pre-check image dimensions in the browser before upload using Image.naturalWidth/naturalHeight

Example fix

// before: upload then fail
upload(file) // -> "image size too large"
// after: client-side pre-check
const img = new Image(); img.onload = () => {
  if (img.naturalWidth * img.naturalHeight > 50_000_000) resizeBeforeUpload(file);
  else upload(file);
};
Defensive patterns

Strategy: validation

Validate before calling

// client-side dimension pre-check
const img = new Image();
img.onload = () => {
  if (img.naturalWidth * img.naturalHeight > 50_000_000) reject('image too large');
};
img.src = URL.createObjectURL(file);

Type guard

func isImageTooLarge(w, h, maxMP int) bool { return w*h > maxMP }

Try / catch

if !checker.DecodeAndCheckImageFile(path, maxMP) {
	return fmt.Errorf("image dimensions exceed the %d megapixel limit", maxMP)
}

Prevention

When it happens

Trigger: A valid jpg/jpeg/png/gif passes formatSpecificConfigCheck decoding but its pixel dimensions exceed the configured maxImageMegapixel limit (Width*Height > limit).

Common situations: Users upload panoramic or high-resolution photos (e.g. 10000x10000), or maxImageMegapixel is configured too low for legitimate use.

Related errors


AI-assisted analysis of apache/answer@3b9f137061 (2026-09-05). Data as JSON: /api/errors/1de9bac185b0f1a8. Report an issue: GitHub.