toeverything/AFFiNE · error · napi::Error

failed to decode image

Error message

failed to decode image

What it means

Image validation guard: either reading the dimensions of the encoded input failed (corrupt/unsupported data, wrapped context from read_dimensions) or validate_dimensions saw a zero width/height; both mean the bytes are not a decodable image.

Source

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

  let mut output = encode_webp_lossy(&image.into_rgba8())?;

  if keep_exif {
    preserve_exif(input, format, &mut output)?;
  }

  Ok(output)
}

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

View on GitHub (pinned to b4c8548c09)

Solutions

  1. Check the image data is a supported, non-corrupt format.
  2. Re-acquire or convert the image and retry.
Defensive patterns

Strategy: validation

When it happens

Trigger: Raised when reading image dimensions fails, when decoded width or height is zero, or when a GIF frame fails to decode from the input bytes.

Common situations: The uploaded file is truncated, corrupt, or not a valid image of its detected format. Ask the user to re-export or re-upload the image.

Understand the failure class


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