{"record":{"id":"7dac842b12387c86","repo":"siyuan-note/siyuan","slug":"encrypted-heif-cache-requires-a-notebook-id","errorCode":null,"errorMessage":"encrypted HEIF cache requires a notebook ID","messagePattern":"encrypted HEIF cache requires a notebook ID","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/heif/cache.go","lineNumber":92,"sourceCode":"\tmemoryCacheItems = map[string]*list.Element{}\n\tmemoryCacheBytes int\n)\n\nfunc IsPath(path string) bool {\n\tpath = strings.ToLower(path)\n\tif index := strings.IndexAny(path, \"?#\"); index >= 0 {\n\t\tpath = path[:index]\n\t}\n\text := filepath.Ext(path)\n\treturn ext == \".heic\" || ext == \".heif\"\n}\n\nfunc GetOrCreate(ctx context.Context, source []byte, options Options) (Result, error) {\n\tif options.Mode != ModePreview && options.Mode != ModeThumbnail {\n\t\treturn Result{}, ErrInvalidMode\n\t}\n\tif options.Encrypted && options.BoxID == \"\" {\n\t\treturn Result{}, errors.New(\"encrypted HEIF cache requires a notebook ID\")\n\t}\n\tif len(source) == 0 {\n\t\treturn Result{}, errors.New(\"empty HEIF image\")\n\t}\n\tif len(source) > MaxInputBytes {\n\t\treturn Result{}, ErrInputTooLarge\n\t}\n\tif err := ctx.Err(); err != nil {\n\t\treturn Result{}, err\n\t}\n\n\tdigest := cacheDigest(source, options.Mode)\n\tetag := `\"heif-` + digest + `\"`\n\tcacheKey := digest\n\tif options.Encrypted {\n\t\tcacheKey = options.BoxID + \":\" + digest\n\t\tif data := getMemoryCache(cacheKey); data != nil {\n\t\t\treturn Result{Data: data, ETag: etag}, nil","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/heif/cache.go#L74-L110","documentation":"heif.GetOrCreate caches decoded HEIF previews/thumbnails. When options.Encrypted is true, cache entries must be namespaced per notebook, so a non-empty BoxID is mandatory; the function rejects encrypted requests without one before doing any decode work.","triggerScenarios":"Calling heif.GetOrCreate with Options{Encrypted: true, BoxID: \"\"} — e.g. a preview writer (writeHEIFPreview) that failed to propagate the notebook ID for an image inside an encrypted notebook.","commonSituations":"Rendering HEIF assets in encrypted notebooks where the caller dropped the box context, or test harnesses constructing Options manually and omitting BoxID.","solutions":["Populate Options.BoxID with the owning notebook's ID whenever Encrypted is true.","If the image is not in an encrypted notebook, set Encrypted=false instead of leaving Encrypted=true with no BoxID.","Fix the upstream caller (writeHEIFPreview path) to thread the box ID through to the cache call."],"exampleFix":"// before\nres, err := heif.GetOrCreate(ctx, src, heif.Options{Mode: heif.ModePreview, Encrypted: true})\n// after\nres, err := heif.GetOrCreate(ctx, src, heif.Options{Mode: heif.ModePreview, Encrypted: true, BoxID: boxID})","handlingStrategy":"validation","validationCode":"if opts.Encrypted && opts.BoxID == \"\" {\n    return errors.New(\"BoxID is required for encrypted HEIF caching\")\n}","typeGuard":null,"tryCatchPattern":"res, err := heif.GetOrCreate(ctx, src, opts)\nif err != nil && strings.Contains(err.Error(), \"requires a notebook ID\") {\n    // fix Options and retry\n}","preventionTips":["Thread the notebook ID through all asset-preview call sites","Build Options via a constructor that enforces Encrypted=>BoxID","Add a unit test mirroring TestGetOrCreateValidatesOptionsBeforeDecode for new callers"],"tags":["heif","cache","encryption","validation"],"backgroundTag":"missing-required-argument","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"}