Skip to content

Commit

Permalink
Fix unknown handling in impl_writeable_tlv_based_enum_upgradable
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
TheBlueMatt committed Mar 26, 2024
1 parent b8b1ef3 commit c9286b2
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lightning/src/util/ser_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,14 @@ macro_rules! impl_writeable_tlv_based_enum_upgradable {
$($($tuple_variant_id => {
Ok(Some($st::$tuple_variant_name(Readable::read(reader)?)))
}),*)*
_ if id % 2 == 1 => Ok(None),
_ if id % 2 == 1 => {
// Assume that a $variant_id was written, not a $tuple_variant_id, and read
// the length prefix and discard the correct number of bytes.
let tlv_len: $crate::util::ser::BigSize = $crate::util::ser::Readable::read(reader)?;
let mut rd = $crate::util::ser::FixedLengthReader::new(reader, tlv_len.0);
rd.eat_remaining().map_err(|_| $crate::ln::msgs::DecodeError::ShortRead)?;
Ok(None)
},
_ => Err($crate::ln::msgs::DecodeError::UnknownRequiredFeature),
}
}
Expand Down

0 comments on commit c9286b2

Please sign in to comment.