66
77from __future__ import annotations
88
9- import os
109import socket
1110
12- from hypothesis import given , settings
11+ from hypothesis import given
1312from hypothesis import strategies as st
1413
1514from zeroconf import DNSIncoming , DNSNsec , DNSOutgoing , const
15+ from zeroconf ._dns import DNSRecord
1616
1717from .benchmarks .test_incoming import generate_packets
1818
19- # Deterministic in CI; set HYPOTHESIS_PROFILE=long for a deep local run.
20- settings .register_profile ("ci" , derandomize = True , max_examples = 200 , deadline = None )
21- settings .register_profile ("long" , max_examples = 50000 , deadline = None )
22- settings .load_profile (os .environ .get ("HYPOTHESIS_PROFILE" , "ci" ))
23-
24- MAX_PACKET_SIZE = 9194
19+ # Slack past the codec's cap so the fuzzer also probes oversized input
20+ MAX_PACKET_SIZE = const ._MAX_MSG_ABSOLUTE + 256
2521
2622
2723def _nsec_packet () -> bytes :
@@ -43,7 +39,7 @@ def _nsec_packet() -> bytes:
4339CORPUS = [* generate_packets (), _nsec_packet ()]
4440
4541
46- def _parse (data : bytes ) -> list :
42+ def _parse (data : bytes ) -> list [ DNSRecord ] :
4743 """Parse and touch every public surface; any exception is a bug."""
4844 incoming = DNSIncoming (data )
4945 assert isinstance (incoming .valid , bool )
@@ -53,9 +49,20 @@ def _parse(data: bytes) -> list:
5349 assert incoming .questions is not None
5450 answers = incoming .answers ()
5551 assert isinstance (answers , list )
52+ for record in answers :
53+ repr (record )
54+ hash (record )
5655 return answers
5756
5857
58+ def test_corpus_parses_cleanly () -> None :
59+ """Positive control: the fuzz corpus itself must parse fully."""
60+ for packet in CORPUS :
61+ incoming = DNSIncoming (packet )
62+ assert incoming .valid
63+ assert incoming .answers ()
64+
65+
5966@given (data = st .binary (max_size = MAX_PACKET_SIZE ))
6067def test_arbitrary_bytes_never_raise (data : bytes ) -> None :
6168 """Random garbage must parse or fail quietly, and parsing is deterministic."""
0 commit comments