fix: use fixed-size slices for protocol data parsing

- Improve borsh deserialization safety across all protocol decoders
- Add MarketState support for raydium_amm_v4
- Prevent buffer overflow in data decoding operations
This commit is contained in:
ysq
2025-08-19 17:37:17 +08:00
parent a9ceaa55d3
commit 915209abd8
9 changed files with 50 additions and 18 deletions
@@ -30,7 +30,7 @@ pub struct AmmConfig {
pub const AMM_CONFIG_SIZE: usize = 228;
pub fn amm_config_decode(data: &[u8]) -> Option<AmmConfig> {
borsh::from_slice::<AmmConfig>(&data).ok()
borsh::from_slice::<AmmConfig>(&data[..AMM_CONFIG_SIZE]).ok()
}
pub fn amm_config_parser(
@@ -85,7 +85,7 @@ pub struct PoolState {
pub const POOL_STATE_SIZE: usize = 629;
pub fn pool_state_decode(data: &[u8]) -> Option<PoolState> {
borsh::from_slice::<PoolState>(&data).ok()
borsh::from_slice::<PoolState>(&data[..POOL_STATE_SIZE]).ok()
}
pub fn pool_state_parser(