lang: Make Anchor use fallback function instead of panicking if ix data.len() is < `8` (#1721)
This commit is contained in:
parent
4ebcc5fb7e
commit
adb90c33d7
|
@ -27,6 +27,7 @@ The minor version will be incremented upon a breaking change and the patch versi
|
|||
* avm: `amv install` switches to the newly installed version after installation finishes ([#1670](https://github.com/project-serum/anchor/pull/1670)).
|
||||
* spl: Re-export the `spl_token` crate ([#1665](https://github.com/project-serum/anchor/pull/1665)).
|
||||
* lang, cli, spl: Update solana toolchain to v1.9.13 ([#1653](https://github.com/project-serum/anchor/pull/1653)).
|
||||
* lang: Use fallback function if ix data length smaller than `8` instead of panicking ([#1721](https://github.com/project-serum/anchor/pull/1721)).
|
||||
|
||||
## [0.23.0] - 2022-03-20
|
||||
|
||||
|
|
|
@ -143,16 +143,21 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
|
|||
// Split the instruction data into the first 8 byte method
|
||||
// identifier (sighash) and the serialized instruction data.
|
||||
let mut ix_data: &[u8] = data;
|
||||
let sighash: [u8; 8] = {
|
||||
let sighash: Option<[u8; 8]> = {
|
||||
let mut sighash: [u8; 8] = [0; 8];
|
||||
if ix_data.len() < 8 {
|
||||
None
|
||||
} else {
|
||||
sighash.copy_from_slice(&ix_data[..8]);
|
||||
ix_data = &ix_data[8..];
|
||||
sighash
|
||||
Some(sighash)
|
||||
}
|
||||
};
|
||||
|
||||
// If the method identifier is the IDL tag, then execute an IDL
|
||||
// instruction, injected into all Anchor programs.
|
||||
if cfg!(not(feature = "no-idl")) {
|
||||
if let Some(sighash) = sighash {
|
||||
if sighash == anchor_lang::idl::IDL_IX_TAG.to_le_bytes() {
|
||||
return __private::__idl::__idl_dispatch(
|
||||
program_id,
|
||||
|
@ -161,7 +166,9 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
match sighash {
|
||||
Some(sighash) => {
|
||||
match sighash {
|
||||
#ctor_state_dispatch_arm
|
||||
#(#state_dispatch_arms)*
|
||||
|
@ -172,6 +179,9 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
|
|||
}
|
||||
}
|
||||
}
|
||||
None => #fallback_fn
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -160,7 +160,7 @@ describe("misc", () => {
|
|||
"Program data: jvbowsvlmkcJAAAA",
|
||||
"Program data: zxM5neEnS1kBAgMEBQYHCAkK",
|
||||
"Program data: g06Ei2GL1gIBAgMEBQYHCAkKCw==",
|
||||
"Program 3TEqcc8xhrhdspwbvoamUJe2borm4Nr72JxL66k6rgrh consumed 5395 of 1400000 compute units",
|
||||
"Program 3TEqcc8xhrhdspwbvoamUJe2borm4Nr72JxL66k6rgrh consumed 5418 of 1400000 compute units",
|
||||
"Program 3TEqcc8xhrhdspwbvoamUJe2borm4Nr72JxL66k6rgrh success",
|
||||
];
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ async fn update_foo() {
|
|||
|
||||
let mut pt = ProgramTest::new("zero_copy", zero_copy::id(), None);
|
||||
pt.add_account(foo_pubkey, foo_account);
|
||||
pt.set_compute_max_units(3157);
|
||||
pt.set_compute_max_units(3174);
|
||||
let (mut banks_client, payer, recent_blockhash) = pt.start().await;
|
||||
|
||||
let client = Client::new_with_options(
|
||||
|
|
Loading…
Reference in New Issue