Fix that lift/lower instructions do not allow to work with offsets bigger than 2gb (#18)

This commit is contained in:
Valery Antopol 2022-04-25 22:51:04 +03:00 committed by GitHub
parent b233bfcadd
commit 522dd91b39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 13 additions and 58 deletions

2
Cargo.lock generated
View File

@ -280,7 +280,7 @@ checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe"
[[package]]
name = "wasmer-interface-types-fl"
version = "0.23.0"
version = "0.23.1"
dependencies = [
"fluence-it-types",
"it-lilo",

View File

@ -1,6 +1,6 @@
[package]
name = "wasmer-interface-types-fl"
version = "0.23.0"
version = "0.23.1"
description = "WebAssembly Interface Types library for Wasmer"
license = "MIT"
authors = ["The Wasmer Engineering Team <engineering@wasmer.io>"]

View File

@ -12,8 +12,6 @@ use it_lilo::lowerer::ILowerer;
use it_lilo::lowerer::LoweredArray;
use it_lilo::traits::DEFAULT_MEMORY_INDEX;
use std::convert::TryInto;
pub(crate) fn array_lift_memory<Instance, Export, LocalImport, Memory, MemoryView>(
instruction: Instruction,
value_type: IType,
@ -37,15 +35,9 @@ where
)
})?;
let offset: u32 = to_native::<i32>(inputs.remove(0), instruction.clone())?
.try_into()
.map_err(|e| (e, "offset").into())
.map_err(|k| InstructionError::from_error_kind(instruction.clone(), k))?;
let offset = to_native::<i32>(inputs.remove(0), instruction.clone())? as u32;
let size: u32 = to_native::<i32>(inputs.remove(0), instruction.clone())?
.try_into()
.map_err(|e| (e, "size").into())
.map_err(|k| InstructionError::from_error_kind(instruction.clone(), k))?;
let size = to_native::<i32>(inputs.remove(0), instruction.clone())? as u32;
log::trace!(
"array.lift_memory: lifting memory for value type: {:?}, popped offset {}, size {}",

View File

@ -9,8 +9,6 @@ use crate::{
use it_lilo::traits::DEFAULT_MEMORY_INDEX;
use std::convert::TryInto;
executable_instruction!(
byte_array_lift_memory(instruction: Instruction) -> _ {
move |runtime| -> _ {
@ -32,14 +30,8 @@ executable_instruction!(
)
})?;
let pointer: u32 = to_native::<i32>(inputs.remove(0), instruction.clone())?
.try_into()
.map_err(|e| (e, "pointer").into())
.map_err(|k| InstructionError::from_error_kind(instruction.clone(), k))?;
let length: u32 = to_native::<i32>(inputs.remove(0), instruction.clone())?
.try_into()
.map_err(|e| (e, "length").into())
.map_err(|k| InstructionError::from_error_kind(instruction.clone(), k))?;
let pointer = to_native::<i32>(inputs.remove(0), instruction.clone())? as u32;
let length = to_native::<i32>(inputs.remove(0), instruction.clone())? as u32;
let memory_view = memory.view();
@ -73,17 +65,9 @@ executable_instruction!(
)
})?;
let array_pointer: u32 = to_native::<i32>(inputs.remove(0), instruction.clone())?
.try_into()
.map_err(|e| (e, "pointer").into())
.map_err(|k| InstructionError::from_error_kind(instruction.clone(), k))?;
let array_pointer = to_native::<i32>(inputs.remove(0), instruction.clone())? as u32;
let array: Vec<u8> = to_native(inputs.remove(0), instruction.clone())?;
let length: u32 = array.len().try_into().map_err(|_| {
InstructionError::from_error_kind(
instruction.clone(),
InstructionErrorKind::NegativeValue { subject: "array_length" },
)
})?;
let length = array.len() as u32;
let instance = &mut runtime.wasm_instance;
let memory_index = DEFAULT_MEMORY_INDEX;

View File

@ -9,8 +9,6 @@ use it_lilo::lifter::ILifter;
use it_lilo::lowerer::ILowerer;
use it_lilo::traits::DEFAULT_MEMORY_INDEX;
use std::convert::TryInto;
pub(crate) fn record_lift_memory<Instance, Export, LocalImport, Memory, MemoryView>(
record_type_id: u64,
instruction: Instruction,
@ -34,10 +32,7 @@ where
)
})?;
let offset: u32 = to_native::<i32>(inputs.remove(0), instruction.clone())?
.try_into()
.map_err(|e| (e, "offset").into())
.map_err(|k| InstructionError::from_error_kind(instruction.clone(), k))?;
let offset: u32 = to_native::<i32>(inputs.remove(0), instruction.clone())? as u32;
// TODO: size = 0
let instance = &runtime.wasm_instance;

View File

@ -9,8 +9,6 @@ use crate::{
use it_lilo::traits::DEFAULT_MEMORY_INDEX;
use std::convert::TryInto;
executable_instruction!(
string_lift_memory(instruction: Instruction) -> _ {
move |runtime| -> _ {
@ -32,14 +30,8 @@ executable_instruction!(
)
})?;
let pointer: u32 = to_native::<i32>(inputs.remove(0), instruction.clone())?
.try_into()
.map_err(|e| (e, "pointer").into())
.map_err(|k| InstructionError::from_error_kind(instruction.clone(), k))?;
let length: u32 = to_native::<i32>(inputs.remove(0), instruction.clone())?
.try_into()
.map_err(|e| (e, "length").into())
.map_err(|k| InstructionError::from_error_kind(instruction.clone(), k))?;
let pointer = to_native::<i32>(inputs.remove(0), instruction.clone())? as u32;
let length = to_native::<i32>(inputs.remove(0), instruction.clone())? as u32;
let memory_view = memory.view();
if length == 0 {
@ -74,18 +66,10 @@ executable_instruction!(
)
})?;
let string_pointer: u32 = to_native::<i32>(inputs.remove(0), instruction.clone())?
.try_into()
.map_err(|e| (e, "pointer").into())
.map_err(|k| InstructionError::from_error_kind(instruction.clone(), k))?;
let string_pointer = to_native::<i32>(inputs.remove(0), instruction.clone())? as u32;
let string: String = to_native(inputs.remove(0), instruction.clone())?;
let string_bytes = string.as_bytes();
let string_length: u32 = string_bytes.len().try_into().map_err(|_| {
InstructionError::from_error_kind(
instruction.clone(),
InstructionErrorKind::NegativeValue { subject: "string_length" },
)
})?;
let string_length: u32 = string_bytes.len() as u32;
let instance = &mut runtime.wasm_instance;
let memory_index = DEFAULT_MEMORY_INDEX;