{"record":{"id":"6c06297274388301","repo":"siyuan-note/siyuan","slug":"image-exceeds-pixel-limit-d","errorCode":null,"errorMessage":"image exceeds pixel limit: %d","messagePattern":"image exceeds pixel limit: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/openai.go","lineNumber":642,"sourceCode":"\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),\n\t\t}, nil\n\t}\n\tif needsResize {","sourceCodeStart":624,"sourceCodeEnd":660,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/util/openai.go#L624-L660","documentation":"Decoded dimensions have width or height < 1 (invalid) OR width*height exceeds maxPixels. The guard prevents memory exhaustion and respects provider pixel caps.","triggerScenarios":"A very high-resolution photo (e.g. 8000x8000) exceeds the provider's megapixel cap; or a degenerate image whose header reports zero/tiny dimensions.","commonSituations":"Full-resolution DSLR or phone panoramas; stitched images; malformed header reporting tiny dimensions.","solutions":["Downscale the source to within the provider's pixel budget before sending.","Reject over-large images at the UI.","Re-export malformed headers via an image editor."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"cfg, _, _ := image.DecodeConfig(bytes.NewReader(data))\nif maxPixels > 0 && int64(cfg.Width)*int64(cfg.Height) > int64(maxPixels) {\n    return errors.New(\"downscale the image before sending\")\n}","typeGuard":"func WithinPixelLimit(data []byte, maxPixels int) bool {\n    cfg, _, err := image.DecodeConfig(bytes.NewReader(data))\n    if err != nil { return false }\n    return maxPixels <= 0 || int64(cfg.Width)*int64(cfg.Height) <= int64(maxPixels)\n}","tryCatchPattern":null,"preventionTips":["Downscale large photos before attaching","Enforce the pixel budget in the UI"],"tags":["ai","multimodal","image","go","size-limit"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}