XTLS/Xray-core · error

PacketsFrom can't be 0

Error message

PacketsFrom can't be 0

What it means

After successfully parsing "packets" as a numeric range, FragmentMask.Build (infra/conf/transport_finalmask.go:261) rejects a range whose lower bound is 0: packet indices are 1-based, so a fragment starting at packet 0 is meaningless and "PacketsFrom can't be 0" aborts the build.

Source

Thrown at infra/conf/transport_finalmask.go:261

func (c *FragmentMask) Build() (proto.Message, error) {
	config := &fragment.Config{}

	switch strings.ToLower(c.Packets) {
	case "tlshello":
		config.PacketsFrom = 0
		config.PacketsTo = 1
	case "":
		config.PacketsFrom = 0
		config.PacketsTo = 0
	default:
		from, to, err := ParseRangeString(c.Packets)
		if err != nil {
			return nil, errors.New("Invalid PacketsFrom").Base(err)
		}
		config.PacketsFrom = int64(from)
		config.PacketsTo = int64(to)
		if config.PacketsFrom == 0 {
			return nil, errors.New("PacketsFrom can't be 0")
		}
	}

	if len(c.Lengths) > 0 {
		for _, r := range c.Lengths {
			config.LengthsMin = append(config.LengthsMin, int64(r.From))
			config.LengthsMax = append(config.LengthsMax, int64(r.To))
		}
	} else {
		config.LengthsMin = append(config.LengthsMin, int64(c.Length.From))
		config.LengthsMax = append(config.LengthsMax, int64(c.Length.To))
	}

	if config.LengthsMin[len(config.LengthsMin)-1] == 0 {
		return nil, errors.New("last lengths entry min can't be 0")
	}

	if len(c.Delays) > 0 {

View on GitHub (pinned to 7d214f8b09)

Solutions

  1. Start the range at 1: "packets":"1-2"
  2. Use "packets":"tlshello" if the goal is just ClientHello fragmentation

Example fix

// before
"packets": "0-1"
// after
"packets": "1-1"
Defensive patterns

Strategy: validation

Validate before calling

const m = /^(\d+)(?:-(\d+))?$/.exec(cfg.packets ?? '');
if (m && parseInt(m[1], 10) === 0) throw new Error('packet indices are 1-based; got 0');

Prevention

When it happens

Trigger: "packets":"0-2" or "packets":"0". Note "tlshello" and "" set from=0 internally but bypass this check; only explicit numeric ranges starting at 0 are rejected.

Common situations: Zero-indexed thinking (first packet = 0); config generators emitting 0-based inclusive ranges; copying "0-1" from snippets that predate the check.

Related errors


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