siyuan-note/siyuan · warning
ErrInputTooLarge
ErrInputTooLarge
Error message
HEIF image exceeds the input size limit
What it means
ErrInputTooLarge signals that a HEIF image byte buffer exceeds MaxInputBytes, the package's hard cap on input size. The package enforces this before decoding (in GetOrCreate, ReadFileLimited, convert, ImageSize) because oversized HEIF decodes can exhaust memory or CPU. It is a sentinel error, returned unwrapped so callers can compare with errors.Is or ==.
Solutions
- Check len(source) against MaxInputBytes before calling and reject or downscale the asset earlier in the pipeline
- Transcode or compress the HEIF file outside SiYuan (e.g. sips/ffmpeg to a smaller HEIC or JPEG) and re-import
- If reading from disk, use ReadFileLimited only after checking the file size, and surface a user-facing message asking to shrink the image
Example fix
// before
result, err := heif.GetOrCreate(ctx, data, heif.Options{Mode: heif.ModePreview})
// after
if len(data) > heif.MaxInputBytes {
return fmt.Errorf("asset too large for HEIF conversion (%d bytes)", len(data))
}
result, err := heif.GetOrCreate(ctx, data, heif.Options{Mode: heif.ModePreview}) Defensive patterns
Strategy: validation
Validate before calling
if len(data) > heif.MaxInputBytes {
return fmt.Errorf("HEIF input too large: %d bytes", len(data))
} Try / catch
if err != nil {
if errors.Is(err, heif.ErrInputTooLarge) {
// skip or downscale the asset
}
return err
} Prevention
- Check len(source) against heif.MaxInputBytes before any conversion call
- Reject or transcode oversized camera assets at import time
- Surface the size limit to users so they compress large HEIC photos
When it happens
Trigger: Calling GetOrCreate/convert/ImageSize with a source []byte longer than MaxInputBytes, or ReadFileLimited/TestReadFileLimited on an asset file whose byte length exceeds the limit (cache.go:98 returns it before any decode work begins).
Common situations: Users insert very large HEIC photos (e.g. 48MP iPhone ProRAW or burst shots) into a note; assets copied from a camera without compression; a test feeding an oversized buffer to ReadFileLimited.
Understand the failure class
Background: "File too large" / "file size exceeds limit" errors: why libraries cap file sizes and how to fix them — this error's family across 46 libraries.
Related errors
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/a3bb405397d79493.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/heif/convert.go:52
const (
thumbnailWidth = 520
previewQuality = 90
thumbnailQuality = 85
MaxInputBytes = 32 * 1024 * 1024
maxDimension = 65535
desktopMaxPixels = 50_000_000
mobileMaxPixels = 12_500_000
// 解码层仅接受至多 10-bit 4:2:0、无透明通道的单 slice 图像;这里按解码面、CTU 表、
// NRGBA 和一次合并变换预留每像素 16 字节,再单独预留源文件、RBSP 副本与 JPEG 输出。
workingBytesPerPixel = 16
desktopWorkingBudget = 960 * 1024 * 1024
mobileWorkingBudget = 320 * 1024 * 1024
desktopOutputReserve = 96 * 1024 * 1024
mobileOutputReserve = 32 * 1024 * 1024
)
var (
ErrInputTooLarge = errors.New("HEIF image exceeds the input size limit")
ErrImageTooLarge = errors.New("HEIF image exceeds the dimension limit")
ErrInvalidMode = errors.New("invalid HEIF conversion mode")
conversionSlots = make(chan struct{}, 1)
maxPixels = platformMaxPixels()
)
func platformMaxPixels() int {
if runtime.GOOS == "android" || runtime.GOOS == "ios" {
return pixelsWithinBudget(mobileWorkingBudget, mobileOutputReserve, mobileMaxPixels)
}
return pixelsWithinBudget(desktopWorkingBudget, desktopOutputReserve, desktopMaxPixels)
}
func ReadFileLimited(path string, maxBytes int64) ([]byte, error) {
if maxBytes <= 0 {
return nil, ErrInputTooLarge
}View on GitHub (pinned to 9f775e8a12)