XTLS/Xray-core · error

padding turn 0 is too short for

Error message

padding turn 0 is too short for %d prefix bytes

What it means

validatePaddingSchedule rejects turn 0 because its minimum total length minus firstTurnPrefixLength is less than 1: after the prefix bytes that must lead the first turn, no room remains for even one record byte, so the first padding record could never be emitted.

Solutions

  1. Increase the first turn's minLength to at least firstTurnPrefixLength + 1
  2. Reduce firstTurnPrefixLength by moving prefix bytes out of turn 0
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at transport/internet/finalmask/xmc/padding.go:115 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at transport/internet/finalmask/xmc/padding.go:115

		if len(turn.variants) > 0 && turn.writeChunkLength != 0 {
			return fmt.Errorf("padding turn %d combines variants with generated write chunks", i)
		}

		minLength, maxLength, err := paddingTurnBounds(turn)
		if err != nil {
			return fmt.Errorf("padding turn %d: %w", i, err)
		}
		hasSendRange := turn.sendMinLength != 0 || turn.sendMaxLength != 0
		if hasSendRange {
			if len(turn.variants) > 0 {
				return fmt.Errorf("padding turn %d combines variants with a send range", i)
			}
			if turn.sendMinLength < minLength || turn.sendMaxLength < turn.sendMinLength || turn.sendMaxLength > maxLength {
				return fmt.Errorf("padding turn %d has an invalid send range: %d-%d", i, turn.sendMinLength, turn.sendMaxLength)
			}
		}
		if i == 0 && minLength-firstTurnPrefixLength < 1 {
			return fmt.Errorf("padding turn 0 is too short for %d prefix bytes", firstTurnPrefixLength)
		}
		if i == 0 && len(turn.variants) > 0 {
			for j, variant := range turn.variants {
				if _, _, err = trimPaddingPrefix(variant, firstTurnPrefixLength); err != nil {
					return fmt.Errorf("padding turn 0 variant %d: %w", j, err)
				}
			}
		}
		if i > 0 && turn.direction == schedule[i-1].direction {
			return fmt.Errorf("padding turns %d and %d have the same direction", i-1, i)
		}
	}
	return nil
}

func writePaddingTurn(w io.Writer, turn paddingTurn, prefixLength int) error {
	return writePaddingTurnWithSleep(w, turn, prefixLength, time.Sleep)
}

View on GitHub (pinned to 7d214f8b09)