Skip to content

Commit 63a245e

Browse files
authored
Merge pull request #925 from valentinewallace/ignore-zlib-compressed-msgs
Ignore messages with zlib-compressed fields
2 parents 5d74cae + 9c344b7 commit 63a245e

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

fuzz/src/router.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
133133
msgs::DecodeError::BadLengthDescriptor => return,
134134
msgs::DecodeError::ShortRead => panic!("We picked the length..."),
135135
msgs::DecodeError::Io(e) => panic!("{:?}", e),
136+
msgs::DecodeError::UnsupportedCompression => return,
136137
}
137138
}
138139
}}

lightning/src/ln/msgs.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ pub enum DecodeError {
6363
/// Error from std::io
6464
Io(/// (C-not exported) as ErrorKind doesn't have a reasonable mapping
6565
::std::io::ErrorKind),
66+
/// The message included zlib-compressed values, which we don't support.
67+
UnsupportedCompression,
6668
}
6769

6870
/// An init message to be sent or received from a peer
@@ -953,6 +955,7 @@ impl fmt::Display for DecodeError {
953955
DecodeError::ShortRead => f.write_str("Packet extended beyond the provided bytes"),
954956
DecodeError::BadLengthDescriptor => f.write_str("A length descriptor in the packet didn't describe the later data correctly"),
955957
DecodeError::Io(ref e) => e.fmt(f),
958+
DecodeError::UnsupportedCompression => f.write_str("We don't support receiving messages with zlib-compressed fields"),
956959
}
957960
}
958961
}
@@ -1634,17 +1637,18 @@ impl Readable for QueryShortChannelIds {
16341637
fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
16351638
let chain_hash: BlockHash = Readable::read(r)?;
16361639

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

16441643
// Must be encoding_type=0 uncompressed serialization. We do not
16451644
// support encoding_type=1 zlib serialization.
1646-
let encoding_type: u8 = Readable::read(r)?;
16471645
if encoding_type != EncodingType::Uncompressed as u8 {
1646+
return Err(DecodeError::UnsupportedCompression);
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 {
16481652
return Err(DecodeError::InvalidValue);
16491653
}
16501654

@@ -1746,17 +1750,18 @@ impl Readable for ReplyChannelRange {
17461750
let number_of_blocks: u32 = Readable::read(r)?;
17471751
let sync_complete: bool = Readable::read(r)?;
17481752

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

17561756
// Must be encoding_type=0 uncompressed serialization. We do not
17571757
// support encoding_type=1 zlib serialization.
1758-
let encoding_type: u8 = Readable::read(r)?;
17591758
if encoding_type != EncodingType::Uncompressed as u8 {
1759+
return Err(DecodeError::UnsupportedCompression);
1760+
}
1761+
1762+
// We expect the encoding_len to always includes the 1-byte
1763+
// encoding_type and that short_channel_ids are 8-bytes each
1764+
if encoding_len == 0 || (encoding_len - 1) % 8 != 0 {
17601765
return Err(DecodeError::InvalidValue);
17611766
}
17621767

lightning/src/ln/peer_handler.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,10 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref> PeerManager<D
783783
}
784784
msgs::DecodeError::BadLengthDescriptor => return Err(PeerHandleError { no_connection_possible: false }),
785785
msgs::DecodeError::Io(_) => return Err(PeerHandleError { no_connection_possible: false }),
786+
msgs::DecodeError::UnsupportedCompression => {
787+
log_debug!(self.logger, "We don't support zlib-compressed message fields, ignoring message");
788+
continue;
789+
}
786790
}
787791
}
788792
};

0 commit comments

Comments
 (0)