siyuan-note/siyuan · error

font file is too large

Error message

font file is too large

What it means

Returned by InstallCustomFont when the uploaded font file's size exceeds MaxCustomFontSize (64 MiB, defined in custom_font.go:35). The guard runs before opening or hashing the file, so it is a hard cap intended to prevent oversized uploads from being parsed or stored.

Source

Thrown at kernel/util/custom_font.go:106

	defer customFontsLock.Unlock()

	loadCustomFontsLocked()
	return cloneCustomFonts(customFonts)
}

func InstallCustomFont(tempPath string) (*CustomFont, bool, error) {
	customFontsLock.Lock()
	defer customFontsLock.Unlock()

	info, err := os.Stat(tempPath)
	if err != nil {
		return nil, false, err
	}
	if !info.Mode().IsRegular() || info.Size() < 1 {
		return nil, false, errors.New("font file is empty")
	}
	if MaxCustomFontSize < info.Size() {
		return nil, false, errors.New("font file is too large")
	}

	fontFile, err := os.Open(tempPath)
	if err != nil {
		return nil, false, err
	}

	extension, err := detectCustomFontExtension(fontFile)
	if err != nil {
		fontFile.Close()
		return nil, false, err
	}
	if _, err = fontFile.Seek(0, io.SeekStart); err != nil {
		fontFile.Close()
		return nil, false, err
	}

	id, err := customFontHash(fontFile)

View on GitHub (pinned to 251596fc0d)

Solutions

  1. Upload a single regular TTF/OTF file under 64 MiB; install other weights separately.
  2. If the file is not actually a font, route it to the correct upload endpoint.
  3. Only raise MaxCustomFileSize if you have reviewed the parsing cost and storage impact — it is a deliberate cap.

Example fix

// before
font, _, err := util.InstallCustomFont(tempPath)

// after
const maxFont = 64 * 1024 * 1024
if info, _ := os.Stat(tempPath); info.Size() > maxFont {
    return fmt.Errorf("font exceeds %d bytes; split the family", maxFont)
}
font, _, err := util.InstallCustomFont(tempPath)
Defensive patterns

Strategy: validation

Validate before calling

const maxFont = 64 * 1024 * 1024 // keep in sync with util.MaxCustomFontSize
func fontWithinLimit(tempPath string) bool {
    info, err := os.Stat(tempPath)
    return err == nil && info.Size() <= maxFont
}

Prevention

When it happens

Trigger: Calling util.InstallCustomFont(tempPath) where the temp file is larger than 64 MiB (67108864 bytes).

Common situations: A user uploaded a font family archive or a multi-weight 'super' font instead of a single TTF/OTF; a non-font binary (video, image) mistakenly routed to the font endpoint; an extraordinarily large legitimate font.

Related errors


AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12). Data as JSON: /api/errors/04aaef394f7d92f3. Report an issue: GitHub.