{"record":{"id":"c9b76bb68a2dcfe2","repo":"siyuan-note/siyuan","slug":"invalid-encrypted-asset-chunk-count","errorCode":null,"errorMessage":"invalid encrypted asset chunk count","messagePattern":"invalid encrypted asset chunk count","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/crypto.go","lineNumber":2358,"sourceCode":"\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}\n\treturn output.Bytes(), originalName, nil\n}\n\n// DecryptAssetName 只解密资源的名称元数据，不处理资源内容。\nfunc DecryptAssetName(boxID, diskName string, dek, ciphertext []byte) (originalName string, err error) {\n\tmetadata, _, err := decryptAssetMetadata(boxID, diskName, dek, ciphertext)\n\tif err != nil {","sourceCodeStart":2340,"sourceCodeEnd":2376,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/crypto.go#L2340-L2376","documentation":"The metadata's Chunks field is cross-checked against the value derived from Size: chunks = ceil(Size / encryptedAssetChunkSize). This error means the declared chunk count does not match the declared size, so the container's content region cannot be parsed reliably and the kernel refuses to decrypt it.","triggerScenarios":"Decrypting a container where metadata.Chunks was written inconsistently with metadata.Size — e.g. truncated content region plus an unadjusted chunk count, an encryptor bug, or a container assembled from mixed parts; also fires for Size==0 with a nonzero chunk count since zero-size assets are rejected upstream.","commonSituations":"Partially copied/stitched encrypted assets; containers written by an older kernel with a different chunk-size constant then partially updated; third-party encryptors using a different chunk size.","solutions":["Restore/re-sync the asset so content and metadata come from the same write","Re-encrypt from the original source with the current kernel's EncryptAsset","Check whether the producing tool used a different encryptedAssetChunkSize and regenerate the container"],"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 chunk count\") {\n    return restoreAssetFromSyncHistory(box, disk)\n}","preventionTips":["Never copy or stitch encrypted asset containers in parts; content and metadata must come from one atomic write","Ensure all clients use the same kernel version so encryptedAssetChunkSize matches","Keep sync history enabled to roll back inconsistent containers"],"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"}