{"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":"exception","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/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/crypto.go#L2333-L2369","documentation":"decryptAssetMetadata found metadata.Size negative. Size must be a non-negative content length consistent with the chunk layout; a negative value means the metadata is internally inconsistent (it is authenticated via AAD, so this indicates corruption or a writer bug).","triggerScenarios":"Decrypting a container whose authenticated metadata decrypted to a negative Size — from a corrupted metadata blob or a bug in the encrypting version that recorded the size.","commonSituations":"Bit-rot/storage corruption, assets written by buggy third-party tooling that bypassed the official writer, integer mishandling in an external generator of containers.","solutions":["Restore the asset from sync or backup — authenticated metadata should never be negative","Re-encrypt the original source file with the current kernel to regenerate valid metadata","Audit any third-party tool that generated the container to fix its size accounting"],"exampleFix":"// before: trusting size from external tool\nmeta.Size = int64(externalSize)\n// after: validate on the writer side\nif externalSize < 0 { return errors.New(\"invalid asset size\") }\nmeta.Size = int64(externalSize)","handlingStrategy":"validation","validationCode":"if metadata.Size < 0 {\n    return errors.New(\"asset metadata corrupted\")\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"content metadata\") {\n    // restore from backup; authenticated metadata must not be negative\n}","preventionTips":["Validate size fields in any tool that generates containers","Use the official writer API instead of building metadata manually","Monitor storage for bit-rot; keep verified backups"],"tags":["encryption","assets","corruption","validation","go-kernel"],"backgroundTag":"schema-validation-failed","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}