From e6a1812bbc14002a11c420432cfc36c9f7a3f417 Mon Sep 17 00:00:00 2001 From: HaoranYi <219428+HaoranYi@users.noreply.github.com> Date: Fri, 12 Jul 2024 16:41:14 -0500 Subject: [PATCH] accounts-db: throw error explicitly for next_account_offset calculation when overflows (#2093) * explicitly throw overflow exception for storage offset calculation * revert fileio overflow error throw. there is another change that unifies offset calc with mmap --------- Co-authored-by: HaoranYi --- accounts-db/src/append_vec.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/accounts-db/src/append_vec.rs b/accounts-db/src/append_vec.rs index 76785d2338371b..12b1d47df2daae 100644 --- a/accounts-db/src/append_vec.rs +++ b/accounts-db/src/append_vec.rs @@ -855,8 +855,12 @@ impl AppendVec { /// data is at the end of each account and is variable sized /// the next account is then aligned on a 64 bit boundary. /// With these helpers, we can skip over reading some of the data depending on what the caller wants. + /// + /// *Safety* - The caller must ensure that the `stored_meta.data_len` won't overflow the calculation. fn next_account_offset(start_offset: usize, stored_meta: &StoredMeta) -> AccountOffsets { - let stored_size_unaligned = STORE_META_OVERHEAD + stored_meta.data_len as usize; + let stored_size_unaligned = STORE_META_OVERHEAD + .checked_add(stored_meta.data_len as usize) + .expect("stored size cannot overflow"); let stored_size_aligned = u64_align!(stored_size_unaligned); let offset_to_end_of_data = start_offset + stored_size_unaligned; let next_account_offset = start_offset + stored_size_aligned;