{"record":{"id":"a3bb405397d79493","repo":"siyuan-note/siyuan","slug":"errinputtoolarge","errorCode":"ErrInputTooLarge","errorMessage":"HEIF image exceeds the input size limit","messagePattern":"HEIF image exceeds the input size limit","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"kernel/heif/convert.go","lineNumber":52,"sourceCode":"const (\n\tthumbnailWidth   = 520\n\tpreviewQuality   = 90\n\tthumbnailQuality = 85\n\tMaxInputBytes    = 32 * 1024 * 1024\n\tmaxDimension     = 65535\n\tdesktopMaxPixels = 50_000_000\n\tmobileMaxPixels  = 12_500_000\n\t// 解码层仅接受至多 10-bit 4:2:0、无透明通道的单 slice 图像；这里按解码面、CTU 表、\n\t// NRGBA 和一次合并变换预留每像素 16 字节，再单独预留源文件、RBSP 副本与 JPEG 输出。\n\tworkingBytesPerPixel = 16\n\tdesktopWorkingBudget = 960 * 1024 * 1024\n\tmobileWorkingBudget  = 320 * 1024 * 1024\n\tdesktopOutputReserve = 96 * 1024 * 1024\n\tmobileOutputReserve  = 32 * 1024 * 1024\n)\n\nvar (\n\tErrInputTooLarge = errors.New(\"HEIF image exceeds the input size limit\")\n\tErrImageTooLarge = errors.New(\"HEIF image exceeds the dimension limit\")\n\tErrInvalidMode   = errors.New(\"invalid HEIF conversion mode\")\n\n\tconversionSlots = make(chan struct{}, 1)\n\tmaxPixels       = platformMaxPixels()\n)\n\nfunc platformMaxPixels() int {\n\tif runtime.GOOS == \"android\" || runtime.GOOS == \"ios\" {\n\t\treturn pixelsWithinBudget(mobileWorkingBudget, mobileOutputReserve, mobileMaxPixels)\n\t}\n\treturn pixelsWithinBudget(desktopWorkingBudget, desktopOutputReserve, desktopMaxPixels)\n}\n\nfunc ReadFileLimited(path string, maxBytes int64) ([]byte, error) {\n\tif maxBytes <= 0 {\n\t\treturn nil, ErrInputTooLarge\n\t}","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/heif/convert.go#L34-L70","documentation":"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 ==.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before\nresult, err := heif.GetOrCreate(ctx, data, heif.Options{Mode: heif.ModePreview})\n// after\nif len(data) > heif.MaxInputBytes {\n\treturn fmt.Errorf(\"asset too large for HEIF conversion (%d bytes)\", len(data))\n}\nresult, err := heif.GetOrCreate(ctx, data, heif.Options{Mode: heif.ModePreview})","handlingStrategy":"validation","validationCode":"if len(data) > heif.MaxInputBytes {\n\treturn fmt.Errorf(\"HEIF input too large: %d bytes\", len(data))\n}","typeGuard":null,"tryCatchPattern":"if err != nil {\n\tif errors.Is(err, heif.ErrInputTooLarge) {\n\t\t// skip or downscale the asset\n\t}\n\treturn err\n}","preventionTips":["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"],"tags":["heif","image-processing","input-validation"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}