Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions tlv-account-resolution/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ impl ExtraAccountMetaList {
data: &mut [u8],
extra_account_metas: &[ExtraAccountMeta],
) -> Result<(), ProgramError> {
let mut state = TlvStateMut::unpack(data).unwrap();
let mut state = TlvStateMut::unpack(data)?;
let tlv_size = ListView::<ExtraAccountMeta>::size_of(extra_account_metas.len())?;
let (bytes, _) = state.alloc::<T>(tlv_size, false)?;
let mut validation_data = ListView::<ExtraAccountMeta>::init(bytes)?;
Expand All @@ -172,7 +172,7 @@ impl ExtraAccountMetaList {
data: &mut [u8],
extra_account_metas: &[ExtraAccountMeta],
) -> Result<(), ProgramError> {
let mut state = TlvStateMut::unpack(data).unwrap();
let mut state = TlvStateMut::unpack(data)?;
let tlv_size = ListView::<ExtraAccountMeta>::size_of(extra_account_metas.len())?;
let bytes = state.realloc_first::<T>(tlv_size)?;
let mut validation_data = ListView::<ExtraAccountMeta>::init(bytes)?;
Expand Down Expand Up @@ -1761,4 +1761,23 @@ mod tests {
"corrupt validation data must error, not panic"
);
}

#[test]
fn init_and_update_with_malformed_data_error() {
let required_accounts =
[ExtraAccountMeta::new_with_pubkey(&Pubkey::new_unique(), false, true).unwrap()];

// Too short for a TLV header, so the unpack fails.
let mut buffer = vec![1u8; 4];
assert_eq!(
ExtraAccountMetaList::init::<TestInstruction>(&mut buffer, &required_accounts)
.unwrap_err(),
ProgramError::InvalidAccountData,
);
assert_eq!(
ExtraAccountMetaList::update::<TestInstruction>(&mut buffer, &required_accounts)
.unwrap_err(),
ProgramError::InvalidAccountData,
);
}
}
Loading