XTLS/Xray-core · error
rand lengthMin or lengthMax cannot be 0
Error message
rand lengthMin or lengthMax cannot be 0
What it means
Thrown by ParseNoise when a rand noise's parsed range has a lower bound of 0. A zero-length random padding packet is useless (it would emit nothing), so after LengthMin/LengthMax are set the builder rejects LengthMin == 0. Note only the minimum is checked here.
Source
Thrown at infra/conf/freedom.go:210
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)
}
case "base64":
// user input base64
NConfig.Packet, err = base64.RawURLEncoding.DecodeString(strings.NewReplacer("+", "-", "/", "_", "=", "").Replace(noise.Packet))
if err != nil {
return nil, errors.New("Invalid base64 string").Base(err)View on GitHub (pinned to 7d214f8b09)
Solutions
- Start the range at 1 or higher, e.g. "50-100".
- Use a fixed positive range like "100-100" for deterministic padding size.
- Validate noise ranges in config tooling before deployment.
Example fix
// before
{"type": "rand", "packet": "0-100"}
// after
{"type": "rand", "packet": "50-100"} Defensive patterns
Strategy: validation
Validate before calling
if min, _, err := ParseRangeString(noise.Packet); err == nil && min < 1 {
return errors.New("rand noise length must be >= 1")
} Prevention
- Avoid 0-based ranges for noise lengths.
- Validate generated noise configs before deploy.
When it happens
Trigger: {"type": "rand", "packet": "0-100"} — the range parses fine but min is 0. Also "0-0".
Common situations: 0-based ranges from generators; misunderstanding the range as byte counts where 0 seems harmless.
Related errors
- PacketsFrom can't be 0
- LengthMin can't be 0
- invalid value for rand Length
- Invalid hex string
- Invalid base64 string
AI-assisted analysis of XTLS/Xray-core@7d214f8b09 (2026-08-15).
Data as JSON: /api/errors/44fe60655e19f702.
Report an issue: GitHub.