Skip to content

keep TYPE0 in Bitmap.from_rdtypes so type bitmaps round trip - #1415

Merged
rthalley merged 1 commit into
rthalley:mainfrom
nab-iha3:bitmap-keep-type0
Nov 6, 2026
Merged

rthalley merged 1 commit into
rthalley:mainfrom
nab-iha3:bitmap-keep-type0

Conversation

@nab-iha3

@nab-iha3 nab-iha3 commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

on main (6f41707), an NSEC read from wire loses TYPE0 when it is read back from text:

>>> rd = dns.rdata.from_wire("IN", "NSEC", b"\x00\x00\x01\xe0", 0, 4)
>>> rd.to_text()
'. TYPE0 A NS'
>>> dns.rdata.from_text("IN", "NSEC", rd.to_text()).to_text()
'. A NS'

Bitmap.from_rdtypes dedups the sorted types against prior_rdtype, which starts at 0, so TYPE0 is always skipped as a duplicate. 5f2f0d7 made from_text accept TYPE0 so a record received with the bit set (e.g. in an AXFR) can be written to a zone file and read back, but the bit is now silently cleared on reload, which is what the discussion in #1403 says can't happen since the bitmap is signed. an NSEC with TYPE0 A NS signed with dns.dnssec.sign() validates as received and fails dns.dnssec.validate() after zone.to_text() and dns.zone.from_text(). NSEC3 and CSYNC go through the same helper. before 5f2f0d7 the same load raised SyntaxError, so this only affects main.

starting prior_rdtype at None, as MandatoryParam does with prior_k, fixes it. added tests for TYPE0 in Bitmap.from_text and wire to text to wire for NSEC, NSEC3 and CSYNC, plus a whatsnew entry since 5f2f0d7 didn't have one.

from_rdtypes skips duplicate types by comparing each sorted type with
prior_rdtype, which started at 0, so TYPE0 was always taken for a
duplicate and dropped.  Since 5f2f0d7 the text parser accepts TYPE0,
but an NSEC, NSEC3, or CSYNC record with the TYPE0 bit set still lost
the bit when read back from text, and the RRSIG covering it no longer
validated.  Start prior_rdtype at None, as MandatoryParam does.
@rthalley
rthalley merged commit e2b4fd8 into rthalley:main Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants