{"record":{"id":"11ccbe3e870dd1fb","repo":"TechnitiumSoftware/DnsServer","slug":"invalid-domain-name-domain-label-length-canno-11ccbe","errorCode":null,"errorMessage":"Invalid domain name [{domain}]: label length cannot exceed 63 bytes.","messagePattern":"Invalid domain name \\[(.+?)\\]: label length cannot exceed 63 bytes\\.","errorType":"validation","errorClass":"InvalidDomainNameException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Dns/Trees/DomainTree.cs","lineNumber":149,"sourceCode":"            {\n                if (labelEnd < 0)\n                    labelEnd = 0;\n\n                labelStart = domain.LastIndexOf('.', labelEnd);\n                labelLength = labelEnd - labelStart;\n\n                if (labelLength == 0)\n                {\n                    if (throwException)\n                        throw new InvalidDomainNameException(\"Invalid domain name [\" + domain + \"]: label length cannot be 0 byte.\");\n\n                    return null;\n                }\n\n                if (labelLength > 63)\n                {\n                    if (throwException)\n                        throw new InvalidDomainNameException(\"Invalid domain name [\" + domain + \"]: label length cannot exceed 63 bytes.\");\n\n                    return null;\n                }\n\n                if ((labelLength == 1) && (domain[labelStart + 1] == '*')) //[*]\n                {\n                    key[keyOffset++] = 1;\n                }\n                else\n                {\n                    for (i = labelStart + 1; i <= labelEnd; i++)\n                    {\n                        labelChar = domain[i];\n                        if (labelChar >= _keyMap.Length)\n                        {\n                            if (throwException)\n                                throw new InvalidDomainNameException(\"Invalid domain name [\" + domain + \"]: invalid character [\" + labelChar + \"] was found.\");\n","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Dns/Trees/DomainTree.cs#L131-L167","documentation":"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.","triggerScenarios":"Passing a domain name with at least one dot-delimited label whose character count exceeds 63 to a DomainTree-derived tree operation.","commonSituations":"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.","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."],"exampleFix":"// before\n_tree.GetOrAdd(longLabelDomain, value);\n\n// after\nforeach (var label in domain.Split('.'))\n    if (label.Length > 63) { /* reject */ return; }\n_tree.GetOrAdd(domain, value);","handlingStrategy":"validation","validationCode":"bool LabelsWithinLimit(string d) => d.Split('.').All(l => l.Length <= 63);","typeGuard":"static bool IsValidDnsName(string d) =>\n    d.Length <= 255 && d.Split('.').All(l => l.Length >= 1 && l.Length <= 63);","tryCatchPattern":null,"preventionTips":["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."],"tags":["dns","csharp","validation","rfc-1035","domain-name"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}