Skip to content

Commit 7f23cb6

Browse files
committed
fix: resolve CI failures on #1731 (attempt 1)
1 parent 7392a1c commit 7f23cb6

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

tests/test_protocol.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff 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"\x04test\x05local\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+
864894
def 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)

0 commit comments

Comments
 (0)