ory/hydra · error

memory %v is too large

Error message

memory %v is too large

What it means

Returned by toKB when the configured Argon2 memory limit, converted to kilobytes, exceeds math.MaxUint32 (i.e. the configured value is ~4TB or more). The Argon2 parameter itself is absurdly large; the configuration value for hasher memory is at fault.

Source

Thrown at oryx/hasherx/hasher_argon2.go:73

	}
	// Argon2 is a hasher that uses the Argon2 algorithm.
	Argon2 struct {
		c Argon2Configurator
	}
	// Argon2Configurator is a function that returns the Argon2 configuration.
	Argon2Configurator interface {
		HasherArgon2Config(ctx context.Context) *Argon2Config
	}
)

func NewHasherArgon2(c Argon2Configurator) *Argon2 {
	return &Argon2{c: c}
}

func toKB(mem bytesize.ByteSize) (uint32, error) {
	kb := uint64(mem / bytesize.KB)
	if kb > math.MaxUint32 {
		return 0, errors.Errorf("memory %v is too large", mem)
	}
	return uint32(kb), nil
}

// Generate generates a hash for the given password.
func (h *Argon2) Generate(ctx context.Context, password []byte) (_ []byte, err error) {
	ctx, span := otel.GetTracerProvider().Tracer(tracingComponent).Start(ctx, "hash.Argon2.Generate")
	defer otelx.End(span, &err)
	p := h.c.HasherArgon2Config(ctx)
	span.SetAttributes(attribute.String("argon2.config", fmt.Sprintf("#%v", p)))

	salt := make([]byte, p.SaltLength)
	if _, err := rand.Read(salt); err != nil {
		return nil, err
	}

	mem, err := toKB(p.Memory)
	if err != nil {

View on GitHub (pinned to 4174065ffb)

Solutions

  1. Lower the Argon2 memory configuration to a realistic value (e.g. 64MB–1GB)
  2. Validate the configured memory size at config load time and fail fast with a clear message
  3. Use bytesize units explicitly (e.g. 128MB) to avoid accidental raw-byte magnitudes
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at oryx/hasherx/hasher_argon2.go:73 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of ory/hydra@4174065ffb (2026-09-03). Data as JSON: /api/errors/b1a3a9e6bdbecf7e. Report an issue: GitHub.