Check argument sized >= 12 bytes after header ends
@@ -44,11 +44,12 @@ pub fn validate_next_args(
input: &Vec<u8>,
args_abi: Vec<(Type, u16)>,
) -> Result<Vec<Vec<u8>>, &'static str> {
- let mut start_pos: usize = 0;
- let mut end_pos: usize = 0;
+ let mut start_pos: usize = SIDE_EFFECT_HEADER_SIZE;
+ let mut end_pos: usize = SIDE_EFFECT_HEADER_SIZE;
let mut args_bytes: Vec<Vec<u8>> = vec![];
for (arg_type, arg_size) in args_abi {
+ println!("curr arg size {:?} ", arg_size);
// ToDo: Eliminate possible casting err since as takes only lower bytes - ABI should be in usize
end_pos += arg_size as usize;
args_bytes.push(validate_next_arg(input, arg_type, start_pos, end_pos)?);
@@ -58,6 +59,7 @@ pub fn validate_next_args(
Ok(args_bytes)
}
+pub const SIDE_EFFECT_HEADER_SIZE: usize = 12;
pub const TARGET_ID_SIZE: usize = 4;
pub const SIDE_EFFECT_NAME_SIZE: usize = 4;
pub const SIDE_EFFECT_TYPE_SIZE: usize = 4;
@@ -69,7 +71,7 @@ pub type RawSideEffectHeader = [[u8; 4]; 3];
pub fn read_raw_side_effect_header(input: Vec<u8>) -> Result<RawSideEffectHeader, &'static str> {
ensure_str_err(
- input.len() != 12,
+ input.len() >= SIDE_EFFECT_HEADER_SIZE,
"Side Effect Raw Header can't be shorter than 12 bytes",
)?;
