{"record":{"id":"c78119d1509839a9","repo":"2dust/v2rayN","slug":"invalid-socks5-udp-packet-domain-length-missing","errorCode":null,"errorMessage":"Invalid SOCKS5 UDP packet: domain length missing","messagePattern":"Invalid SOCKS5 UDP packet: domain length missing","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"v2rayN/ServiceLib.UdpTest/Socks5UdpChannel.cs","lineNumber":157,"sourceCode":"                break;\n\n            case Socks5AddressData.AddrTypeIPv6:\n                if (packet.Length < offset + 16)\n                {\n                    throw new ArgumentException(\"Invalid SOCKS5 UDP packet: IPv6 address incomplete\");\n                }\n\n                var ipv6Bytes = new byte[16];\n                Array.Copy(packet, offset, ipv6Bytes, 0, 16);\n                host = new IPAddress(ipv6Bytes).ToString();\n                addressLength = 16;\n                isDomain = false;\n                break;\n\n            case Socks5AddressData.AddrTypeDomain:\n                if (packet.Length < offset + 1)\n                {\n                    throw new ArgumentException(\"Invalid SOCKS5 UDP packet: domain length missing\");\n                }\n\n                var domainLength = packet[offset++];\n                if (packet.Length < offset + domainLength)\n                {\n                    throw new ArgumentException(\"Invalid SOCKS5 UDP packet: domain incomplete\");\n                }\n\n                host = Encoding.ASCII.GetString(packet, offset, domainLength);\n                addressLength = domainLength;\n                isDomain = true;\n                break;\n\n            default:\n                throw new NotSupportedException($\"Unsupported SOCKS5 address type: {addressType}\");\n        }\n\n        offset += addressLength;","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/2dust/v2rayN/blob/e01717d8326a4f5060b335523590c5fda943fe03/v2rayN/ServiceLib.UdpTest/Socks5UdpChannel.cs#L139-L175","documentation":"Thrown when ATYP indicates a domain (0x03) but there is no length byte following it. A domain address in SOCKS5 is length-prefixed (1 length byte + N name bytes); the parser cannot proceed without the length.","triggerScenarios":"ParseSocks5UdpPacket reads ATYP == AddrTypeDomain then packet.Length < offset + 1, i.e. the datagram ends immediately after the ATYP byte with no domain-length octet.","commonSituations":"Truncated relay packet right after the ATYP; proxy that uses an ATYP the client does not expect; corrupt datagram.","solutions":["Catch ArgumentException in the attempt loop and treat as a failed attempt.","Verify the proxy emits domain-type headers as ATYP 0x03 + 1-byte length + ASCII name when it relays by hostname.","Log the packet tail to confirm whether the length byte is genuinely missing or the ATYP was misread due to an earlier field error.","Test with a target that yields an IPv4 (ATYP 0x01) reply to isolate domain-encoding bugs."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-check domain length byte presence\nstatic bool HasDomainLengthByte(byte[] p, int offset) => p != null && p.Length >= offset + 1;","typeGuard":"static bool HasDomainLength(byte[] packet, int offset) => packet != null && offset + 1 <= packet.Length;","tryCatchPattern":"try\n{\n    var (remote, data) = ParseSocks5UdpPacket(packet);\n}\ncatch (ArgumentException ex) when (ex.Message.Contains(\"domain length missing\"))\n{\n    // truncated just after ATYP; mark attempt failed\n}","preventionTips":["Catch the ArgumentException per attempt.","Confirm the proxy emits ATYP 0x03 + length byte + ASCII name.","Log the packet tail to distinguish a missing length byte from earlier misalignment."],"tags":["socks5","udp","packet-parsing","domain","network"],"backgroundTag":null,"analyzedSha":"e01717d8326a4f5060b335523590c5fda943fe03","analyzedAt":"2026-08-13T10:10:23.416Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}