Skip to content

Commit b501cdd

Browse files
committed
fix: extend account resize checks (F-91)
1 parent b91ab7d commit b501cdd

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

transaction-context/src/lib.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,9 +1026,14 @@ impl BorrowedInstructionAccount<'_, '_> {
10261026
#[cfg(not(target_os = "solana"))]
10271027
pub fn can_data_be_resized(&self, new_len: usize) -> Result<(), InstructionError> {
10281028
let old_len = self.get_data().len();
1029-
// Only the owner can change the length of the data
1030-
if new_len != old_len && !self.is_owned_by_current_program() {
1031-
return Err(InstructionError::AccountDataSizeChanged);
1029+
if new_len != old_len {
1030+
if !self.is_owned_by_current_program() {
1031+
// Only the owner can change the length of the data
1032+
return Err(InstructionError::AccountDataSizeChanged);
1033+
} else if self.account.ephemeral() {
1034+
// Ephmeral accounts can only be resized with specialized builtin instruction
1035+
return Err(InstructionError::InvalidRealloc);
1036+
}
10321037
}
10331038
self.transaction_context
10341039
.accounts

0 commit comments

Comments
 (0)