Details
The negative control (a well-formed example.com A query) parses with zero exceptions, confirming the crash is specific to the malformed compression input.
Impact
Any host able to send UDP to the DNS honeypot's bind address/port (unauthenticated, no UI) can crash the per-packet handler with a single ~18-byte datagram. A low-rate flood (a few packets per second) keeps the event loop logging full tracebacks and burning CPU, degrading the DNS honeypot and its logging pipeline. Availability impact only; no memory disclosure or code execution.
Suggested fix
Make decode_labels iterative-bounded: require every compression pointer to point strictly backward to a not-yet-visited offset, which bounds both cycles and long forward chains in O(message length) with no recursion. (This mirrors dnspython's biggest_pointer design and the zeroconf depth-bound fix.) Replace the bare raise "unknown label encoding" with a real exception, and consider wrapping dns.decode_dns_message(data) in DnsUdpProtocol.datagram_received in a try/except so a malformed packet is logged once rather than escaping to the loop handler.
Verified fix (benign + legitimate backward-compression names still decode; both hostile vectors are bounded to ValueError with no recursion):
def decode_labels(message, offset):
labels = []
return_offset = None
max_allowed_pointer = len(message)
while True:
length, = struct.unpack_from("!B", message, offset)
if (length & 0xC0) == 0xC0:
pointer, = struct.unpack_from("!H", message, offset)
if return_offset is None:
return_offset = offset + 2
target = pointer & 0x3FFF
if target >= max_allowed_pointer:
raise ValueError("invalid DNS compression pointer")
max_allowed_pointer = target
offset = target
continue
if (length & 0xC0) != 0x00:
raise ValueError("unknown label encoding")
offset += 1
if length == 0:
return labels, return_offset if return_offset is not None else offset
labels.append(*struct.unpack_from("!%ds" % length, message, offset))
try:
labels[-1] = labels[-1].decode()
except UnicodeDecodeError:
labels[-1] = str(labels[-1])
offset += length
A fix PR will be supplied from a temporary private fork during the embargo.
Credit
Discovered and reported by tonghuaroot.