Ensure we read the full TLV stream length when maybe-reading `None`
authorMatt Corallo <git@bluematt.me>
Thu, 28 Mar 2024 22:02:09 +0000 (22:02 +0000)
committerMatt Corallo <git@bluematt.me>
Mon, 8 Apr 2024 16:10:59 +0000 (16:10 +0000)
commitbdf5a6f1fec9c154750aee7f8fbd2ce89c3523ca
tree21c7722bd840ad8cb4a6ac214092030ec9edd0af
parent499ca937acf9adc18e4f874add0c21c9a79bb64b
Ensure we read the full TLV stream length when maybe-reading `None`

If we are reading an object that is `MaybeReadable` in a TLV stream
using `upgradable_required`, it may return early with `Ok(None)`.
In this case, it will not read any further TLVs from the TLV
stream. This is fine, except that we generally expect
`MaybeReadable` always consume the correct number of bytes for the
full object, even if it doesn't understand it.

This could pose a problem, for example, in cases where we're
reading a TLV-stream `MaybeReadable` object inside another
TLV-stream object. In that case, the `MaybeReadable` object may
return `Ok(None)` and not consume all the available bytes, causing
the outer TLV read to fail as the TLV length does not match.
lightning/src/lib.rs
lightning/src/util/ser_macros.rs