Add function loading validity checks
This commit is contained in:
parent
2c913e86ed
commit
0a9f9fd6ad
@ -211,7 +211,7 @@ fn build_func_list(wasm: &Module, type_info: &TypeInfo) -> Vec<FuncData> {
|
|||||||
wasm.code_section()
|
wasm.code_section()
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|f| builder.create_indexed(f.0 + offset, f.1))
|
.map(|f| builder.create_indexed(f.0 + offset, f.1).unwrap())
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,7 +211,7 @@ fn build_func_list(wasm: &Module, type_info: &TypeInfo) -> Vec<FuncData> {
|
|||||||
wasm.code_section()
|
wasm.code_section()
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|f| builder.create_indexed(f.0 + offset, f.1))
|
.map(|f| builder.create_indexed(f.0 + offset, f.1).unwrap())
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use wasmparser::{BlockType, FunctionBody, MemoryImmediate, Operator};
|
use wasmparser::{BlockType, FunctionBody, MemoryImmediate, Operator, Result};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
module::TypeInfo,
|
module::{read_checked, TypeInfo},
|
||||||
node::{
|
node::{
|
||||||
BinOp, BinOpType, Block, Br, BrIf, BrTable, Call, CallIndirect, CmpOp, CmpOpType,
|
BinOp, BinOpType, Block, Br, BrIf, BrTable, Call, CallIndirect, CmpOp, CmpOpType,
|
||||||
Expression, FuncData, GetGlobal, GetLocal, If, LabelType, LoadAt, LoadType, MemoryGrow,
|
Expression, FuncData, GetGlobal, GetLocal, If, LabelType, LoadAt, LoadType, MemoryGrow,
|
||||||
@ -248,24 +248,23 @@ impl<'a> Factory<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # Panics
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// Panics if the function is malformed.
|
/// Returns an error if the function is malformed.
|
||||||
#[must_use]
|
pub fn create_indexed(&mut self, index: usize, func: &FunctionBody) -> Result<FuncData> {
|
||||||
pub fn create_indexed(&mut self, index: usize, func: &FunctionBody) -> FuncData {
|
let code = read_checked(func.get_operators_reader()?)?;
|
||||||
let code: Result<Vec<_>, _> = func.get_operators_reader().unwrap().into_iter().collect();
|
let local = read_checked(func.get_locals_reader()?)?;
|
||||||
let local: Result<Vec<_>, _> = func.get_locals_reader().unwrap().into_iter().collect();
|
|
||||||
|
|
||||||
let (num_param, num_result) = self.type_info.by_func_index(index);
|
let (num_param, num_result) = self.type_info.by_func_index(index);
|
||||||
let data = self.build_stat_list(&code.unwrap(), num_result);
|
let data = self.build_stat_list(&code, num_result);
|
||||||
|
|
||||||
FuncData {
|
Ok(FuncData {
|
||||||
local_data: local.unwrap(),
|
local_data: local,
|
||||||
num_result,
|
num_result,
|
||||||
num_param,
|
num_param,
|
||||||
num_stack: data.stack.capacity,
|
num_stack: data.stack.capacity,
|
||||||
code: data.into(),
|
code: data.into(),
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_block(&mut self, ty: BlockType, variant: BlockVariant) {
|
fn start_block(&mut self, ty: BlockType, variant: BlockVariant) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user