From: Matt Corallo Date: Sun, 11 Feb 2024 20:33:35 +0000 (+0000) Subject: Fix overflowing subtract in vec preallocation X-Git-Tag: v0.5.4~67 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=1bc1a6325dce9c48f5610edccb91a38a1abb3084;p=dnssec-prover Fix overflowing subtract in vec preallocation If a TXT record comes in with zero length data, we'll overflow in the subtraction and try to allocate much too much data. --- diff --git a/src/rr.rs b/src/rr.rs index 9886e3a..c585555 100644 --- a/src/rr.rs +++ b/src/rr.rs @@ -218,7 +218,7 @@ impl StaticRecord for Txt { format!("{{\"type\":\"txt\",\"name\":\"{}\",\"contents\":{:?}}}", self.name.0, &self.data[..]) } fn read_from_data(name: Name, mut data: &[u8], _wire_packet: &[u8]) -> Result { - let mut parsed_data = Vec::with_capacity(data.len() - 1); + let mut parsed_data = Vec::with_capacity(data.len().saturating_sub(1)); while !data.is_empty() { let len = read_u8(&mut data)? as usize; if data.len() < len { return Err(()); }