Skip to content

Commit 23e2307

Browse files
committed
superblock: Use fixed vec size to stop unbounded growth
Signed-off-by: Ikey Doherty <[email protected]>
1 parent f5844e7 commit 23e2307

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

crates/superblock/src/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,10 @@ impl Superblock {
188188
/// Note: This will read the minimum necessary bytes to detect the superblock,
189189
/// which is more efficient than reading the entire device.
190190
pub fn from_reader<R: Read + Seek>(reader: &mut R) -> Result<Self, Error> {
191-
let mut bytes = Vec::with_capacity(128 * 1024); // 128KB should cover all superblock offsets
191+
// Preallocate a fixed buffer for the largest superblock we need to read
192+
let mut bytes = vec![0u8; 128 * 1024]; // 128KB covers all superblock offsets
192193
reader.rewind()?;
193-
reader.read_to_end(&mut bytes)?;
194+
reader.read_exact(&mut bytes)?;
194195

195196
Self::from_bytes(&bytes)
196197
}

0 commit comments

Comments
 (0)