Skip to content

Commit

Permalink
do not serialize executable accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
seanyoung committed Dec 5, 2023
1 parent 45aa8c2 commit efd77f3
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions programs/bpf_loader/src/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,13 @@ fn serialize_parameters_unaligned(
s.write::<u8>(account.is_writable() as u8);
let vm_key_addr = s.write_all(account.get_key().as_ref());
let vm_lamports_addr = s.write::<u64>(account.get_lamports().to_le());
s.write::<u64>((account.get_data().len() as u64).to_le());
let vm_data_addr = s.write_account(&mut account)?;
let vm_data_addr = if account.is_executable() {
s.write::<u64>(0u64.to_le());
0
} else {
s.write::<u64>((account.get_data().len() as u64).to_le());
s.write_account(&mut account)?
};
let vm_owner_addr = s.write_all(account.get_owner().as_ref());
s.write::<u8>(account.is_executable() as u8);
s.write::<u64>((account.get_rent_epoch()).to_le());
Expand Down Expand Up @@ -389,7 +394,7 @@ pub fn deserialize_parameters_unaligned<I: IntoIterator<Item = usize>>(
}
start += size_of::<u64>() // lamports
+ size_of::<u64>(); // data length
if copy_account_data {
if copy_account_data && !borrowed_account.is_executable() {
let data = buffer
.get(start..start + pre_len)
.ok_or(InstructionError::InvalidArgument)?;
Expand Down Expand Up @@ -471,8 +476,13 @@ fn serialize_parameters_aligned(
let vm_key_addr = s.write_all(borrowed_account.get_key().as_ref());
let vm_owner_addr = s.write_all(borrowed_account.get_owner().as_ref());
let vm_lamports_addr = s.write::<u64>(borrowed_account.get_lamports().to_le());
s.write::<u64>((borrowed_account.get_data().len() as u64).to_le());
let vm_data_addr = s.write_account(&mut borrowed_account)?;
let vm_data_addr = if borrowed_account.is_executable() {
s.write::<u64>(0u64.to_le());
0
} else {
s.write::<u64>((borrowed_account.get_data().len() as u64).to_le());
s.write_account(&mut borrowed_account)?
};
s.write::<u64>((borrowed_account.get_rent_epoch()).to_le());
accounts_metadata.push(SerializedAccountMetadata {
original_data_len: borrowed_account.get_data().len(),
Expand Down Expand Up @@ -535,11 +545,14 @@ pub fn deserialize_parameters_aligned<I: IntoIterator<Item = usize>>(
borrowed_account.set_lamports(lamports)?;
}
start += size_of::<u64>(); // lamports
let post_len = LittleEndian::read_u64(
let mut post_len = LittleEndian::read_u64(
buffer
.get(start..)
.ok_or(InstructionError::InvalidArgument)?,
) as usize;
if borrowed_account.is_executable() {
post_len = pre_len;
}
start += size_of::<u64>(); // data length
if post_len.saturating_sub(pre_len) > MAX_PERMITTED_DATA_INCREASE
|| post_len > MAX_PERMITTED_DATA_LENGTH as usize
Expand Down

0 comments on commit efd77f3

Please sign in to comment.