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 fn global_config_decode(data: &[u8]) -> Option<GlobalConfig> {
if data.len() < GLOBAL_CONFIG_SIZE {
return None;
}
borsh::from_slice::<GlobalConfig>(&data).ok()
borsh::from_slice::<GlobalConfig>(&data[..GLOBAL_CONFIG_SIZE]).ok()
}
pub fn global_config_parser(
@@ -72,7 +72,7 @@ pub fn pool_decode(data: &[u8]) -> Option<Pool> {
if data.len() < POOL_SIZE {
return None;
}
borsh::from_slice::<Pool>(&data).ok()
borsh::from_slice::<Pool>(&data[..POOL_SIZE]).ok()
}
pub fn pool_parser(