chore: simplify lightprograminterface trait#19
chore: simplify lightprograminterface trait#19SwenSchaeferjohann wants to merge 3 commits intomainfrom
Conversation
| let pool_state = PoolState::deserialize(&mut &data[8..]) | ||
| /// Construct from pool state pubkey and its account data. | ||
| pub fn new(pool_state_pubkey: Pubkey, pool_data: &[u8]) -> Result<Self, SwapSdkError> { | ||
| let pool = PoolState::deserialize(&mut &pool_data[8..]) |
There was a problem hiding this comment.
🟡 SwapSdk::new panics on short input data instead of returning an error
The SwapSdk::new constructor at pinocchio/swap/tests/sdk.rs:52 does pool_data[8..] without checking that pool_data has at least 8 bytes. If pool_data.len() < 8, this will panic with an index-out-of-bounds error instead of returning Err(SwapSdkError::ParseError(...)).
Root Cause
The old code (parse_pool_state) had an explicit bounds check:
if data.len() < 8 {
return Err(SwapSdkError::ParseError("Account data too short".to_string()));
}The new code removed this check and directly indexes into the slice:
let pool = PoolState::deserialize(&mut &pool_data[8..])Since the function returns Result<Self, SwapSdkError>, callers expect errors to be returned gracefully, not as panics. The same issue exists in load_specs at line 135 (account.data()[8..]) where short pool state data would also cause a panic.
Impact: Any caller passing data shorter than 8 bytes will get an unrecoverable panic instead of a handleable error. While this is test SDK code, it's still a regression in error handling robustness.
| let pool = PoolState::deserialize(&mut &pool_data[8..]) | |
| if pool_data.len() < 8 { | |
| return Err(SwapSdkError::ParseError("Account data too short".to_string())); | |
| } | |
| let pool = PoolState::deserialize(&mut &pool_data[8..]) |
Was this helpful? React with 👍 or 👎 to provide feedback.
Includes multi-pass cold account lookup fix in test indexer. Co-authored-by: Cursor <cursoragent@cursor.com>
Uh oh!
There was an error while loading. Please reload this page.