{"record":{"id":"8026150b9136dc0b","repo":"toeverything/AFFiNE","slug":"max-edge-must-be-greater-than-0","errorCode":null,"errorMessage":"max_edge must be greater than 0","messagePattern":"max_edge must be greater than 0","errorType":"validation","errorClass":"napi::Error","httpStatus":null,"severity":"error","filePath":"packages/backend/native/src/image.rs","lineNumber":57,"sourceCode":"  }\n\n  fn resolve(&mut self, _: Env, output: Self::Output) -> Result<Self::JsValue> {\n    Ok(output.into())\n  }\n}\n\n#[napi]\npub fn process_image(input: Buffer, max_edge: u32, keep_exif: bool) -> AsyncTask<AsyncProcessImageTask> {\n  AsyncTask::new(AsyncProcessImageTask {\n    input: input.to_vec(),\n    max_edge,\n    keep_exif,\n  })\n}\n\nfn process_image_inner(input: &[u8], max_edge: u32, keep_exif: bool) -> AnyResult<Vec<u8>> {\n  if max_edge == 0 {\n    bail!(\"max_edge must be greater than 0\");\n  }\n\n  let format = image::guess_format(input).context(\"unsupported image format\")?;\n  let (width, height) = read_dimensions(input, format)?;\n  validate_dimensions(width, height)?;\n  let mut image = decode_image(input, format)?;\n  let orientation = read_orientation(input, format)?;\n  image.apply_orientation(orientation);\n\n  if image.width().max(image.height()) > max_edge {\n    image = image.resize(max_edge, max_edge, FilterType::Lanczos3);\n  }\n\n  let mut output = encode_webp_lossy(&image.into_rgba8())?;\n\n  if keep_exif {\n    preserve_exif(input, format, &mut output)?;\n  }","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/b4c8548c09da21b2898443559a5b846f0ccf5dd8/packages/backend/native/src/image.rs#L39-L75","documentation":"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.","triggerScenarios":"Raised in process_image when the caller passes max_edge of 0, before any decoding work is done.","commonSituations":"Caller supplied a zero resize bound. Pass a positive max_edge value when invoking image processing.","solutions":["Pass a max_edge value greater than 0.","Validate resize parameters before calling the image API."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"b4c8548c09da21b2898443559a5b846f0ccf5dd8","analyzedAt":"2026-08-18T21:16:52.546Z","contentChangedAt":"2026-08-18T21:16:52.546Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}