{"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":null,"severity":"warning","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/9f775e8a12daef8255556097396f9b2739078892/kernel/heif/convert.go#L35-L71","documentation":"ErrImageTooLarge indicates the HEIF image's pixel dimensions (width/height) exceed the package limits — either maxDimension per side or platformMaxPixels total pixels. It is raised after decoding dimensions (DecodeConfigBytes) or after full decode when validating img.Bounds(), in convert, ImageSize, decodeImage, and writeHEIFPreview. This protects against decoding hostile or pathological images that would allocate enormous bitmaps.","triggerScenarios":"convert or ImageSize is called with a HEIF whose decoded width or height exceeds maxDimension, or whose width*height exceeds maxPixels; writeHEIFPreview validates the same bound before encoding output.","commonSituations":"Panoramic photos (e.g. 10000x4000 iPhone pano HEIC), stitched microscopy/scan images, or maliciously crafted HEIF headers declaring huge dimensions.","solutions":["Check dimensions first with goheic.DecodeConfigBytes (or ImageSize) and reject images over the limit with a clear user message","Downscale the image with an external tool before importing so it fits within maxDimension/maxPixels","If the limit is too strict for your use case, the platform budget (platformMaxPixels) is derived at init — document it rather than bypassing validDimensions"],"exampleFix":"// before\nresult, err := heif.GetOrCreate(ctx, data, opts)\n// after\nw, h, sizeErr := heif.ImageSize(data)\nif errors.Is(sizeErr, heif.ErrImageTooLarge) {\n\treturn fmt.Errorf(\"image dimensions %dx%d exceed the HEIF conversion limit\", w, h)\n}\nresult, err := heif.GetOrCreate(ctx, data, opts)","handlingStrategy":"validation","validationCode":"w, h, err := heif.ImageSize(data)\nif errors.Is(err, heif.ErrImageTooLarge) {\n\treturn fmt.Errorf(\"image exceeds dimension limit\")\n}","typeGuard":null,"tryCatchPattern":"if err != nil {\n\tif errors.Is(err, heif.ErrImageTooLarge) {\n\t\t// reject panorama/huge images with a user-facing message\n\t}\n\treturn err\n}","preventionTips":["Probe dimensions via ImageSize before full conversion","Downscale panoramas and stitched images before import","Remember limits cover both per-side (maxDimension) and total pixels (maxPixels)"],"tags":["heif","image-processing","dimensions"],"backgroundTag":"value-out-of-range","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"}