From: Valentine Wallace Date: Fri, 5 Aug 2022 17:15:57 +0000 (-0400) Subject: Fix fuzzer-found underflow X-Git-Tag: v0.0.111~35^2~1 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=81b7b03d4ff7424e61b073b81cf4edf627c8694b;p=rust-lightning Fix fuzzer-found underflow --- diff --git a/lightning/src/onion_message/packet.rs b/lightning/src/onion_message/packet.rs index a3414d844..d4ba28c84 100644 --- a/lightning/src/onion_message/packet.rs +++ b/lightning/src/onion_message/packet.rs @@ -69,7 +69,7 @@ impl LengthReadable for Packet { let public_key = Readable::read(r)?; let mut hop_data = Vec::new(); - let hop_data_len = r.total_bytes() as usize - 66; // 1 (version) + 33 (pubkey) + 32 (HMAC) = 66 + let hop_data_len = r.total_bytes().saturating_sub(66) as usize; // 1 (version) + 33 (pubkey) + 32 (HMAC) = 66 let mut read_idx = 0; while read_idx < hop_data_len { let mut read_buffer = [0; READ_BUFFER_SIZE];