toeverything/AFFiNE · error · napi::Error

image pixel count exceeds limit

Error message

image pixel count exceeds limit

What it means

An image-decode safety guard in validate_dimensions: after the width/height are non-zero and within MAX_IMAGE_DIMENSION, this fires when width * height (computed in u64 to avoid overflow) exceeds MAX_IMAGE_PIXELS. It protects the decoder from decompression-bomb images whose individual dimensions are legal but whose total pixel count would exhaust memory; the faulting input is the oversized image buffer passed to process_image_inner.

Source

Thrown at packages/backend/native/src/image.rs:96

}

fn read_dimensions(input: &[u8], format: ImageFormat) -> AnyResult<(u32, u32)> {
  ImageReader::with_format(Cursor::new(input), format)
    .into_dimensions()
    .context("failed to decode image")
}

fn validate_dimensions(width: u32, height: u32) -> AnyResult<()> {
  if width == 0 || height == 0 {
    bail!("failed to decode image");
  }

  if width > MAX_IMAGE_DIMENSION || height > MAX_IMAGE_DIMENSION {
    bail!("image dimensions exceed limit");
  }

  if u64::from(width) * u64::from(height) > MAX_IMAGE_PIXELS {
    bail!("image pixel count exceeds limit");
  }

  Ok(())
}

fn decode_image(input: &[u8], format: ImageFormat) -> AnyResult<DynamicImage> {
  Ok(match format {
    ImageFormat::Gif => {
      let decoder = GifDecoder::new(Cursor::new(input)).context("failed to decode image")?;
      let frame = decoder
        .into_frames()
        .next()
        .transpose()
        .context("failed to decode image")?
        .context("image does not contain any frames")?;
      DynamicImage::ImageRgba8(frame.into_buffer())
    }
    ImageFormat::Png => {

View on GitHub (pinned to b4c8548c09)

Solutions

  1. Resize the image to reduce total pixel count.
  2. Process the image in tiles if supported.
Defensive patterns

Strategy: validation

When it happens

Trigger: Raised in validate_dimensions when width multiplied by height exceeds MAX_IMAGE_PIXELS, guarding against decompression bombs.

Common situations: The image's total pixel count is above the safety cap even though each dimension may look acceptable. Reduce resolution before upload.


AI-assisted analysis of toeverything/AFFiNE@b4c8548c09 (2026-08-18). Data as JSON: /api/errors/1b9e9c657490d951. Report an issue: GitHub.