diff --git a/program-runtime/src/serialization.rs b/program-runtime/src/serialization.rs index 563b37ad17f..f90f07006b3 100644 --- a/program-runtime/src/serialization.rs +++ b/program-runtime/src/serialization.rs @@ -401,12 +401,14 @@ fn deserialize_parameters_unaligned>( .get(start..start + pre_len) .ok_or(InstructionError::InvalidArgument)?; // The redundant check helps to avoid the expensive data comparison if we can - match borrowed_account.can_data_be_resized(data.len()) { + match borrowed_account.can_data_be_resized(pre_len) { Ok(()) => borrowed_account.set_data_from_slice(data)?, Err(err) if borrowed_account.get_data() != data => return Err(err), _ => {} } start += pre_len; // data + } else if borrowed_account.get_data().len() != pre_len { + borrowed_account.set_data_length(pre_len)?; } start += size_of::() // owner + size_of::() // executable diff --git a/programs/sbf/tests/programs.rs b/programs/sbf/tests/programs.rs index 402f2f91184..7509a0e1673 100644 --- a/programs/sbf/tests/programs.rs +++ b/programs/sbf/tests/programs.rs @@ -3955,12 +3955,12 @@ fn test_cpi_account_data_updates() { let account = bank.get_account(&account_keypair.pubkey()).unwrap(); // deprecated_callee is incapable of resizing accounts assert_eq!(account.data(), b"foobar"); - } else if deprecated_caller && (deprecated_callee || !direct_mapping) { + } else if deprecated_caller { assert_eq!( result.unwrap_err().unwrap(), TransactionError::InstructionError( 0, - if direct_mapping { + if direct_mapping && deprecated_callee { InstructionError::InvalidRealloc } else { InstructionError::AccountDataSizeChanged