-
Couldn't load subscription status.
- Fork 2.2k
Description
The current TLV stream decoder doesn't properly handle unknown even TLV types according to the BOLT specification.
- otherwise, if
typeis unknown:
- if
typeis even:
- MUST fail to parse the
tlv_stream.- otherwise, if
typeis odd:
- MUST discard the next
lengthbytes.
https://github.com/lightning/bolts/blob/master/01-messaging.md#type-length-value-format
The stream decoder first try to find the type to see if its known or not.
// Search the records known to the stream for this type. We'll
// begin the search and recordIdx and walk forward until we find
// it or the next record's type is larger.
rec, newIdx, ok := s.getRecord(typ, recordIdx)
switch {If it's unknown (odd or even) it will treat as an unknown odd:
// Otherwise, the record type is unknown and is odd, discard the
// number of bytes specified by length.
default:
// If the caller provided an initialized TypeMap, record
// the encoded bytes.
var b *bytes.Buffer
writer := io.Discard
if parsedTypes != nil {
b = bytes.NewBuffer(make([]byte, 0, length))
writer = b
}https://github.com/lightningnetwork/lnd/blob/790f8bd2ba76d15218061aee14f7ba5796ac5113/tlv/stream.go
This violates the spec because even types indicate required fields that must be understood by all implementations. If a decoder encounters an unknown even type, it should fail immediately rather than silently discarding it.