Skip to content

Commit d3b308e

Browse files
Return new DecodeError::ZlibCompressedUnsupported
if we receive a message with zlib-compressed values.
1 parent 311aaec commit d3b308e

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

lightning/src/ln/msgs.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,20 +1637,22 @@ impl Readable for QueryShortChannelIds {
16371637
fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
16381638
let chain_hash: BlockHash = Readable::read(r)?;
16391639

1640-
// We expect the encoding_len to always includes the 1-byte
1641-
// encoding_type and that short_channel_ids are 8-bytes each
16421640
let encoding_len: u16 = Readable::read(r)?;
1643-
if encoding_len == 0 || (encoding_len - 1) % 8 != 0 {
1644-
return Err(DecodeError::InvalidValue);
1645-
}
1641+
let encoding_type: u8 = Readable::read(r)?;
16461642

16471643
// Must be encoding_type=0 uncompressed serialization. We do not
16481644
// support encoding_type=1 zlib serialization.
1649-
let encoding_type: u8 = Readable::read(r)?;
16501645
if encoding_type != EncodingType::Uncompressed as u8 {
1646+
return Err(DecodeError::ZlibCompressedUnsupported);
1647+
}
1648+
1649+
// We expect the encoding_len to always includes the 1-byte
1650+
// encoding_type and that short_channel_ids are 8-bytes each
1651+
if encoding_len == 0 || (encoding_len - 1) % 8 != 0 {
16511652
return Err(DecodeError::InvalidValue);
16521653
}
16531654

1655+
16541656
// Read short_channel_ids (8-bytes each), for the u16 encoding_len
16551657
// less the 1-byte encoding_type
16561658
let short_channel_id_count: u16 = (encoding_len - 1)/8;
@@ -1749,20 +1751,22 @@ impl Readable for ReplyChannelRange {
17491751
let number_of_blocks: u32 = Readable::read(r)?;
17501752
let sync_complete: bool = Readable::read(r)?;
17511753

1752-
// We expect the encoding_len to always includes the 1-byte
1753-
// encoding_type and that short_channel_ids are 8-bytes each
17541754
let encoding_len: u16 = Readable::read(r)?;
1755-
if encoding_len == 0 || (encoding_len - 1) % 8 != 0 {
1756-
return Err(DecodeError::InvalidValue);
1757-
}
1755+
let encoding_type: u8 = Readable::read(r)?;
17581756

17591757
// Must be encoding_type=0 uncompressed serialization. We do not
17601758
// support encoding_type=1 zlib serialization.
1761-
let encoding_type: u8 = Readable::read(r)?;
17621759
if encoding_type != EncodingType::Uncompressed as u8 {
1760+
return Err(DecodeError::ZlibCompressedUnsupported);
1761+
}
1762+
1763+
// We expect the encoding_len to always includes the 1-byte
1764+
// encoding_type and that short_channel_ids are 8-bytes each
1765+
if encoding_len == 0 || (encoding_len - 1) % 8 != 0 {
17631766
return Err(DecodeError::InvalidValue);
17641767
}
17651768

1769+
17661770
// Read short_channel_ids (8-bytes each), for the u16 encoding_len
17671771
// less the 1-byte encoding_type
17681772
let short_channel_id_count: u16 = (encoding_len - 1)/8;

0 commit comments

Comments
 (0)