Skip to content

Commit 4919172

Browse files
Fix possible incomplete read bug on onion packet decode
Pre-existing to this PR, we were reading next packet bytes with io::Read::read, which is not guaranteed to read all the bytes we need, only guaranteed to read *some* bytes. We fix this to be read_exact, which is guaranteed to read all the next hop packet bytes.
1 parent 3bdf795 commit 4919172

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lightning/src/ln/onion_utils.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,8 @@ pub(crate) fn decode_next_hop<D: DecodeInput, R: ReadableArgs<D::Arg>, N: NextPa
725725
return Ok((msg, None)); // We are the final destination for this packet
726726
} else {
727727
let mut new_packet_bytes = N::new(hop_data.len());
728-
let read_pos = chacha_stream.read(new_packet_bytes.as_mut()).unwrap();
728+
let read_pos = hop_data.len() - chacha_stream.read.position() as usize;
729+
chacha_stream.read_exact(&mut new_packet_bytes.as_mut()[..read_pos]).unwrap();
729730
#[cfg(debug_assertions)]
730731
{
731732
// Check two things:

0 commit comments

Comments
 (0)