{"record":{"id":"a315563c5923e738","repo":"siyuan-note/siyuan","slug":"unsupported-encrypted-asset-container-version","errorCode":null,"errorMessage":"unsupported encrypted asset container version","messagePattern":"unsupported encrypted asset container version","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/crypto.go","lineNumber":2344,"sourceCode":"}\n\nfunc parseEncryptedAssetMetadata(data []byte) (*encryptedAssetMetadata, error) {\n\tmetadata := &encryptedAssetMetadata{}\n\tif err := json.Unmarshal(data, metadata); err != nil {\n\t\treturn nil, err\n\t}\n\tvar version struct {\n\t\tSpec        json.RawMessage `json:\"spec\"`\n\t\tContainerID json.RawMessage `json:\"containerID\"`\n\t}\n\tif err := json.Unmarshal(data, &version); err != nil {\n\t\treturn nil, err\n\t}\n\t// 仅认证元数据同时缺少两个版本字段时按旧容器读取，显式空值或不完整的新格式不能降级。\n\tif len(version.Spec) == 0 && len(version.ContainerID) == 0 {\n\t\tmetadata.Spec = encryptedAssetLegacySpec\n\t} else if metadata.Spec != encryptedAssetSpec || len(metadata.ContainerID) != encryptedAssetContainerIDSize {\n\t\treturn nil, errors.New(\"unsupported encrypted asset container version\")\n\t}\n\tif metadata.OriginalName == \"\" || metadata.OriginalName == \".\" ||\n\t\tfilepath.Base(metadata.OriginalName) != metadata.OriginalName || strings.ContainsAny(metadata.OriginalName, `/\\`) {\n\t\treturn nil, errors.New(\"invalid encrypted asset original name\")\n\t}\n\tif metadata.Size < 0 {\n\t\treturn nil, errors.New(\"invalid encrypted asset content metadata\")\n\t}\n\tchunks := uint64(metadata.Size) / encryptedAssetChunkSize\n\tif metadata.Size%encryptedAssetChunkSize != 0 || metadata.Size == 0 {\n\t\tchunks++\n\t}\n\tif metadata.Chunks != chunks {\n\t\treturn nil, errors.New(\"invalid encrypted asset chunk count\")\n\t}\n\treturn metadata, nil\n}\n","sourceCodeStart":2326,"sourceCodeEnd":2362,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/crypto.go#L2326-L2362","documentation":"decryptAssetMetadata enforces container versioning: metadata must either be the legacy format (both Spec and ContainerID empty) or the current format (Spec == encryptedAssetSpec and ContainerID of encryptedAssetContainerIDSize). Anything else is an unrecognized container version and is rejected rather than silently downgraded.","triggerScenarios":"Decrypting an asset written by a newer SiYuan version whose spec string or container-ID length differs, or a corrupted/mutated metadata blob where Spec/ContainerID fields decrypt to unexpected values.","commonSituations":"Downgrading the kernel after the asset container format was bumped, syncing assets from a newer client to an older one, bit-rot or tampering altering the authenticated-then-parsed metadata.","solutions":["Upgrade the SiYuan kernel to the version that wrote this asset so it understands the newer container spec","If you intentionally downgraded, re-export/re-encrypt the assets with the older version first","Check metadata.Spec and metadata.ContainerID lengths after decryption to identify which format mismatched","Restore the asset from backup if the metadata was corrupted"],"exampleFix":"// before: old kernel reading newer containers\n// unsupported encrypted asset container version\n// after: bump constants to match writer\nconst encryptedAssetSpec = \"siyuan-asset-v2\" // match the version that produced the asset","handlingStrategy":"try-catch","validationCode":"// after decrypt, before use\nif len(meta.Spec) > 0 && meta.Spec != encryptedAssetSpec {\n    return errors.New(\"asset written by a newer version; upgrade required\")\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"container version\") {\n    // inform user to upgrade the kernel; do not attempt downgrade reads\n}","preventionTips":["Keep all synced clients on a kernel version supporting the same asset spec","Before downgrading, decrypt+re-encrypt assets into the older format","Record the container spec version in backups"],"tags":["encryption","assets","versioning","compatibility","go-kernel"],"backgroundTag":"unsupported-operation","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}