TechnitiumSoftware/DnsServer · error · InvalidDomainNameException
Invalid domain name [{domain}]: length cannot exceed 255 byt
Error message
Invalid domain name [{domain}]: length cannot exceed 255 bytes. What it means
Thrown by DomainTree.ConvertToByteKey (the protected key serializer used by the zone/domain radix tree) when a domain name's string length exceeds 255 characters. 255 bytes is the hard RFC 1035 limit for a fully-qualified domain name wire representation; the library enforces it before serializing to the lookup key. Only thrown when throwException is true (the default).
Source
Thrown at DnsServerCore/Dns/Trees/DomainTree.cs:116
}
public DomainTree()
: base(41)
{ }
#endregion
#region protected
protected override byte[] ConvertToByteKey(string domain, bool throwException = true)
{
if (domain.Length == 0)
return [];
if (domain.Length > 255)
{
if (throwException)
throw new InvalidDomainNameException("Invalid domain name [" + domain + "]: length cannot exceed 255 bytes.");
return null;
}
byte[] key = new byte[domain.Length + 1];
int keyOffset = 0;
int labelStart;
int labelEnd = domain.Length - 1;
int labelLength;
int labelChar;
byte labelKeyCode;
int i;
do
{
if (labelEnd < 0)
labelEnd = 0;
View on GitHub (pinned to d0484b6c1e)
Solutions
- Validate domain.Length <= 255 before inserting/querying the tree.
- Reject or truncate the offending record at ingestion (zone load / cache insert) rather than letting it reach the tree.
- If probing for validity, call ConvertToByteKey with throwException=false to get null instead of an exception.
Example fix
// before
_tree.GetOrAdd(veryLongDomain, value);
// after
if (string.IsNullOrEmpty(domain) || domain.Length > 255)
return; // skip invalid name
_tree.GetOrAdd(domain, value); Defensive patterns
Strategy: validation
Validate before calling
bool IsValidDomainLength(string d) => string.IsNullOrEmpty(d) || d.Length <= 255;
Type guard
static bool IsValidDomain(string d) => !string.IsNullOrEmpty(d) && d.Length <= 255 && d.Split('.').All(l => l.Length >= 1 && l.Length <= 63); Prevention
- Validate domain.Length <= 255 before any tree operation.
- Reject over-long names at ingestion (zone load / cache insert).
- Use ConvertToByteKey(domain, throwException:false) when probing.
When it happens
Trigger: Passing a domain name string whose .Length > 255 to any tree operation (TryGet, GetOrAdd, Remove) on a DomainTree-derived tree (AuthZoneTree, cache trees), with the default throwException=true.
Common situations: Storing or querying a malformed/truncated record name from a zone transfer, a misconfigured upstream that synthesizes absurdly long names, or a bug concatenating labels without bounds.
Related errors
- Invalid domain name [{domain}]: label length cannot be 0 byt
- Invalid domain name [{domain}]: label length cannot exceed 6
- Invalid domain name [{domain}]: invalid character [{labelCha
- Zone does not contain SOA record.
- Failed to load DNS zone file: the zone file does not contain
AI-assisted analysis of TechnitiumSoftware/DnsServer@d0484b6c1e (2026-08-13).
Data as JSON: /api/errors/90a7740d1aaa992b.
Report an issue: GitHub.