XTLS/Xray-core · error

invalid CIDR prefix length:

Error message

invalid CIDR prefix length: 

What it means

The CIDR prefix-length suffix in a custom IP rule failed to parse as an unsigned 32-bit decimal integer. strconv.ParseUint rejects non-numeric strings, negatives written as '-1' (the '-' is treated as part of the number by this split path), or values exceeding uint32.

Source

Thrown at common/geodata/rule_parser.go:121

	ipStr, prefixStr, _ := strings.Cut(s, "/")

	ipAddr := net.ParseAddress(ipStr)

	var maxPrefix uint32
	switch ipAddr.Family() {
	case net.AddressFamilyIPv4:
		maxPrefix = 32
	case net.AddressFamilyIPv6:
		maxPrefix = 128
	default:
		return nil, errors.New("unsupported address family")
	}

	prefixBits := maxPrefix
	if prefixStr != "" {
		parsedPrefix, err := strconv.ParseUint(prefixStr, 10, 32)
		if err != nil {
			return nil, errors.New("invalid CIDR prefix length: ", prefixStr).Base(err)
		}
		prefixBits = uint32(parsedPrefix)
	}
	if prefixBits > maxPrefix {
		return nil, errors.New("CIDR prefix length ", prefixBits, " exceeds max ", maxPrefix)
	}

	return &CIDR{
		Ip:     []byte(ipAddr.IP()),
		Prefix: prefixBits,
	}, nil
}

func ParseDomainRule(r string, defaultType Domain_Type) (*DomainRule, error) {
	if strings.HasPrefix(r, "geosite:") {
		r = "ext:" + DefaultGeoSiteDat + ":" + r[len("geosite:"):]
	}

View on GitHub (pinned to 7d214f8b09)

Solutions

  1. Use a decimal prefix length 0–32 for IPv4 and 0–128 for IPv6: "10.0.0.0/8".
  2. Convert netmasks to CIDR notation (255.255.255.0 → /24).

Example fix

// before
"ip": ["10.0.0.0/255.0.0.0"]

// after
"ip": ["10.0.0.0/8"]
Defensive patterns

Strategy: validation

Validate before calling

if _, err := strconv.ParseUint(prefixStr, 10, 32); err != nil {
    return fmt.Errorf("rule %q: prefix %q is not a decimal integer 0-128", rule, prefixStr)
}

Prevention

When it happens

Trigger: IP rules like "10.0.0.0/+8", "10.0.0.0/abc", "10.0.0.0/-8", or "2001:db8::/99999999999999999999".

Common situations: Typos in prefix length; copying netmask notation (255.255.0.0) instead of prefix length (/16); negative prefix values.

Related errors


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