Skip to content

Commit ecda130

Browse files
committed
Allow MaybeReadable to not fully read in upgradable_option
Whils this is generally not supported, issues in our `MaybeReadable` implementations may occur, and we should try to be robust against them.
1 parent 8e161e8 commit ecda130

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lightning/src/util/ser_macros.rs

+11
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,17 @@ macro_rules! _decode_tlv {
400400
// but we can no longer understand it.
401401
($outer_reader: expr, $reader: expr, $field: ident, upgradable_option) => {{
402402
$field = $crate::util::ser::MaybeReadable::read(&mut $reader)?;
403+
if $field.is_none() {
404+
#[cfg(not(debug_assertions))] {
405+
// In general, MaybeReadable implementations are required to consume all the bytes
406+
// of the object even if they don't understand it, but due to a bug in the
407+
// serialization format for `impl_writeable_tlv_based_enum_upgradable` we sometimes
408+
// don't know how many bytes that is. In such cases, we'd like to spuriously allow
409+
// TLV length mismatches, which we do here by calling `eat_remaining` so that the
410+
// `s.bytes_remain()` check in `_decode_tlv_stream_range` doesn't fail.
411+
$reader.eat_remaining()?;
412+
}
413+
}
403414
}};
404415
($outer_reader: expr, $reader: expr, $field: ident, (option: $trait: ident $(, $read_arg: expr)?)) => {{
405416
$field = Some($trait::read(&mut $reader $(, $read_arg)*)?);

0 commit comments

Comments
 (0)