{"record":{"id":"76e555b85510b86b","repo":"toeverything/AFFiNE","slug":"failed-to-decode-image","errorCode":null,"errorMessage":"failed to decode image","messagePattern":"failed to decode image","errorType":"exception","errorClass":"napi::Error","httpStatus":null,"severity":"error","filePath":"packages/backend/native/src/image.rs","lineNumber":88,"sourceCode":"\n  let mut output = encode_webp_lossy(&image.into_rgba8())?;\n\n  if keep_exif {\n    preserve_exif(input, format, &mut output)?;\n  }\n\n  Ok(output)\n}\n\nfn read_dimensions(input: &[u8], format: ImageFormat) -> AnyResult<(u32, u32)> {\n  ImageReader::with_format(Cursor::new(input), format)\n    .into_dimensions()\n    .context(\"failed to decode image\")\n}\n\nfn validate_dimensions(width: u32, height: u32) -> AnyResult<()> {\n  if width == 0 || height == 0 {\n    bail!(\"failed to decode image\");\n  }\n\n  if width > MAX_IMAGE_DIMENSION || height > MAX_IMAGE_DIMENSION {\n    bail!(\"image dimensions exceed limit\");\n  }\n\n  if u64::from(width) * u64::from(height) > MAX_IMAGE_PIXELS {\n    bail!(\"image pixel count exceeds limit\");\n  }\n\n  Ok(())\n}\n\nfn decode_image(input: &[u8], format: ImageFormat) -> AnyResult<DynamicImage> {\n  Ok(match format {\n    ImageFormat::Gif => {\n      let decoder = GifDecoder::new(Cursor::new(input)).context(\"failed to decode image\")?;\n      let frame = decoder","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/b4c8548c09da21b2898443559a5b846f0ccf5dd8/packages/backend/native/src/image.rs#L70-L106","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check the image data is a supported, non-corrupt format.","Re-acquire or convert the image and retry."],"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"}