siyuan-note/siyuan · error

Argon2id Memory too high (maximum 256 MB)

Error message

Argon2id Memory too high (maximum 256 MB)

What it means

Raised by ValidateArgon2Params when p.Memory > 256*1024 (KiB), i.e. above the 256 MB ceiling. The cap exists to stop a malicious backup from specifying enormous memory and forcing an out-of-memory condition during key derivation. Default is 64 MB.

Source

Thrown at kernel/util/kdf.go:71

	return Argon2Params{
		Memory:      64 * 1024,
		Iterations:  3,
		Parallelism: 4,
		KeyLength:   32,
	}
}

// ValidateArgon2Params 校验 Argon2id 参数是否在合理范围内,防止恶意备份设置极大内存导致 OOM,
// 或过弱参数降低安全性。
func ValidateArgon2Params(p Argon2Params) (Argon2Params, error) {
	if p.KeyLength != 32 {
		return p, errors.New("Argon2id KeyLength must be 32")
	}
	if p.Memory < 64*1024 {
		return p, errors.New("Argon2id Memory too low (minimum 64 MB)")
	}
	if p.Memory > 256*1024 {
		return p, errors.New("Argon2id Memory too high (maximum 256 MB)")
	}
	if p.Iterations < 3 {
		return p, errors.New("Argon2id Iterations too low (minimum 3)")
	}
	if p.Iterations > 10 {
		return p, errors.New("Argon2id Iterations too high (maximum 10)")
	}
	if p.Parallelism == 0 || p.Parallelism > 16 {
		return p, errors.New("Argon2id Parallelism must be between 1 and 16")
	}
	return p, nil
}

// DeriveKey 用 Argon2id 从密码派生密钥。同一 password+salt+params 多次调用结果一致。
func DeriveKey(password string, salt []byte, p Argon2Params) []byte {
	return argon2.IDKey([]byte(password), salt, p.Iterations, p.Memory, p.Parallelism, p.KeyLength)
}

View on GitHub (pinned to 251596fc0d)

Solutions

  1. Lower KDFParams.Memory to <= 256*1024 KiB (256 MB); DefaultArgon2Params uses 64*1024.
  2. Do not import crypto configs from untrusted backups; if you must, clamp Memory to the valid range first.
  3. Confirm the value is in KiB (256*1024 KiB == 256 MB).

Example fix

// before: exceeds the 256 MB DoS cap
params := util.Argon2Params{Memory: 512 * 1024, Iterations: 3, Parallelism: 4, KeyLength: 32}

// after: within range
params := util.Argon2Params{Memory: 256 * 1024, Iterations: 3, Parallelism: 4, KeyLength: 32}
Defensive patterns

Strategy: validation

Validate before calling

if p.Memory > 256*1024 {
    return fmt.Errorf("rejecting crypto config: Memory %d exceeds the 256 MB DoS cap", p.Memory)
}
if _, err := util.ValidateArgon2Params(p); err != nil {
    return err
}

Prevention

When it happens

Trigger: A notebook crypto config (possibly from an imported/malicious backup) sets Memory above 256*1024 KiB; ValidateArgon2Params is invoked during unlock/import and rejects it before argon2.IDKey allocates.

Common situations: Importing a backup crafted to OOM the kernel; a user-raised memory value to harden KDF but exceeding the cap; a unit confusion (entering bytes or MiB).

Related errors


AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12). Data as JSON: /api/errors/ef11b80c39a3477e. Report an issue: GitHub.