@@ -17,6 +17,11 @@ pub fn calculate_token_pool_account_indices(
1717 start_indices : & [ u8 ] ,
1818 remaining_accounts_count : usize ,
1919) -> Result < ( usize , usize ) > {
20+ require ! (
21+ i < start_indices. len( ) ,
22+ CcipRouterError :: InvalidInputsTokenIndices
23+ ) ;
24+
2025 // account set = [start...end)
2126 let start: usize = start_indices[ i] as usize ;
2227 let end: usize = if i == start_indices. len ( ) - 1 {
@@ -355,6 +360,10 @@ pub mod token_admin_registry_writable {
355360
356361 #[ cfg( test) ]
357362 mod tests {
363+ use crate :: {
364+ instructions:: v1:: pools:: calculate_token_pool_account_indices, CcipRouterError ,
365+ } ;
366+
358367 use super :: * ;
359368 use solana_program:: pubkey:: Pubkey ;
360369
@@ -422,5 +431,30 @@ pub mod token_admin_registry_writable {
422431 assert ! ( is( state, 128 + 56 ) ) ;
423432 assert ! ( is( state, 128 + 100 ) ) ;
424433 }
434+
435+ #[ test]
436+ fn token_pool_indices_underflow_overflow ( ) {
437+ let empty_start_indices: [ u8 ; 0 ] = [ ] ;
438+ let full_start_indices = [ 1u8 , 2 , 3 ] ;
439+ let arbitrary_account_count = 5 ;
440+
441+ assert_eq ! (
442+ calculate_token_pool_account_indices(
443+ 0 ,
444+ & empty_start_indices,
445+ arbitrary_account_count
446+ ) ,
447+ Err ( CcipRouterError :: InvalidInputsTokenIndices . into( ) )
448+ ) ;
449+
450+ assert_eq ! (
451+ calculate_token_pool_account_indices(
452+ full_start_indices. len( ) ,
453+ & full_start_indices,
454+ arbitrary_account_count
455+ ) ,
456+ Err ( CcipRouterError :: InvalidInputsTokenIndices . into( ) )
457+ ) ;
458+ }
425459 }
426460}
0 commit comments