Skip to content

Commit 8a0464c

Browse files
authored
Merge pull request lightningdevkit#4705 from TheBlueMatt/2026-05-no-huge-features
Refuse to build feature objects larger than `u16::MAX` bytes
2 parents 63fcc4f + 87c8c32 commit 8a0464c

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

lightning-types/src/features.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,9 @@ impl<T: sealed::Context> Features<T> {
12681268
fn set_bit(&mut self, bit: usize, custom: bool) -> Result<(), ()> {
12691269
let byte_offset = bit / 8;
12701270
let mask = 1 << (bit - 8 * byte_offset);
1271+
if byte_offset >= u16::MAX as usize {
1272+
return Err(());
1273+
}
12711274
if byte_offset < T::KNOWN_FEATURE_MASK.len() && custom {
12721275
if (T::KNOWN_FEATURE_MASK[byte_offset] & mask) != 0 {
12731276
return Err(());

lightning/src/ln/features.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ macro_rules! impl_feature_len_prefixed_write {
4040
}
4141
impl Readable for $features {
4242
fn read<R: io::Read>(r: &mut R) -> Result<Self, DecodeError> {
43-
Ok(Self::from_be_bytes(Vec::<u8>::read(r)?))
43+
let len: u16 = Readable::read(r)?;
44+
let mut bytes = vec![0u8; len as usize];
45+
r.read_exact(&mut bytes[..])?;
46+
Ok(Self::from_be_bytes(bytes))
4447
}
4548
}
4649
};

0 commit comments

Comments
 (0)