Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit bf10dfd

Browse files
fix possible panic from short data length (#3751)
1 parent 5f3cbc4 commit bf10dfd

File tree

1 file changed

+11
-0
lines changed
  • token/program-2022/src/extension

1 file changed

+11
-0
lines changed

token/program-2022/src/extension/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,9 @@ fn get_extension<S: BaseState, V: Extension>(tlv_data: &[u8]) -> Result<&V, Prog
244244
// get_extension_indices has checked that tlv_data is long enough to include these indices
245245
let length = pod_from_bytes::<Length>(&tlv_data[length_start..value_start])?;
246246
let value_end = value_start.saturating_add(usize::from(*length));
247+
if tlv_data.len() < value_end {
248+
return Err(ProgramError::InvalidAccountData);
249+
}
247250
pod_from_bytes::<V>(&tlv_data[value_start..value_end])
248251
}
249252

@@ -933,6 +936,14 @@ mod test {
933936
state.get_extension::<TransferFeeConfig>(),
934937
Err(ProgramError::InvalidAccountData)
935938
);
939+
940+
// data buffer is too small
941+
let buffer = &MINT_WITH_EXTENSION[..MINT_WITH_EXTENSION.len() - 1];
942+
let state = StateWithExtensions::<Mint>::unpack(buffer).unwrap();
943+
assert_eq!(
944+
state.get_extension::<MintCloseAuthority>(),
945+
Err(ProgramError::InvalidAccountData)
946+
);
936947
}
937948

938949
#[test]

0 commit comments

Comments
 (0)