siyuan-note/siyuan · error

invalid encrypted asset content metadata

Error message

invalid encrypted asset content metadata

What it means

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.

Solutions

  1. Re-encrypt the asset from its original source with the official EncryptAsset
  2. Verify which tool produced the container and stop using the broken producer
  3. Restore the asset from sync history/backup
Defensive patterns

Strategy: try-catch

Try / catch

plain, name, err := model.DecryptAssetWithName(box, disk, dek, data)
if err != nil && strings.Contains(err.Error(), "invalid encrypted asset content metadata") {
    return errors.New("asset metadata is corrupt; restore from backup or re-encrypt the source")
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/b2235925a7752c5e. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/crypto.go:2351

	var version struct {
		Spec        json.RawMessage `json:"spec"`
		ContainerID json.RawMessage `json:"containerID"`
	}
	if err := json.Unmarshal(data, &version); err != nil {
		return nil, err
	}
	// 仅认证元数据同时缺少两个版本字段时按旧容器读取,显式空值或不完整的新格式不能降级。
	if len(version.Spec) == 0 && len(version.ContainerID) == 0 {
		metadata.Spec = encryptedAssetLegacySpec
	} else if metadata.Spec != encryptedAssetSpec || len(metadata.ContainerID) != encryptedAssetContainerIDSize {
		return nil, errors.New("unsupported encrypted asset container version")
	}
	if metadata.OriginalName == "" || metadata.OriginalName == "." ||
		filepath.Base(metadata.OriginalName) != metadata.OriginalName || strings.ContainsAny(metadata.OriginalName, `/\`) {
		return nil, errors.New("invalid encrypted asset original name")
	}
	if metadata.Size < 0 {
		return nil, errors.New("invalid encrypted asset content metadata")
	}
	chunks := uint64(metadata.Size) / encryptedAssetChunkSize
	if metadata.Size%encryptedAssetChunkSize != 0 || metadata.Size == 0 {
		chunks++
	}
	if metadata.Chunks != chunks {
		return nil, errors.New("invalid encrypted asset chunk count")
	}
	return metadata, nil
}

// DecryptAssetWithName 解密资源内容并返回原始名称。
func DecryptAssetWithName(boxID, diskName string, dek, ciphertext []byte) (plaintext []byte, originalName string, err error) {
	var output bytes.Buffer
	originalName, err = DecryptAssetToWriter(boxID, diskName, dek, bytes.NewReader(ciphertext), &output)
	if err != nil {
		return nil, "", err
	}

View on GitHub (pinned to 9f775e8a12)