siyuan-note/siyuan · error
unsupported or invalid image:
Error message
unsupported or invalid image:
What it means
image.DecodeConfig (header decode) failed after the mime check passed. Causes: corrupt header, truncated file, or a header that decodes but is structurally invalid. The underlying decoder error is appended.
Source
Thrown at kernel/util/openai.go:639
func PrepareModelImage(data []byte, maxBytes, maxPixels, maxEdge int) (PreparedImage, error) {
if len(data) == 0 {
return PreparedImage{}, errors.New("image data is empty")
}
if maxBytes > 0 && len(data) > maxBytes {
return PreparedImage{}, fmt.Errorf("image exceeds size limit: %d bytes", maxBytes)
}
mimeType := mimetype.Detect(data).String()
if strings.Contains(mimeType, "svg") || bytes.Contains(bytes.ToLower(data[:min(len(data), 512)]), []byte("<svg")) {
return PreparedImage{}, errors.New("SVG images are not accepted by multimodal models")
}
switch mimeType {
case "image/gif", "image/jpeg", "image/png", "image/webp":
default:
return PreparedImage{}, fmt.Errorf("unsupported image type: %s", mimeType)
}
config, _, err := image.DecodeConfig(bytes.NewReader(data))
if err != nil {
return PreparedImage{}, errors.New("unsupported or invalid image: " + err.Error())
}
if config.Width < 1 || config.Height < 1 || maxPixels > 0 && int64(config.Width)*int64(config.Height) > int64(maxPixels) {
return PreparedImage{}, fmt.Errorf("image exceeds pixel limit: %d", maxPixels)
}
decoded, err := imaging.Decode(bytes.NewReader(data), imaging.AutoOrientation(true))
if err != nil {
return PreparedImage{}, errors.New("decode image failed: " + err.Error())
}
bounds := decoded.Bounds()
needsResize := maxEdge > 0 && (bounds.Dx() > maxEdge || bounds.Dy() > maxEdge)
if !needsResize && bounds.Dx() == config.Width && bounds.Dy() == config.Height && mimeType != "image/gif" {
return PreparedImage{
Data: data,
MIMEType: mimeType,
Width: bounds.Dx(),
Height: bounds.Dy(),
SourceSize: len(data),View on GitHub (pinned to 251596fc0d)
Solutions
- Re-download or re-copy the asset.
- Re-save the image with an editor (rewrites a clean header).
- Convert to PNG/JPEG through a trusted tool.
- Drop the unreadable asset from the vision context.
Defensive patterns
Strategy: try-catch
Validate before calling
if _, _, err := image.DecodeConfig(bytes.NewReader(data)); err != nil {
return errors.New("image header unreadable; re-export the asset")
} Try / catch
img, err := util.PrepareModelImage(data, maxB, maxP, maxE)
if err != nil {
log.Warnf("drop unreadable image from vision context: %s", err)
continue
} Prevention
- Validate image headers before sending
- Re-export corrupt assets from a trusted tool
When it happens
Trigger: Truncated download (e.g. partial PNG header); file with a valid magic but corrupt IHDR/SOIF; copy interrupted mid-file; exFAT/FAT corruption.
Common situations: Partial image download; copy/paste interrupted; asset exported with a broken header by a buggy tool.
Related errors
- decode image failed:
- image data is empty
- image exceeds size limit: %d bytes
- SVG images are not accepted by multimodal models
- unsupported image type: %s
AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12).
Data as JSON: /api/errors/ba81e870a04f4e3d.
Report an issue: GitHub.