TechnitiumSoftware/DnsServer · error · InvalidDomainNameException
Invalid domain name [{domain}]: label length cannot exceed 6
Error message
Invalid domain name [{domain}]: label length cannot exceed 63 bytes. What it means
Thrown by DomainTree.ConvertToByteKey when a single label within the domain name exceeds 63 bytes, the RFC 1035 per-label limit (the length must fit in a 6-bit/2-byte length field on the wire). Only thrown when throwException is true.
Source
Thrown at DnsServerCore/Dns/Trees/DomainTree.cs:149
{
if (labelEnd < 0)
labelEnd = 0;
labelStart = domain.LastIndexOf('.', labelEnd);
labelLength = labelEnd - labelStart;
if (labelLength == 0)
{
if (throwException)
throw new InvalidDomainNameException("Invalid domain name [" + domain + "]: label length cannot be 0 byte.");
return null;
}
if (labelLength > 63)
{
if (throwException)
throw new InvalidDomainNameException("Invalid domain name [" + domain + "]: label length cannot exceed 63 bytes.");
return null;
}
if ((labelLength == 1) && (domain[labelStart + 1] == '*')) //[*]
{
key[keyOffset++] = 1;
}
else
{
for (i = labelStart + 1; i <= labelEnd; i++)
{
labelChar = domain[i];
if (labelChar >= _keyMap.Length)
{
if (throwException)
throw new InvalidDomainNameException("Invalid domain name [" + domain + "]: invalid character [" + labelChar + "] was found.");
View on GitHub (pinned to d0484b6c1e)
Solutions
- Validate each label's length is <= 63 before inserting/querying.
- Split overly long single tokens across multiple labels or store the data in record RDATA instead of the name.
- Probe with throwException=false to silently skip invalid names.
Example fix
// before
_tree.GetOrAdd(longLabelDomain, value);
// after
foreach (var label in domain.Split('.'))
if (label.Length > 63) { /* reject */ return; }
_tree.GetOrAdd(domain, value); Defensive patterns
Strategy: validation
Validate before calling
bool LabelsWithinLimit(string d) => d.Split('.').All(l => l.Length <= 63); Type guard
static bool IsValidDnsName(string d) =>
d.Length <= 255 && d.Split('.').All(l => l.Length >= 1 && l.Length <= 63); Prevention
- Cap each label at 63 octets before tree insertion.
- Store long blobs in RDATA, not in labels.
- Reject over-long single tokens at input parsing.
When it happens
Trigger: Passing a domain name with at least one dot-delimited label whose character count exceeds 63 to a DomainTree-derived tree operation.
Common situations: A TXT/record owner name built from a long token, a base64/blob string used as a label, DKIM/long selector names, or accidentally concatenating labels without splitting.
Related errors
- Invalid domain name [{domain}]: length cannot exceed 255 byt
- Invalid domain name [{domain}]: label length cannot be 0 byt
- 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/11ccbe3e870dd1fb.
Report an issue: GitHub.