From 1bc1a6325dce9c48f5610edccb91a38a1abb3084 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Sun, 11 Feb 2024 20:33:35 +0000 Subject: [PATCH] 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. --- src/rr.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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(()); } -- 2.39.5