Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
Add options to maintain behavior with bincode::options()
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyera Eulberg committed Jul 8, 2020
1 parent 3965bff commit cc01eb9
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions core/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1690,6 +1690,8 @@ fn deserialize_bs58_transaction(bs58_transaction: String) -> Result<(Vec<u8>, Tr
}
bincode::options()
.with_limit(PACKET_DATA_SIZE as u64)
.with_fixint_encoding()
.allow_trailing_bytes()
.deserialize_from(&wire_transaction[..])
.map_err(|err| {
info!("transaction deserialize error: {:?}", err);
Expand Down
2 changes: 2 additions & 0 deletions ledger/src/shred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ impl Shred {
{
let ret = bincode::options()
.with_limit(PACKET_DATA_SIZE as u64)
.with_fixint_encoding()
.allow_trailing_bytes()
.deserialize(&buf[*index..*index + size])?;
*index += size;
Ok(ret)
Expand Down
2 changes: 2 additions & 0 deletions perf/src/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ where
{
bincode::options()
.with_limit(PACKET_DATA_SIZE as u64)
.with_fixint_encoding()
.allow_trailing_bytes()
.deserialize_from(data)
}

Expand Down
2 changes: 2 additions & 0 deletions programs/move_loader/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ impl MoveProcessor {
let mut writer = std::io::Cursor::new(data);
bincode::options()
.with_limit(original_len)
.with_fixint_encoding()
.allow_trailing_bytes()
.serialize_into(&mut writer, &state)
.map_err(map_data_error)?;
if writer.position() < original_len {
Expand Down
2 changes: 2 additions & 0 deletions runtime/src/serde_snapshot/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ impl<'a> TypeContext<'a> for Context {
// (1st of 3 elements) read in map of slots to account storage entries
let storage: HashMap<Slot, Vec<Self::SerializableAccountStorageEntry>> = bincode::options()
.with_limit(serialized_len)
.with_fixint_encoding()
.allow_trailing_bytes()
.deserialize_from(&mut stream)?;

// (2nd of 3 elements) read in write version
Expand Down
4 changes: 4 additions & 0 deletions runtime/src/snapshot_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,8 @@ where
let bank = deserialize_snapshot_data_file(&root_paths.snapshot_file_path, |mut stream| {
let mut bank: Bank = bincode::options()
.with_limit(MAX_SNAPSHOT_DATA_FILE_SIZE)
.with_fixint_encoding()
.allow_trailing_bytes()
.deserialize_from(&mut stream)?;

info!("Rebuilding accounts...");
Expand Down Expand Up @@ -760,6 +762,8 @@ where
info!("Rebuilding status cache...");
let slot_deltas: Vec<BankSlotDelta> = bincode::options()
.with_limit(MAX_SNAPSHOT_DATA_FILE_SIZE)
.with_fixint_encoding()
.allow_trailing_bytes()
.deserialize_from(stream)?;
Ok(slot_deltas)
})?;
Expand Down
2 changes: 2 additions & 0 deletions sdk/src/program_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ where
let limit = crate::packet::PACKET_DATA_SIZE as u64;
bincode::options()
.with_limit(limit)
.with_fixint_encoding() // As per https://github.com/servo/bincode/issues/333, these two options are needed
.allow_trailing_bytes() // to retain the behavior of bincode::deserialize with the new `options()` method
.deserialize_from(instruction_data)
.map_err(|_| InstructionError::InvalidInstructionData)
}
Expand Down

0 comments on commit cc01eb9

Please sign in to comment.