{"record":{"id":"9bb4cd8c082f77a6","repo":"TechnitiumSoftware/DnsServer","slug":"qpm-prefix-limits-for-ipv4-cannot-have-more-than-2","errorCode":null,"errorMessage":"QPM Prefix Limits for IPv4 cannot have more than 255 entries.","messagePattern":"QPM Prefix Limits for IPv4 cannot have more than 255 entries\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Dns/DnsServer.cs","lineNumber":7411,"sourceCode":"                        value = new NetworkAddress(value.Address, _eDnsClientSubnetIPv6PrefixLength);\n                }\n\n                _eDnsClientSubnetIpv6Override = value;\n            }\n        }\n\n        public IReadOnlyDictionary<int, (int, int)> QpmPrefixLimitsIPv4\n        {\n            get { return _qpmPrefixLimitsIPv4; }\n            set\n            {\n                if (value is null)\n                {\n                    _qpmPrefixLimitsIPv4 = new Dictionary<int, (int, int)>();\n                }\n                else if (value.Count > byte.MaxValue)\n                {\n                    throw new ArgumentOutOfRangeException(nameof(QpmPrefixLimitsIPv4), \"QPM Prefix Limits for IPv4 cannot have more than 255 entries.\");\n                }\n                else\n                {\n                    foreach (KeyValuePair<int, (int, int)> qpmPrefixLimit in value)\n                    {\n                        if ((qpmPrefixLimit.Key < 0) || (qpmPrefixLimit.Key > 32))\n                            throw new ArgumentOutOfRangeException(nameof(QpmPrefixLimitsIPv4), \"QPM limit IPv4 prefix valid range is between 0 and 32.\");\n\n                        if ((qpmPrefixLimit.Value.Item1 < 0) || (qpmPrefixLimit.Value.Item2 < 0))\n                            throw new ArgumentOutOfRangeException(nameof(QpmPrefixLimitsIPv4), \"QPM limit value cannot be less than 0.\");\n                    }\n\n                    _qpmPrefixLimitsIPv4 = value;\n                }\n\n                ResetQpsLimitTimer();\n            }\n        }","sourceCodeStart":7393,"sourceCodeEnd":7429,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Dns/DnsServer.cs#L7393-L7429","documentation":"Thrown by the QpmPrefixLimitsIPv4 property setter when the dictionary has more than 255 entries. QPM (Queries Per Minute) prefix limits map IPv4 prefix lengths to rate-limit tuples; the 255-entry cap matches byte serialization. A null value resets to an empty dictionary.","triggerScenarios":"Assigning server.QpmPrefixLimitsIPv4 a dictionary with Count > 255.","commonSituations":"Generating prefix limits for every possible /1 through /32 as separate keys; loading a large external rate-limit config; migrating from a config that did not enforce the cap.","solutions":["Reduce the dictionary to 255 or fewer prefix-length keys (only 33 possible IPv4 prefix lengths exist: 0-32, so this is rarely hit unless duplicates are present).","Check for duplicate keys being inserted under different guises.","Set to null to reset if the limits are not needed."],"exampleFix":"// before\nserver.QpmPrefixLimitsIPv4 = hugeRateMap; // 256+ entries\n\n// after\nserver.QpmPrefixLimitsIPv4 =\n    hugeRateMap.Take(32).ToDictionary(k => k.Key, v => v.Value);","handlingStrategy":"validation","validationCode":"if (qpmV4.Count > 255)\n    qpmV4 = qpmV4.Take(255).ToDictionary(k => k.Key, v => v.Value);\nserver.QpmPrefixLimitsIPv4 = qpmV4;","typeGuard":"static bool IsValidQpmDict(Dictionary<int,(int,int)> d) =>\n    d is null || d.Count <= 255;","tryCatchPattern":"try { server.QpmPrefixLimitsIPv4 = qpmV4; }\ncatch (ArgumentOutOfRangeException) { qpmV4 = qpmV4.Take(255).ToDictionary(k=>k.Key,v=>v.Value); server.QpmPrefixLimitsIPv4 = qpmV4; }","preventionTips":["Only 33 valid IPv4 prefix lengths (0-32) exist — dedupe before building.","Cap dictionary size during generation."],"tags":["dns","qpm","rate-limiting","ipv4","configuration"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}