{"record":{"id":"a2cb85c2f1846fc7","repo":"XTLS/Xray-core","slug":"invalid-hex-string","errorCode":null,"errorMessage":"Invalid hex string","messagePattern":"Invalid hex string","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"infra/conf/freedom.go","lineNumber":221,"sourceCode":"\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)\n\t\t}\n\n\tdefault:\n\t\treturn nil, errors.New(\"Invalid packet, only rand/str/hex/base64 are supported\")\n\t}\n\n\tif noise.Delay != nil {\n\t\tNConfig.DelayMin = uint64(noise.Delay.From)\n\t\tNConfig.DelayMax = uint64(noise.Delay.To)\n\t}\n\tswitch strings.ToLower(noise.ApplyTo) {","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/infra/conf/freedom.go#L203-L239","documentation":"Thrown by ParseNoise when a noise entry of type \"hex\" has a packet value that is not valid hexadecimal. The raw string is passed straight to hex.DecodeString and any error (odd length, non-hex characters) is wrapped with this message. Decoding happens at config build time, before any traffic flows.","triggerScenarios":"{\"type\": \"hex\", \"packet\": \"zz\"} or \"abc\" (odd number of digits) or a string with 0x prefix. hex.DecodeString fails and the error is chained.","commonSituations":"Forgetting that Go hex requires even-length strings; including a \"0x\" prefix; pasting base64 into a hex field; whitespace mixed in.","solutions":["Provide an even-length hex string without prefix or separators, e.g. \"deadbeef\".","Strip \"0x\" prefixes and whitespace before embedding.","If the payload is not hex, switch the type to \"base64\" or \"str\"."],"exampleFix":"// before\n{\"type\": \"hex\", \"packet\": \"0xdeadbeef\"}\n\n// after\n{\"type\": \"hex\", \"packet\": \"deadbeef\"}","handlingStrategy":"validation","validationCode":"if noise.Type == \"hex\" {\n    if _, err := hex.DecodeString(noise.Packet); err != nil {\n        return fmt.Errorf(\"noise packet is not valid hex (even length, no 0x prefix): %w\", err)\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use even-length hex without 0x prefix or whitespace.","Generate hex with a library (xxd -p, hex.EncodeToString), never by hand."],"tags":["go","xray","freedom","noise","hex","config","validation"],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}