Skip to content

Ignore messages with zlib-compressed fields #925

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions fuzz/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
msgs::DecodeError::BadLengthDescriptor => return,
msgs::DecodeError::ShortRead => panic!("We picked the length..."),
msgs::DecodeError::Io(e) => panic!("{:?}", e),
msgs::DecodeError::UnsupportedCompression => return,
}
}
}}
Expand Down
29 changes: 17 additions & 12 deletions lightning/src/ln/msgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ pub enum DecodeError {
/// Error from std::io
Io(/// (C-not exported) as ErrorKind doesn't have a reasonable mapping
::std::io::ErrorKind),
/// The message included zlib-compressed values, which we don't support.
UnsupportedCompression,
}

/// An init message to be sent or received from a peer
Expand Down Expand Up @@ -953,6 +955,7 @@ impl fmt::Display for DecodeError {
DecodeError::ShortRead => f.write_str("Packet extended beyond the provided bytes"),
DecodeError::BadLengthDescriptor => f.write_str("A length descriptor in the packet didn't describe the later data correctly"),
DecodeError::Io(ref e) => e.fmt(f),
DecodeError::UnsupportedCompression => f.write_str("We don't support receiving messages with zlib-compressed fields"),
}
}
}
Expand Down Expand Up @@ -1634,17 +1637,18 @@ impl Readable for QueryShortChannelIds {
fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
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);
}

Expand Down Expand Up @@ -1746,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);
}

Expand Down
4 changes: 4 additions & 0 deletions lightning/src/ln/peer_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,10 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref> PeerManager<D
}
msgs::DecodeError::BadLengthDescriptor => return Err(PeerHandleError { no_connection_possible: false }),
msgs::DecodeError::Io(_) => return Err(PeerHandleError { no_connection_possible: false }),
msgs::DecodeError::UnsupportedCompression => {
log_debug!(self.logger, "We don't support zlib-compressed message fields, ignoring message");
continue;
}
}
}
};
Expand Down