Skip to content

Commit

Permalink
accounts-db: throw error explicitly for next_account_offset calculati…
Browse files Browse the repository at this point in the history
…on 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 <[email protected]>
  • Loading branch information
HaoranYi and HaoranYi authored Jul 12, 2024
1 parent c365bac commit e6a1812
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion accounts-db/src/append_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e6a1812

Please sign in to comment.