From 9c344b714c48c6452bcd4dc47e192f0a70e8d8ff Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Wed, 19 May 2021 15:15:41 -0400 Subject: [PATCH] Return new DecodeError::UnsupportedCompression if we receive a message with zlib-compressed values. --- lightning/src/ln/msgs.rs | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index d5ad0205..5ae6955d 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -1637,17 +1637,18 @@ impl Readable for QueryShortChannelIds { fn read(r: &mut R) -> Result { let chain_hash: BlockHash = Readable::read(r)?; - // We expect the encoding_len to always includes the 1-byte - // encoding_type and that short_channel_ids are 8-bytes each let encoding_len: u16 = Readable::read(r)?; - if encoding_len == 0 || (encoding_len - 1) % 8 != 0 { - return Err(DecodeError::InvalidValue); - } + let encoding_type: u8 = Readable::read(r)?; // Must be encoding_type=0 uncompressed serialization. We do not // support encoding_type=1 zlib serialization. - let encoding_type: u8 = Readable::read(r)?; if encoding_type != EncodingType::Uncompressed as u8 { + return Err(DecodeError::UnsupportedCompression); + } + + // We expect the encoding_len to always includes the 1-byte + // encoding_type and that short_channel_ids are 8-bytes each + if encoding_len == 0 || (encoding_len - 1) % 8 != 0 { return Err(DecodeError::InvalidValue); } @@ -1749,17 +1750,18 @@ impl Readable for ReplyChannelRange { let number_of_blocks: u32 = Readable::read(r)?; let sync_complete: bool = Readable::read(r)?; - // We expect the encoding_len to always includes the 1-byte - // encoding_type and that short_channel_ids are 8-bytes each let encoding_len: u16 = Readable::read(r)?; - if encoding_len == 0 || (encoding_len - 1) % 8 != 0 { - return Err(DecodeError::InvalidValue); - } + let encoding_type: u8 = Readable::read(r)?; // Must be encoding_type=0 uncompressed serialization. We do not // support encoding_type=1 zlib serialization. - let encoding_type: u8 = Readable::read(r)?; if encoding_type != EncodingType::Uncompressed as u8 { + return Err(DecodeError::UnsupportedCompression); + } + + // We expect the encoding_len to always includes the 1-byte + // encoding_type and that short_channel_ids are 8-bytes each + if encoding_len == 0 || (encoding_len - 1) % 8 != 0 { return Err(DecodeError::InvalidValue); } -- 2.30.2