XTLS/Xray-core · error

invalid value for rand Length

Error message

invalid value for rand Length

What it means

Thrown by ParseNoise when a noise entry of type "rand" has a packet value that is not a parseable numeric range. rand noises encode their size as a from-to range string (e.g. "50-100"); ParseRangeString failing produces this error with the parse cause chained. It fires while building the freedom outbound's noise list.

Source

Thrown at infra/conf/freedom.go:205

		if err != nil {
			return nil, err
		}
		config.FinalRules = append(config.FinalRules, rule)
	}

	return config, nil
}

func ParseNoise(noise *Noise) (*freedom.Noise, error) {
	var err error
	NConfig := new(freedom.Noise)
	noise.Packet = strings.TrimSpace(noise.Packet)

	switch noise.Type {
	case "rand":
		min, max, err := ParseRangeString(noise.Packet)
		if err != nil {
			return nil, errors.New("invalid value for rand Length").Base(err)
		}
		NConfig.LengthMin = uint64(min)
		NConfig.LengthMax = uint64(max)
		if NConfig.LengthMin == 0 {
			return nil, errors.New("rand lengthMin or lengthMax cannot be 0")
		}

	case "str":
		// user input string
		NConfig.Packet = []byte(noise.Packet)

	case "hex":
		// user input hex
		NConfig.Packet, err = hex.DecodeString(noise.Packet)
		if err != nil {
			return nil, errors.New("Invalid hex string").Base(err)
		}

View on GitHub (pinned to 7d214f8b09)

Solutions

  1. Write the rand packet as a range: "50-100".
  2. For a fixed size repeat the value: "100-100".
  3. For fixed-content noise use type "str", "hex", or "base64" instead of "rand".

Example fix

// before
{"type": "rand", "packet": "100"}

// after
{"type": "rand", "packet": "100-100"}
Defensive patterns

Strategy: validation

Validate before calling

if noise.Type == "rand" {
    if _, _, err := ParseRangeString(strings.TrimSpace(noise.Packet)); err != nil {
        return fmt.Errorf("rand noise packet must be a range like '50-100': %w", err)
    }
}

Prevention

When it happens

Trigger: "noise": {"type": "rand", "packet": "100"} (single number, not a range in the expected form), "50:100", or "abc". Any non-range string on the rand branch triggers it.

Common situations: Assuming a single length is accepted; wrong separator; copying noise examples from other tools with different notation.

Related errors


AI-assisted analysis of XTLS/Xray-core@7d214f8b09 (2026-08-15). Data as JSON: /api/errors/4bf58eaaf8596c1b. Report an issue: GitHub.