{"record":{"id":"94bfcdf7ced7374f","repo":"XTLS/Xray-core","slug":"padding-turn-d-has-an-invalid-chunk-delay-w","errorCode":null,"errorMessage":"padding turn %d has an invalid chunk delay: %w","messagePattern":"padding turn (.+?) has an invalid chunk delay: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"transport/internet/finalmask/xmc/padding.go","lineNumber":92,"sourceCode":"\tif len(schedule) == 0 {\n\t\treturn fmt.Errorf(\"empty padding schedule\")\n\t}\n\tif firstTurnPrefixLength < 0 {\n\t\treturn fmt.Errorf(\"negative first turn prefix length: %d\", firstTurnPrefixLength)\n\t}\n\tif firstTurnPrefixLength > 0 && schedule[0].direction != paddingClientToServer {\n\t\treturn fmt.Errorf(\"first prefixed padding turn is not client-to-server\")\n\t}\n\n\tfor i, turn := range schedule {\n\t\tif turn.direction != paddingClientToServer && turn.direction != paddingServerToClient {\n\t\t\treturn fmt.Errorf(\"padding turn %d has invalid direction: %d\", i, turn.direction)\n\t\t}\n\t\tif err := validatePaddingDelayRange(turn.startDelay); err != nil {\n\t\t\treturn fmt.Errorf(\"padding turn %d has an invalid start delay: %w\", i, err)\n\t\t}\n\t\tif err := validatePaddingDelayRange(turn.chunkDelay); err != nil {\n\t\t\treturn fmt.Errorf(\"padding turn %d has an invalid chunk delay: %w\", i, err)\n\t\t}\n\t\tif turn.writeChunkMinLength < 0 || turn.writeChunkLength < turn.writeChunkMinLength || turn.writeChunkLength > maxPaddingChunkLength {\n\t\t\treturn fmt.Errorf(\"padding turn %d has an invalid write chunk range: %d-%d\", i, turn.writeChunkMinLength, turn.writeChunkLength)\n\t\t}\n\t\tif len(turn.variants) > 0 && turn.writeChunkLength != 0 {\n\t\t\treturn fmt.Errorf(\"padding turn %d combines variants with generated write chunks\", i)\n\t\t}\n\n\t\tminLength, maxLength, err := paddingTurnBounds(turn)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"padding turn %d: %w\", i, err)\n\t\t}\n\t\thasSendRange := turn.sendMinLength != 0 || turn.sendMaxLength != 0\n\t\tif hasSendRange {\n\t\t\tif len(turn.variants) > 0 {\n\t\t\t\treturn fmt.Errorf(\"padding turn %d combines variants with a send range\", i)\n\t\t\t}\n\t\t\tif turn.sendMinLength < minLength || turn.sendMaxLength < turn.sendMinLength || turn.sendMaxLength > maxLength {","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/transport/internet/finalmask/xmc/padding.go#L74-L110","documentation":"validatePaddingSchedule rejected turn i's chunkDelay range: min negative or max < min. Chunk delays space out individual padding chunk writes inside a turn and must satisfy 0 <= min <= max, same rule as start delays.","triggerScenarios":"A schedule turn with chunkDelay.min negative or fields ordered max-then-min swapped in a struct literal.","commonSituations":"Config-driven delays with signed values; copy-paste between startDelay and chunkDelay fields with wrong ordering; tests with sentinel durations.","solutions":["Fix the range so 0 <= chunkDelay.min <= chunkDelay.max","Validate delay ranges at config-load time when they are externally configurable","Add a helper that constructs paddingDelayRange and rejects inverted inputs"],"exampleFix":"// before\nchunkDelay: paddingDelayRange{min: -time.Millisecond, max: time.Second}\n\n// after\nchunkDelay: paddingDelayRange{min: 0, max: time.Second}","handlingStrategy":"validation","validationCode":"func validChunkDelay(d paddingDelayRange) bool { return d.min >= 0 && d.max >= d.min }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Construct delay ranges through one helper that rejects inverted inputs","Validate config-sourced delays before building turns"],"tags":["go","padding","validation","timing"],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}