{"record":{"id":"88a6847d1525d5e2","repo":"siyuan-note/siyuan","slug":"decode-image-failed-s","errorCode":null,"errorMessage":"decode image failed: %s","messagePattern":"decode image failed: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/openai.go","lineNumber":787,"sourceCode":"\tif strings.Contains(mimeType, \"svg\") || bytes.Contains(bytes.ToLower(data[:min(len(data), 512)]), []byte(\"<svg\")) {\n\t\treturn PreparedImage{}, errors.New(\"SVG images are not accepted by multimodal models\")\n\t}\n\tswitch mimeType {\n\tcase \"image/gif\", \"image/jpeg\", \"image/png\", \"image/webp\":\n\tdefault:\n\t\treturn PreparedImage{}, fmt.Errorf(\"unsupported image type: %s\", mimeType)\n\t}\n\tconfig, _, err := image.DecodeConfig(bytes.NewReader(data))\n\tif err != nil {\n\t\treturn PreparedImage{}, errors.New(\"unsupported or invalid image: \" + err.Error())\n\t}\n\tif config.Width < 1 || config.Height < 1 || maxPixels > 0 && int64(config.Width)*int64(config.Height) > int64(maxPixels) {\n\t\treturn PreparedImage{}, fmt.Errorf(\"image exceeds pixel limit: %d\", maxPixels)\n\t}\n\n\tdecoded, err := imaging.Decode(bytes.NewReader(data), imaging.AutoOrientation(true))\n\tif err != nil {\n\t\treturn PreparedImage{}, errors.New(\"decode image failed: \" + err.Error())\n\t}\n\tbounds := decoded.Bounds()\n\tneedsResize := maxEdge > 0 && (bounds.Dx() > maxEdge || bounds.Dy() > maxEdge)\n\tif !needsResize && bounds.Dx() == config.Width && bounds.Dy() == config.Height && mimeType != \"image/gif\" {\n\t\treturn PreparedImage{\n\t\t\tData:       data,\n\t\t\tMIMEType:   mimeType,\n\t\t\tWidth:      bounds.Dx(),\n\t\t\tHeight:     bounds.Dy(),\n\t\t\tSourceSize: len(data),\n\t\t}, nil\n\t}\n\tif needsResize {\n\t\tdecoded = imaging.Fit(decoded, maxEdge, maxEdge, imaging.Lanczos)\n\t}\n\tbounds = decoded.Bounds()\n\tif mimeType == \"image/png\" || mimeType == \"image/webp\" {\n\t\tvar output bytes.Buffer","sourceCodeStart":769,"sourceCodeEnd":805,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/util/openai.go#L769-L805","documentation":"Identical message to 2211 but thrown at kernel/util/openai.go:787 after imaging.Decode (with auto-orientation applied) fails, i.e. the header parsed via DecodeConfig but the full pixel data cannot be decoded by the imaging library. The library-specific reason is appended to the message.","triggerScenarios":"Feeding an image whose full decode fails even though DecodeConfig succeeded: truncated pixel data, corrupt IDAT/scan segments, unsupported EXIF-heavy or progressive variants, or CMYK JPEGs the decoder rejects.","commonSituations":"Partially synced asset files; images stripped or mangled by an external processor; exotic JPEG variants (CMYK, lossless) or animated WebP edge cases failing imaging.Decode.","solutions":["Re-export/re-encode the image with a standard tool (e.g. convert to baseline JPEG or PNG) and retry","Check the file size against the source to detect truncation; re-sync or re-download the asset","Open the file in a viewer to confirm it is valid before sending it to the AI feature","Inspect the appended reason in the message to identify the specific decoder complaint"],"exampleFix":"// before: trusting the header parse\nimg, err := prepareImage(truncatedBytes, \"image/jpeg\", ...)\n// after: verify full decodability first\nif _, err := imaging.Decode(bytes.NewReader(truncatedBytes)); err != nil {\n    return fmt.Errorf(\"source image is corrupt: %w\", err)\n}\nimg, err := prepareImage(truncatedBytes, \"image/jpeg\", ...)","handlingStrategy":"validation","validationCode":"if _, err := imaging.Decode(bytes.NewReader(data)); err != nil {\n    return fmt.Errorf(\"source image is corrupt: %w\", err)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Full-decode the image before sending it to processing that will decode again","Compare on-disk size with the source size to catch truncation early","Re-encode suspicious images once with a standard tool (fixes most variant issues)","Keep sync/backup tooling from writing partial asset files"],"tags":["image","decoding","corrupt-file","ai"],"backgroundTag":"invalid-argument-format","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}