{"record":{"id":"b2235925a7752c5e","repo":"siyuan-note/siyuan","slug":"invalid-encrypted-asset-content-metadata","errorCode":null,"errorMessage":"invalid encrypted asset content metadata","messagePattern":"invalid encrypted asset content metadata","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/crypto.go","lineNumber":2351,"sourceCode":"\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\n// DecryptAssetWithName 解密资源内容并返回原始名称。\nfunc DecryptAssetWithName(boxID, diskName string, dek, ciphertext []byte) (plaintext []byte, originalName string, err error) {\n\tvar output bytes.Buffer\n\toriginalName, err = DecryptAssetToWriter(boxID, diskName, dek, bytes.NewReader(ciphertext), &output)\n\tif err != nil {\n\t\treturn nil, \"\", err\n\t}","sourceCodeStart":2333,"sourceCodeEnd":2369,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/crypto.go#L2333-L2369","documentation":"The metadata Size field must be non-negative and consistent with the chunking scheme: the declared Chunks count must equal ceil(Size / encryptedAssetChunkSize). This error fires when Size is negative, meaning the authenticated metadata is internally inconsistent (a corrupt or forged container), so content decryption cannot be laid out correctly.","triggerScenarios":"Decrypting an asset whose metadata.Size < 0 — only possible from a container written with corrupted metadata or produced by a broken/foreign encryptor, since the official EncryptAsset never emits negative sizes and GCM authentication would catch tampering.","commonSituations":"Containers produced by experimental or third-party tooling; bit-rot in stored metadata that somehow still authenticated (effectively impossible — indicates a producer bug); format confusion between containers.","solutions":["Re-encrypt the asset from its original source with the official EncryptAsset","Verify which tool produced the container and stop using the broken producer","Restore the asset from sync history/backup"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"plain, name, err := model.DecryptAssetWithName(box, disk, dek, data)\nif err != nil && strings.Contains(err.Error(), \"invalid encrypted asset content metadata\") {\n    return errors.New(\"asset metadata is corrupt; restore from backup or re-encrypt the source\")\n}","preventionTips":["Only produce encrypted assets with the official model.EncryptAsset","Avoid third-party tools that rewrite encrypted asset metadata fields","Keep pre-encryption originals available so corrupted containers can be regenerated"],"tags":["encryption","corrupt-data","validation"],"backgroundTag":"schema-validation-failed","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"}