From 7f0278caa845604d021940f5496bcfde46751771 Mon Sep 17 00:00:00 2001 From: Jon Cinque Date: Tue, 19 Oct 2021 00:46:49 +0200 Subject: [PATCH] stake-pool: Add checked math to big vec calc (#2524) --- stake-pool/program/src/big_vec.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/stake-pool/program/src/big_vec.rs b/stake-pool/program/src/big_vec.rs index 0c0f81a672f..385fb3f2f1d 100644 --- a/stake-pool/program/src/big_vec.rs +++ b/stake-pool/program/src/big_vec.rs @@ -90,7 +90,10 @@ impl<'data> BigVec<'data> { len: usize, ) -> Result, ProgramError> { let vec_len = self.len(); - if skip + len > vec_len as usize { + let last_item_index = skip + .checked_add(len) + .ok_or(ProgramError::AccountDataTooSmall)?; + if last_item_index > vec_len as usize { return Err(ProgramError::AccountDataTooSmall); }