The vulnerability lies in the zeroconf library's handling of incoming mDNS packets. Specifically, the _read_character_string and _read_string methods within the DNSIncoming class in src/zeroconf/_protocol/incoming.py were found to be vulnerable. These functions are responsible for parsing specific data fields from the mDNS packet payload.
The root cause is an improper handling of length parameters, a vulnerability type known as CWE-130. The functions would read a length value from the packet and use it to slice a portion of the packet data. However, they failed to validate whether this length, when added to the current offset, would exceed the total length of the packet data.
Due to Python's slicing behavior, if the end index of a slice is out of bounds, it doesn't raise an error but instead returns all bytes up to the end of the buffer. The vulnerability arises because even though a truncated payload was read, the internal offset of the parser was still advanced by the full, attacker-controlled length value. This desynchronized the parser's state.
An attacker on the local network could send a specially crafted mDNS response with a record (e.g., TXT, HINFO, A/AAAA) that advertises a very large rdlength (resource data length) but provides only a small payload. The vulnerable functions would read the truncated payload, create a corrupt record, and add it to the application's DNS cache. Subsequent parsing of the packet would fail, but the corrupted data would have already been cached. This allows an attacker to poison the cache with malformed data, which could disrupt services or be a stepping stone for more complex attacks.
The patch addresses this by adding an explicit bounds check in both _read_character_string and _read_string to ensure the declared length does not cause the read to go past the end of the packet data, raising an IncomingDecodeError if the check fails. This prevents the corrupt record from being processed and cached.
The identified vulnerable functions are DNSIncoming._read_character_string and DNSIncoming._read_string because they contain the flawed logic that processes the malicious input without proper validation. These are the functions that would appear in a runtime profile during the exploitation of this vulnerability.