From 7d62ddc64e6d6e873febac92474359e807b9c4dd Mon Sep 17 00:00:00 2001 From: Andrew Gunnerson Date: Thu, 28 Sep 2023 19:20:26 -0400 Subject: [PATCH] ota: Don't preallocate buffer when reading OTA metadata This way we can't run out of memory if the zip entry lists an invalid file size that's much bigger than the actual file. Issue: #157 Signed-off-by: Andrew Gunnerson --- avbroot/src/format/ota.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/avbroot/src/format/ota.rs b/avbroot/src/format/ota.rs index 6e1b923..d03259b 100644 --- a/avbroot/src/format/ota.rs +++ b/avbroot/src/format/ota.rs @@ -521,8 +521,8 @@ pub fn parse_zip_ota_info( let metadata = { let mut entry = zip.by_name(PATH_METADATA_PB)?; - let mut buf = vec![0u8; entry.size() as usize]; - entry.read_exact(&mut buf)?; + let mut buf = Vec::new(); + entry.read_to_end(&mut buf)?; util::read_protobuf::(&buf)? };