File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -861,6 +861,36 @@ def test_nsec_bitmap_zero_length_window_rejected():
861861 assert not any (isinstance (a , r .DNSNsec ) for a in answers )
862862
863863
864+ def test_nsec_bitmap_truncated_window_header_rejected ():
865+ """A bitmap with a trailing byte too short to hold a window header must be rejected.
866+
867+ rdata = compressed next-name (2B) + one valid window block (3B) + 1 stray byte.
868+ On the second loop iteration, offset+2 walks past the record's declared end —
869+ the parser must refuse to read window/length fields from past the record.
870+ """
871+ packet = (
872+ b"\x00 \x00 \x84 \x00 \x00 \x00 \x00 \x02 \x00 \x00 \x00 \x00 "
873+ b"\x04 test\x05 local\x00 "
874+ b"\x00 \x2f \x80 \x01 "
875+ b"\x00 \x00 \x11 \x94 "
876+ b"\x00 \x06 "
877+ b"\xc0 \x0c "
878+ b"\x00 \x01 \x80 "
879+ b"\xff "
880+ b"\xc0 \x0c "
881+ b"\x00 \x0c \x00 \x01 "
882+ b"\x00 \x00 \x11 \x94 "
883+ b"\x00 \x02 "
884+ b"\xc0 \x0c "
885+ )
886+ parsed = r .DNSIncoming (packet )
887+ answers = parsed .answers ()
888+ ptrs = [a for a in answers if isinstance (a , r .DNSPointer )]
889+ assert len (ptrs ) == 1
890+ assert ptrs [0 ].alias == "test.local."
891+ assert not any (isinstance (a , r .DNSNsec ) for a in answers )
892+
893+
864894def test_records_same_packet_share_fate ():
865895 """Test records in the same packet all have the same created time."""
866896 out = r .DNSOutgoing (const ._FLAGS_QR_QUERY | const ._FLAGS_AA )
You can’t perform that action at this time.
0 commit comments