Skip to content

Commit 5bdc22e

Browse files
Fix crash due to index-out-of-bounds in feature parsing
This was reported by a user when trying to send a payment using the LDK sample (specifically during route generation iiuc)
1 parent afae12e commit 5bdc22e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lightning/src/ln/features.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,10 +490,11 @@ impl<T: sealed::Context> Features<T> {
490490
/// Converts `Features<T>` to `Features<C>`. Only known `T` features relevant to context `C` are
491491
/// included in the result.
492492
fn to_context_internal<C: sealed::Context>(&self) -> Features<C> {
493-
let byte_count = C::KNOWN_FEATURE_MASK.len();
493+
let from_byte_count = T::KNOWN_FEATURE_MASK.len();
494+
let to_byte_count = C::KNOWN_FEATURE_MASK.len();
494495
let mut flags = Vec::new();
495496
for (i, byte) in self.flags.iter().enumerate() {
496-
if i < byte_count {
497+
if i < from_byte_count && i < to_byte_count {
497498
let known_source_features = T::KNOWN_FEATURE_MASK[i];
498499
let known_target_features = C::KNOWN_FEATURE_MASK[i];
499500
flags.push(byte & known_source_features & known_target_features);

0 commit comments

Comments
 (0)