named-data / python-ndn

An NDN client library with AsyncIO support in Python 3
https://python-ndn.readthedocs.io/en/latest
Apache License 2.0
24 stars 17 forks source link

Name components with TLV type greater than 65535 should be rejected #35

Closed Pesa closed 2 years ago

Pesa commented 2 years ago

The spec says they're invalid:

TLV-TYPE of name component MUST be in the range 1-65535 (inclusive). Name element containing a sub-element out of this range is invalid and the packet SHOULD be dropped. This requirement overrides the TLV evolvability guidelines.

But Name.from_str and Name.encode happily accept them:

>>> Name.from_str("/a/123456=foo")
[bytearray(b'\x08\x01a'), bytearray(b'\xfe\x00\x01\xe2@\x03foo')]
>>> Name.encode(Name.from_str("/a/123456=foo"))
bytearray(b'\x07\x0c\x08\x01a\xfe\x00\x01\xe2@\x03foo')

I haven't checked the decoding routines but similar checks should be added there too.

Pesa commented 2 years ago

Type == 0 is also invalid and should be rejected.