toeverything/AFFiNE · error · napi::Error

max_edge must be greater than 0

Error message

max_edge must be greater than 0

What it means

Validation at the start of process_image_inner: the caller passed max_edge == 0 to the process_image NAPI binding, which would make target scaling meaningless or divide-by-zero; the work bails with this message before any decoding.

Source

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

  }

  fn resolve(&mut self, _: Env, output: Self::Output) -> Result<Self::JsValue> {
    Ok(output.into())
  }
}

#[napi]
pub fn process_image(input: Buffer, max_edge: u32, keep_exif: bool) -> AsyncTask<AsyncProcessImageTask> {
  AsyncTask::new(AsyncProcessImageTask {
    input: input.to_vec(),
    max_edge,
    keep_exif,
  })
}

fn process_image_inner(input: &[u8], max_edge: u32, keep_exif: bool) -> AnyResult<Vec<u8>> {
  if max_edge == 0 {
    bail!("max_edge must be greater than 0");
  }

  let format = image::guess_format(input).context("unsupported image format")?;
  let (width, height) = read_dimensions(input, format)?;
  validate_dimensions(width, height)?;
  let mut image = decode_image(input, format)?;
  let orientation = read_orientation(input, format)?;
  image.apply_orientation(orientation);

  if image.width().max(image.height()) > max_edge {
    image = image.resize(max_edge, max_edge, FilterType::Lanczos3);
  }

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

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

View on GitHub (pinned to b4c8548c09)

Solutions

  1. Pass a max_edge value greater than 0.
  2. Validate resize parameters before calling the image API.
Defensive patterns

Strategy: validation

When it happens

Trigger: Raised in process_image when the caller passes max_edge of 0, before any decoding work is done.

Common situations: Caller supplied a zero resize bound. Pass a positive max_edge value when invoking image processing.


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