{"record":{"id":"4bf58eaaf8596c1b","repo":"XTLS/Xray-core","slug":"invalid-value-for-rand-length","errorCode":null,"errorMessage":"invalid value for rand Length","messagePattern":"invalid value for rand Length","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"infra/conf/freedom.go","lineNumber":205,"sourceCode":"\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tconfig.FinalRules = append(config.FinalRules, rule)\n\t}\n\n\treturn config, nil\n}\n\nfunc ParseNoise(noise *Noise) (*freedom.Noise, error) {\n\tvar err error\n\tNConfig := new(freedom.Noise)\n\tnoise.Packet = strings.TrimSpace(noise.Packet)\n\n\tswitch noise.Type {\n\tcase \"rand\":\n\t\tmin, max, err := ParseRangeString(noise.Packet)\n\t\tif err != nil {\n\t\t\treturn nil, errors.New(\"invalid value for rand Length\").Base(err)\n\t\t}\n\t\tNConfig.LengthMin = uint64(min)\n\t\tNConfig.LengthMax = uint64(max)\n\t\tif NConfig.LengthMin == 0 {\n\t\t\treturn nil, errors.New(\"rand lengthMin or lengthMax cannot be 0\")\n\t\t}\n\n\tcase \"str\":\n\t\t// user input string\n\t\tNConfig.Packet = []byte(noise.Packet)\n\n\tcase \"hex\":\n\t\t// user input hex\n\t\tNConfig.Packet, err = hex.DecodeString(noise.Packet)\n\t\tif err != nil {\n\t\t\treturn nil, errors.New(\"Invalid hex string\").Base(err)\n\t\t}\n","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/infra/conf/freedom.go#L187-L223","documentation":"Thrown by ParseNoise when a noise entry of type \"rand\" has a packet value that is not a parseable numeric range. rand noises encode their size as a from-to range string (e.g. \"50-100\"); ParseRangeString failing produces this error with the parse cause chained. It fires while building the freedom outbound's noise list.","triggerScenarios":"\"noise\": {\"type\": \"rand\", \"packet\": \"100\"} (single number, not a range in the expected form), \"50:100\", or \"abc\". Any non-range string on the rand branch triggers it.","commonSituations":"Assuming a single length is accepted; wrong separator; copying noise examples from other tools with different notation.","solutions":["Write the rand packet as a range: \"50-100\".","For a fixed size repeat the value: \"100-100\".","For fixed-content noise use type \"str\", \"hex\", or \"base64\" instead of \"rand\"."],"exampleFix":"// before\n{\"type\": \"rand\", \"packet\": \"100\"}\n\n// after\n{\"type\": \"rand\", \"packet\": \"100-100\"}","handlingStrategy":"validation","validationCode":"if noise.Type == \"rand\" {\n    if _, _, err := ParseRangeString(strings.TrimSpace(noise.Packet)); err != nil {\n        return fmt.Errorf(\"rand noise packet must be a range like '50-100': %w\", err)\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Encode rand sizes as ranges; repeat the value for fixed size.","Use str/hex/base64 types for literal payloads."],"tags":["go","xray","freedom","noise","config","validation"],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}