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

Commit 3863914

Browse files
token-2022: fix handling for extensions with no data (#2858)
* Add failing test * Fix
1 parent 448e75f commit 3863914

File tree

1 file changed

+23
-1
lines changed
  • token/program-2022/src/extension

1 file changed

+23
-1
lines changed

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ fn get_extension_types(tlv_data: &[u8]) -> Result<Vec<ExtensionType>, ProgramErr
115115
let mut start_index = 0;
116116
while start_index < tlv_data.len() {
117117
let tlv_indices = get_tlv_indices(start_index);
118-
if tlv_data.len() <= tlv_indices.value_start {
118+
if tlv_data.len() < tlv_indices.value_start {
119119
return Ok(extension_types);
120120
}
121121
let extension_type =
@@ -1531,4 +1531,26 @@ mod test {
15311531
None
15321532
);
15331533
}
1534+
1535+
#[test]
1536+
fn test_extension_with_no_data() {
1537+
let account_size =
1538+
ExtensionType::get_account_len::<Account>(&[ExtensionType::ImmutableOwner]);
1539+
let mut buffer = vec![0; account_size];
1540+
let mut state =
1541+
StateWithExtensionsMut::<Account>::unpack_uninitialized(&mut buffer).unwrap();
1542+
state.base = TEST_ACCOUNT;
1543+
state.pack_base();
1544+
state.init_account_type().unwrap();
1545+
state.init_extension::<ImmutableOwner>().unwrap();
1546+
1547+
assert_eq!(
1548+
get_first_extension_type(state.tlv_data).unwrap(),
1549+
Some(ExtensionType::ImmutableOwner)
1550+
);
1551+
assert_eq!(
1552+
get_extension_types(state.tlv_data).unwrap(),
1553+
vec![ExtensionType::ImmutableOwner]
1554+
);
1555+
}
15341556
}

0 commit comments

Comments
 (0)