Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/zeroconf/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,18 +282,20 @@ def datagram_received(
else:
# https://github.com/python/mypy/issues/1178
addr, port, flow, scope = addrs # type: ignore
log.debug('IPv6 scope_id %d associated to the receiving interface', scope)
if debug:
log.debug('IPv6 scope_id %d associated to the receiving interface', scope)
v6_flow_scope = (flow, scope)

if data_len > _MAX_MSG_ABSOLUTE:
# Guard against oversized packets to ensure bad implementations cannot overwhelm
# the system.
log.debug(
"Discarding incoming packet with length %s, which is larger "
"than the absolute maximum size of %s",
data_len,
_MAX_MSG_ABSOLUTE,
)
if debug:
log.debug(
"Discarding incoming packet with length %s, which is larger "
"than the absolute maximum size of %s",
data_len,
_MAX_MSG_ABSOLUTE,
)
return

now = current_time_millis()
Expand Down
16 changes: 16 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,22 @@ def test_guard_against_oversized_packets():
is None
)

logging.getLogger('zeroconf').setLevel(logging.INFO)

listener.datagram_received(over_sized_packet, ('::1', const._MDNS_PORT, 1, 1))
assert (
zc.cache.async_get_unique(
r.DNSText(
"packet0.local.",
const._TYPE_TXT,
const._CLASS_IN | const._CLASS_UNIQUE,
500,
b'path=/~paulsm/',
)
)
is None
)

zc.close()


Expand Down