siyuan-note/siyuan · error
unsupported custom emoji image format
Error message
unsupported custom emoji image format
What it means
Returned by normalizeCustomEmojiData as the final fallback: http.DetectContentType did not recognize the bytes as png/jpeg/gif/webp (raster=false) AND util.SanitizeSVG rejected the bytes as an SVG. The data is neither a supported raster nor a sanitizable SVG.
Source
Thrown at kernel/api/system.go:384
case "image/webp":
ext = ".webp"
default:
raster = false
}
if raster {
config, _, decodeErr := image.DecodeConfig(bytes.NewReader(data))
if decodeErr != nil || config.Width < 1 || config.Height < 1 || config.Width > 16384 || config.Height > 16384 ||
int64(config.Width)*int64(config.Height) > 100*1000*1000 {
return nil, "", fmt.Errorf("invalid custom emoji image")
}
return data, ext, nil
}
sanitizedSVG, sanitizeErr := util.SanitizeSVG(string(data))
if sanitizeErr == nil {
return []byte(sanitizedSVG), ".svg", nil
}
return nil, "", fmt.Errorf("unsupported custom emoji image format")
}
func normalizeCustomEmojiPath(name, ext string) (string, error) {
name = strings.TrimSpace(strings.ReplaceAll(name, "\\", "/"))
parts := strings.Split(name, "/")
if len(parts) == 0 {
return "", fmt.Errorf("custom emoji name must not be empty")
}
lastIndex := len(parts) - 1
switch strings.ToLower(filepath.Ext(parts[lastIndex])) {
case ".png", ".jpg", ".jpeg", ".gif", ".webp", ".svg":
parts[lastIndex] = strings.TrimSuffix(parts[lastIndex], filepath.Ext(parts[lastIndex]))
}
for i, part := range parts {
part = strings.TrimSpace(part)
if part == "" || part == "." || part == ".." {
return "", fmt.Errorf("invalid custom emoji name")View on GitHub (pinned to 251596fc0d)
Solutions
- Convert the image to one of png/jpeg/gif/webp, or to a clean hand-authored SVG.
- If the source is SVG, remove <script>, on* handlers, external hrefs, and DOCTYPE/entity declarations, then retry.
- Run the file through `file` to see its true type and re-export accordingly.
Example fix
// before // uploading a BMP file -> 'unsupported custom emoji image format' // after: convert to a supported format // convert emoji.bmp emoji.png (ImageMagick) // then upload emoji.png
Defensive patterns
Strategy: validation
Validate before calling
// Confirm the content type is one of the accepted formats before uploading
ct := http.DetectContentType(data)
switch ct {
case "image/png", "image/jpeg", "image/gif", "image/webp":
// ok raster
case "image/svg+xml", "text/xml; charset=utf-8":
// candidate SVG; ensure it sanitizes
if _, e := util.SanitizeSVG(string(data)); e != nil { return e }
default:
return fmt.Errorf("unsupported content type %s", ct)
} Prevention
- Convert BMP/TIFF/ICO/AVIF/HEIC to png or webp first.
- For SVG, remove scripts, external refs, and DOCTYPE entities before upload.
- Match the file extension to the actual content type.
When it happens
Trigger: Uploading a BMP, TIFF, ICO, AVIF, HEIC, or a text/binary blob; or an SVG that fails sanitization (contains script, external refs, or malformed XML that SanitizeSVG rejects).
Common situations: User drops a .bmp or .tiff thinking it is supported; a SVG with embedded <script> or external entity that the sanitizer refuses; a file with a .svg extension but non-XML content.
Related errors
- custom emoji file is too large
- custom emoji file must not be empty
- invalid custom emoji image
- custom emoji name must not be empty
- invalid custom emoji name
AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12).
Data as JSON: /api/errors/27012c04f9b390e9.
Report an issue: GitHub.