2dust/v2rayN · error · ArgumentException
Invalid SOCKS5 UDP packet: port incomplete
Error message
Invalid SOCKS5 UDP packet: port incomplete
What it means
Thrown when fewer than 2 bytes remain after the address for the big-endian port field. The parser needs exactly 2 bytes for the port; a short datagram here means the relay packet was truncated at the very end.
Source
Thrown at v2rayN/ServiceLib.UdpTest/Socks5UdpChannel.cs:180
{
throw new ArgumentException("Invalid SOCKS5 UDP packet: domain incomplete");
}
host = Encoding.ASCII.GetString(packet, offset, domainLength);
addressLength = domainLength;
isDomain = true;
break;
default:
throw new NotSupportedException($"Unsupported SOCKS5 address type: {addressType}");
}
offset += addressLength;
// Port (2 bytes, big-endian)
if (packet.Length < offset + 2)
{
throw new ArgumentException("Invalid SOCKS5 UDP packet: port incomplete");
}
var port = BinaryPrimitives.ReadUInt16BigEndian(packet.AsSpan(offset, 2));
offset += 2;
// Data (remaining bytes)
var dataLength = packet.Length - offset;
var data = new byte[dataLength];
if (dataLength > 0)
{
Array.Copy(packet, offset, data, 0, dataLength);
}
// Create remote endpoint without DNS resolution
var remote = new Socks5RemoteEndpoint(host, port, isDomain);
return (remote, data);
}
View on GitHub (pinned to e01717d832)
Solutions
- Catch ArgumentException per attempt and continue.
- Confirm the proxy always appends a 2-byte big-endian port after the address per RFC 1928.
- Re-validate the address-length math (especially for domain type) to ensure offset is correct before the port read.
- Log offset and total length at failure to locate the truncation.
Defensive patterns
Strategy: try-catch
Validate before calling
// Pre-check port field availability static bool HasPortBytes(byte[] p, int offset) => p != null && p.Length >= offset + 2;
Type guard
static bool HasCompletePort(byte[] packet, int offset) => packet != null && offset + 2 <= packet.Length;
Try / catch
try
{
var (remote, data) = ParseSocks5UdpPacket(packet);
}
catch (ArgumentException ex) when (ex.Message.Contains("port incomplete"))
{
// truncated at the port field; mark attempt failed
} Prevention
- Catch the ArgumentException per attempt.
- Confirm the proxy always appends a 2-byte big-endian port after the address.
- Re-validate address-length math for domain-type packets to keep offset correct.
When it happens
Trigger: ParseSocks5UdpPacket has consumed RSV/FRAG/ATYP/address, then packet.Length < offset + 2 before reading the port.
Common situations: Datagram truncated just before the port field; proxy that omits the 2-byte port; earlier address-length misparse leaving the offset wrong so the port read overruns the buffer.
Related errors
- Invalid SOCKS5 UDP packet: too short
- Invalid SOCKS5 UDP packet: IPv4 address incomplete
- Invalid SOCKS5 UDP packet: IPv6 address incomplete
- Invalid SOCKS5 UDP packet: domain length missing
- Invalid SOCKS5 UDP packet: domain incomplete
AI-assisted analysis of 2dust/v2rayN@e01717d832 (2026-08-13).
Data as JSON: /api/errors/dd8d9aca72918ed4.
Report an issue: GitHub.