{"record":{"id":"ba81e870a04f4e3d","repo":"siyuan-note/siyuan","slug":"unsupported-or-invalid-image","errorCode":null,"errorMessage":"unsupported or invalid image: ","messagePattern":"unsupported or invalid image: ","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/openai.go","lineNumber":639,"sourceCode":"func PrepareModelImage(data []byte, maxBytes, maxPixels, maxEdge int) (PreparedImage, error) {\n\tif len(data) == 0 {\n\t\treturn PreparedImage{}, errors.New(\"image data is empty\")\n\t}\n\tif maxBytes > 0 && len(data) > maxBytes {\n\t\treturn PreparedImage{}, fmt.Errorf(\"image exceeds size limit: %d bytes\", maxBytes)\n\t}\n\tmimeType := mimetype.Detect(data).String()\n\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),","sourceCodeStart":621,"sourceCodeEnd":657,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/util/openai.go#L621-L657","documentation":"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.","triggerScenarios":"Truncated download (e.g. partial PNG header); file with a valid magic but corrupt IHDR/SOIF; copy interrupted mid-file; exFAT/FAT corruption.","commonSituations":"Partial image download; copy/paste interrupted; asset exported with a broken header by a buggy tool.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if _, _, err := image.DecodeConfig(bytes.NewReader(data)); err != nil {\n    return errors.New(\"image header unreadable; re-export the asset\")\n}","typeGuard":null,"tryCatchPattern":"img, err := util.PrepareModelImage(data, maxB, maxP, maxE)\nif err != nil {\n    log.Warnf(\"drop unreadable image from vision context: %s\", err)\n    continue\n}","preventionTips":["Validate image headers before sending","Re-export corrupt assets from a trusted tool"],"tags":["ai","multimodal","image","go","corruption"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}