From 8e5bb0a1e2213916aca3a6511e1e93e31a1f32a6 Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" Date: Tue, 10 May 2022 13:33:22 -0500 Subject: [PATCH] check file size of accounts cache mmap before indexing (#25077) --- runtime/src/cache_hash_data.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/runtime/src/cache_hash_data.rs b/runtime/src/cache_hash_data.rs index 5e50ae36bb..4071d9cd2c 100644 --- a/runtime/src/cache_hash_data.rs +++ b/runtime/src/cache_hash_data.rs @@ -182,6 +182,10 @@ impl CacheHashData { let mmap = CacheHashDataFile::load_map(&path)?; m1.stop(); stats.read_us = m1.as_us(); + let header_size = std::mem::size_of::
() as u64; + if file_len < header_size { + return Err(std::io::Error::from(std::io::ErrorKind::UnexpectedEof)); + } let cell_size = std::mem::size_of::() as u64; let mut cache_file = CacheHashDataFile { @@ -192,7 +196,10 @@ impl CacheHashData { let header = cache_file.get_header_mut(); let entries = header.count; - let capacity = cell_size * (entries as u64) + std::mem::size_of::
() as u64; + let capacity = cell_size * (entries as u64) + header_size; + if file_len < capacity { + return Err(std::io::Error::from(std::io::ErrorKind::UnexpectedEof)); + } cache_file.capacity = capacity; assert_eq!( capacity, file_len,