Update parity-wasm (#198)

This commit is contained in:
Sergei Pepyakin 2019-07-17 14:24:36 +03:00 committed by GitHub
parent b67af25899
commit b1ea069c4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 28 additions and 12 deletions

View File

@ -12,7 +12,7 @@ exclude = [ "/res/*", "/tests/*", "/fuzz/*", "/benches/*" ]
[dependencies] [dependencies]
wasmi-validation = { version = "0.1", path = "validation", default-features = false } wasmi-validation = { version = "0.1", path = "validation", default-features = false }
parity-wasm = { version = "0.31", default-features = false } parity-wasm = { version = "0.39", default-features = false }
memory_units = "0.3.0" memory_units = "0.3.0"
libm = { version = "0.1.2", optional = true } libm = { version = "0.1.2", optional = true }
num-rational = "0.2.2" num-rational = "0.2.2"

View File

@ -421,7 +421,11 @@ impl ModuleInstance {
.map(|es| es.entries()) .map(|es| es.entries())
.unwrap_or(&[]) .unwrap_or(&[])
{ {
let offset_val = match eval_init_expr(element_segment.offset(), &module_ref) { let offset = element_segment
.offset()
.as_ref()
.expect("passive segments are rejected due to validation");
let offset_val = match eval_init_expr(offset, &module_ref) {
RuntimeValue::I32(v) => v as u32, RuntimeValue::I32(v) => v as u32,
_ => panic!("Due to validation elem segment offset should evaluate to i32"), _ => panic!("Due to validation elem segment offset should evaluate to i32"),
}; };
@ -450,7 +454,11 @@ impl ModuleInstance {
} }
for data_segment in module.data_section().map(|ds| ds.entries()).unwrap_or(&[]) { for data_segment in module.data_section().map(|ds| ds.entries()).unwrap_or(&[]) {
let offset_val = match eval_init_expr(data_segment.offset(), &module_ref) { let offset = data_segment
.offset()
.as_ref()
.expect("passive segments are rejected due to validation");
let offset_val = match eval_init_expr(offset, &module_ref) {
RuntimeValue::I32(v) => v as u32, RuntimeValue::I32(v) => v as u32,
_ => panic!("Due to validation data segment offset should evaluate to i32"), _ => panic!("Due to validation data segment offset should evaluate to i32"),
}; };

View File

@ -251,13 +251,14 @@ impl Compiler {
); );
self.sink.emit_br_nez(target); self.sink.emit_br_nez(target);
} }
BrTable(ref table, default) => { BrTable(ref br_table_data) => {
// At this point, the condition value is at the top of the stack. // At this point, the condition value is at the top of the stack.
// But at the point of actual jump the condition will already be // But at the point of actual jump the condition will already be
// popped off. // popped off.
let value_stack_height = context.value_stack.len().saturating_sub(1); let value_stack_height = context.value_stack.len().saturating_sub(1);
let targets = table let targets = br_table_data
.table
.iter() .iter()
.map(|depth| { .map(|depth| {
require_target( require_target(
@ -269,7 +270,7 @@ impl Compiler {
}) })
.collect::<Result<Vec<_>, _>>(); .collect::<Result<Vec<_>, _>>();
let default_target = require_target( let default_target = require_target(
default, br_table_data.default,
value_stack_height, value_stack_height,
&context.frame_stack, &context.frame_stack,
&self.label_stack, &self.label_stack,

View File

@ -8,7 +8,7 @@ repository = "https://github.com/paritytech/wasmi"
description = "Wasm code validator" description = "Wasm code validator"
[dependencies] [dependencies]
parity-wasm = { version = "0.31", default-features = false } parity-wasm = { version = "0.39", default-features = false }
[dev-dependencies] [dev-dependencies]
assert_matches = "1.1" assert_matches = "1.1"

View File

@ -266,8 +266,8 @@ impl<'a> FunctionValidationContext<'a> {
BrIf(depth) => { BrIf(depth) => {
self.validate_br_if(depth)?; self.validate_br_if(depth)?;
} }
BrTable(ref table, default) => { BrTable(ref br_table_data) => {
self.validate_br_table(table, default)?; self.validate_br_table(&*br_table_data.table, br_table_data.default)?;
make_top_frame_polymorphic(&mut self.value_stack, &mut self.frame_stack); make_top_frame_polymorphic(&mut self.value_stack, &mut self.frame_stack);
} }
Return => { Return => {

View File

@ -319,7 +319,11 @@ pub fn validate_module<V: Validator>(module: &Module) -> Result<V::Output, Error
if let Some(data_section) = module.data_section() { if let Some(data_section) = module.data_section() {
for data_segment in data_section.entries() { for data_segment in data_section.entries() {
context.require_memory(data_segment.index())?; context.require_memory(data_segment.index())?;
let init_ty = expr_const_type(data_segment.offset(), context.globals())?; let offset = data_segment
.offset()
.as_ref()
.ok_or_else(|| Error("passive memory segments are not supported".into()))?;
let init_ty = expr_const_type(&offset, context.globals())?;
if init_ty != ValueType::I32 { if init_ty != ValueType::I32 {
return Err(Error("segment offset should return I32".into())); return Err(Error("segment offset should return I32".into()));
} }
@ -330,8 +334,11 @@ pub fn validate_module<V: Validator>(module: &Module) -> Result<V::Output, Error
if let Some(element_section) = module.elements_section() { if let Some(element_section) = module.elements_section() {
for element_segment in element_section.entries() { for element_segment in element_section.entries() {
context.require_table(element_segment.index())?; context.require_table(element_segment.index())?;
let offset = element_segment
let init_ty = expr_const_type(element_segment.offset(), context.globals())?; .offset()
.as_ref()
.ok_or_else(|| Error("passive element segments are not supported".into()))?;
let init_ty = expr_const_type(&offset, context.globals())?;
if init_ty != ValueType::I32 { if init_ty != ValueType::I32 {
return Err(Error("segment offset should return I32".into())); return Err(Error("segment offset should return I32".into()));
} }