{"record":{"id":"dbf1ec61a7f930f0","repo":"2dust/v2rayN","slug":"invalid-socks5-udp-packet-domain-incomplete","errorCode":null,"errorMessage":"Invalid SOCKS5 UDP packet: domain incomplete","messagePattern":"Invalid SOCKS5 UDP packet: domain incomplete","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"v2rayN/ServiceLib.UdpTest/Socks5UdpChannel.cs","lineNumber":163,"sourceCode":"                }\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;\n\n        // Port (2 bytes, big-endian)\n        if (packet.Length < offset + 2)\n        {\n            throw new ArgumentException(\"Invalid SOCKS5 UDP packet: port incomplete\");\n        }","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/2dust/v2rayN/blob/e01717d8326a4f5060b335523590c5fda943fe03/v2rayN/ServiceLib.UdpTest/Socks5UdpChannel.cs#L145-L181","documentation":"Thrown when the declared domain length exceeds the remaining bytes in the packet. The length-prefix said N bytes of domain name, but fewer than N bytes are actually present.","triggerScenarios":"ParseSocks5UdpPacket reads ATYP == AddrTypeDomain, reads domainLength, then packet.Length < offset + domainLength; i.e. the length byte promised more name bytes than the datagram contains.","commonSituations":"Corrupt length byte (e.g. a high value from bit noise); truncated datagram after the length byte; proxy that writes a wrong domain length; packet loss dropping the tail of the relay datagram.","solutions":["Catch ArgumentException per attempt and continue to the next retry.","Confirm the proxy writes the correct 1-byte domain length matching the hostname it relays.","Sanity-check domainLength (e.g. reject values > 253, the max DNS label/hostname length) before trusting it.","Log domainLength vs. remaining-bytes to distinguish a wrong length from truncation."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Sanity-check the declared domain length before trusting it\nstatic bool IsValidDomainSpan(byte[] p, int offset)\n{\n    if (p == null || offset + 1 > p.Length) return false;\n    var len = p[offset];\n    return len > 0 && len <= 253 && offset + 1 + len <= p.Length;\n}","typeGuard":"static bool IsCompleteDomainPacket(byte[] packet, int offset) => packet != null && offset + 1 <= packet.Length && (offset + 1 + packet[offset]) <= packet.Length;","tryCatchPattern":"try\n{\n    var (remote, data) = ParseSocks5UdpPacket(packet);\n}\ncatch (ArgumentException ex) when (ex.Message.Contains(\"domain incomplete\"))\n{\n    // declared length exceeds remaining bytes; corrupt length or truncation\n}","preventionTips":["Reject implausible domain lengths (> 253) before parsing.","Catch the ArgumentException per attempt.","Log declared length vs remaining bytes to spot a corrupt length octet."],"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"}