Fix fuzzer-found underflow

This commit is contained in:
Valentine Wallace 2022-08-05 13:15:57 -04:00
parent b414c0641b
commit 81b7b03d4f
No known key found for this signature in database
GPG key ID: FD3E106A2CE099B4

View file

@ -69,7 +69,7 @@ impl LengthReadable for Packet {
let public_key = Readable::read(r)?; let public_key = Readable::read(r)?;
let mut hop_data = Vec::new(); 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; let mut read_idx = 0;
while read_idx < hop_data_len { while read_idx < hop_data_len {
let mut read_buffer = [0; READ_BUFFER_SIZE]; let mut read_buffer = [0; READ_BUFFER_SIZE];