Skip to content

Commit c9286b2

Browse files
committed
Fix unknown handling in impl_writeable_tlv_based_enum_upgradable
`impl_writeable_tlv_based_enum_upgradable` professed to supporting upgrades by returning `None` from `MaybeReadable` when unknown variants written by newer versions of LDK were read. However, it generally didn't support this as it didn't discard bytes for unknown types, resulting in corrupt reading. This is fixed here for enum variants written as a TLV stream, however we don't have a length prefix for tuple enum variants, so the documentation on the macro is updated to mention that downgrades are not supported for tuple variants.
1 parent b8b1ef3 commit c9286b2

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lightning/src/util/ser_macros.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,14 @@ macro_rules! impl_writeable_tlv_based_enum_upgradable {
11021102
$($($tuple_variant_id => {
11031103
Ok(Some($st::$tuple_variant_name(Readable::read(reader)?)))
11041104
}),*)*
1105-
_ if id % 2 == 1 => Ok(None),
1105+
_ if id % 2 == 1 => {
1106+
// Assume that a $variant_id was written, not a $tuple_variant_id, and read
1107+
// the length prefix and discard the correct number of bytes.
1108+
let tlv_len: $crate::util::ser::BigSize = $crate::util::ser::Readable::read(reader)?;
1109+
let mut rd = $crate::util::ser::FixedLengthReader::new(reader, tlv_len.0);
1110+
rd.eat_remaining().map_err(|_| $crate::ln::msgs::DecodeError::ShortRead)?;
1111+
Ok(None)
1112+
},
11061113
_ => Err($crate::ln::msgs::DecodeError::UnknownRequiredFeature),
11071114
}
11081115
}

0 commit comments

Comments
 (0)