* Update spl-token to v2.0 (#11884)
* Update account-decoder to spl-token v2.0
* Update transaction-status to spl-token v2.0
* Update rpc to spl-token v2.0
* Update getTokenSupply to pull from Mint directly
* Fixup to spl-token v2.0.1
(cherry picked from commit 76be36c9ce
)
# Conflicts:
# Cargo.lock
# account-decoder/Cargo.toml
# core/Cargo.toml
# core/src/rpc.rs
# transaction-status/Cargo.toml
* Fix non-Cargo.lock conflicts
* Limited Deserialize isn't limiting anything (#10952)
* Add failing test
* Use deserialize_from to enable limit
* Cargo.lock
* chore(deps): bump bincode from 1.2.1 to 1.3.1 (#10867)
* chore(deps): bump bincode from 1.2.1 to 1.3.1
Bumps [bincode](https://github.com/servo/bincode) from 1.2.1 to 1.3.1.
- [Release notes](https://github.com/servo/bincode/releases)
- [Commits](https://github.com/servo/bincode/commits)
Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
* [auto-commit] Update all Cargo lock files
* Switch from deprecated method
* Add options to maintain behavior with bincode::options()
Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: dependabot-buildkite <dependabot-buildkite@noreply.solana.com>
Co-authored-by: Tyera Eulberg <tyera@solana.com>
Co-authored-by: Tyera Eulberg <tyera@solana.com>
Co-authored-by: Tyera Eulberg <teulberg@gmail.com>
Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: dependabot-buildkite <dependabot-buildkite@noreply.solana.com>
This commit is contained in:
@@ -31,7 +31,7 @@ default = [
|
||||
|
||||
[dependencies]
|
||||
assert_matches = { version = "1.3.0", optional = true }
|
||||
bincode = "1.2.1"
|
||||
bincode = "1.3.1"
|
||||
bs58 = "0.3.1"
|
||||
bv = { version = "0.11.1", features = ["serde"] }
|
||||
byteorder = { version = "1.3.4", optional = true }
|
||||
|
@@ -1,4 +1,5 @@
|
||||
use crate::instruction::InstructionError;
|
||||
use bincode::config::Options;
|
||||
|
||||
/// Deserialize with a limit based the maximum amount of data a program can expect to get.
|
||||
/// This function should be used in place of direct deserialization to help prevent OOM errors
|
||||
@@ -7,8 +8,31 @@ where
|
||||
T: serde::de::DeserializeOwned,
|
||||
{
|
||||
let limit = crate::packet::PACKET_DATA_SIZE as u64;
|
||||
bincode::config()
|
||||
.limit(limit)
|
||||
.deserialize(instruction_data)
|
||||
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)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_limited_deserialize() {
|
||||
#[derive(Deserialize, Serialize)]
|
||||
enum Foo {
|
||||
Bar(Vec<u8>),
|
||||
}
|
||||
|
||||
let item = Foo::Bar([1; crate::packet::PACKET_DATA_SIZE - 12].to_vec()); // crate::packet::PACKET_DATA_SIZE - 12: size limit, minus enum variant and vec len() serialized sizes
|
||||
let serialized = bincode::serialize(&item).unwrap();
|
||||
assert!(limited_deserialize::<Foo>(&serialized).is_ok());
|
||||
|
||||
let item = Foo::Bar([1; crate::packet::PACKET_DATA_SIZE - 11].to_vec()); // Extra byte should bump serialized size over the size limit
|
||||
let serialized = bincode::serialize(&item).unwrap();
|
||||
assert!(limited_deserialize::<Foo>(&serialized).is_err());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user