{"record":{"id":"0d663e9092dab85f","repo":"siyuan-note/siyuan","slug":"errimagetoolarge","errorCode":"ErrImageTooLarge","errorMessage":"HEIF image exceeds the dimension limit","messagePattern":"HEIF image exceeds the dimension limit","errorType":"error_code","errorClass":null,"httpStatus":413,"severity":"error","filePath":"kernel/heif/convert.go","lineNumber":53,"sourceCode":"\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}\n\tfile, err := os.Open(path)","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/afa823b6b4e4f183511e0bc0a3be93caa94c7c97/kernel/heif/convert.go#L35-L71","documentation":"ErrImageTooLarge (kernel/heif/convert.go:53) fires when pixel dimensions exceed the platform budget: at most 50,000,000 px on desktop and 12,500,000 px on mobile (both further squeezed by a 16 bytes-per-pixel working-memory budget), with a per-side cap of 65535 px (maxDimension). It is checked from the HEIF header via goheic.DecodeConfigBytes before full decode (convert.go:188) and again on decoded bounds (127/171), so oversized images fail fast without huge allocations.","triggerScenarios":"Inserting a >50 MP HEIF panorama or medium-format export on desktop; the same image on Android/iOS where the cap is 12.5 MP; any side exceeding 65535 px, caught at header or post-decode check.","commonSituations":"Stitched panoramas; 100 MP 'super-res' phone modes; desktop-size images synced to and opened on the mobile app where the budget is smaller.","solutions":["Downscale below the platform cap (desktop 50 MP / mobile 12.5 MP, each side <= 65535 px)","Convert the panorama to JPEG, which bypasses the HEIF decode budget","Tile very large images into multiple assets"],"exampleFix":"# before: insert panorama_120mp.heic\n# -> HEIF image exceeds the dimension limit\n\n# after: downscale under the 50 MP desktop budget, then insert\nmagick panorama_120mp.heic -resize 50% panorama_small.heic","handlingStrategy":"fallback","validationCode":"// Go: probe before committing the asset; ImageSize reports the same sentinel\n_, _, err := heif.ImageSize(data)\nif errors.Is(err, heif.ErrImageTooLarge) {\n    // downscale or convert to JPEG, then retry the insert\n}","typeGuard":"func isHEIFImageTooLarge(err error) bool {\n    return errors.Is(err, heif.ErrImageTooLarge)\n}","tryCatchPattern":"On ErrImageTooLarge from preview/size APIs, re-encode the asset with an external tool (downscale under 50 MP desktop / 12.5 MP mobile, sides <= 65535 px) or convert it to JPEG, then retry once - do not loop on the same bytes.","preventionTips":["Keep HEIF captures within platform pixel budgets","Split panoramas into tiles instead of one huge file","Check dimensions at import and transcode oversized images proactively"],"tags":["heif","image","dimension-limit","assets","resource-limits"],"backgroundTag":"image-dimension-limit","analyzedSha":"afa823b6b4e4f183511e0bc0a3be93caa94c7c97","analyzedAt":"2026-08-18T17:04:10.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}