{"record":{"id":"44fe60655e19f702","repo":"XTLS/Xray-core","slug":"rand-lengthmin-or-lengthmax-cannot-be-0","errorCode":null,"errorMessage":"rand lengthMin or lengthMax cannot be 0","messagePattern":"rand lengthMin or lengthMax cannot be 0","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"infra/conf/freedom.go","lineNumber":210,"sourceCode":"\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\n\tcase \"base64\":\n\t\t// user input base64\n\t\tNConfig.Packet, err = base64.RawURLEncoding.DecodeString(strings.NewReplacer(\"+\", \"-\", \"/\", \"_\", \"=\", \"\").Replace(noise.Packet))\n\t\tif err != nil {\n\t\t\treturn nil, errors.New(\"Invalid base64 string\").Base(err)","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/infra/conf/freedom.go#L192-L228","documentation":"Thrown by ParseNoise when a rand noise's parsed range has a lower bound of 0. A zero-length random padding packet is useless (it would emit nothing), so after LengthMin/LengthMax are set the builder rejects LengthMin == 0. Note only the minimum is checked here.","triggerScenarios":"{\"type\": \"rand\", \"packet\": \"0-100\"} — the range parses fine but min is 0. Also \"0-0\".","commonSituations":"0-based ranges from generators; misunderstanding the range as byte counts where 0 seems harmless.","solutions":["Start the range at 1 or higher, e.g. \"50-100\".","Use a fixed positive range like \"100-100\" for deterministic padding size.","Validate noise ranges in config tooling before deployment."],"exampleFix":"// before\n{\"type\": \"rand\", \"packet\": \"0-100\"}\n\n// after\n{\"type\": \"rand\", \"packet\": \"50-100\"}","handlingStrategy":"validation","validationCode":"if min, _, err := ParseRangeString(noise.Packet); err == nil && min < 1 {\n    return errors.New(\"rand noise length must be >= 1\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Avoid 0-based ranges for noise lengths.","Validate generated noise configs before deploy."],"tags":["go","xray","freedom","noise","config","numeric-range"],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}