mirror of
https://github.com/fluencelabs/parity-wasm
synced 2025-06-29 06:32:17 +00:00
malformed test
This commit is contained in:
@ -15,6 +15,7 @@ macro_rules! run_test {
|
|||||||
|
|
||||||
run_test!("address", wasm_address);
|
run_test!("address", wasm_address);
|
||||||
run_test!("address-offset-range.fail", wasm_address_offset_range_fail, fail);
|
run_test!("address-offset-range.fail", wasm_address_offset_range_fail, fail);
|
||||||
|
run_test!("binary", wasm_binary);
|
||||||
run_test!("endianness", wasm_endianness);
|
run_test!("endianness", wasm_endianness);
|
||||||
run_test!("f32", wasm_f32);
|
run_test!("f32", wasm_f32);
|
||||||
run_test!("f32_bitwise", wasm_f32_bitwise);
|
run_test!("f32_bitwise", wasm_f32_bitwise);
|
||||||
|
@ -211,7 +211,9 @@ pub fn spec(name: &str) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
&test::Command::AssertInvalid { line, ref filename, .. } => {
|
&test::Command::AssertInvalid { line, ref filename, .. }
|
||||||
|
| &test::Command::AssertMalformed { line, ref filename, .. }
|
||||||
|
=> {
|
||||||
let module_load = try_load(&outdir, filename);
|
let module_load = try_load(&outdir, filename);
|
||||||
match module_load {
|
match module_load {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
|
@ -47,6 +47,12 @@ pub enum Command {
|
|||||||
filename: String,
|
filename: String,
|
||||||
text: String,
|
text: String,
|
||||||
},
|
},
|
||||||
|
#[serde(rename = "assert_malformed")]
|
||||||
|
AssertMalformed {
|
||||||
|
line: u64,
|
||||||
|
filename: String,
|
||||||
|
text: String,
|
||||||
|
},
|
||||||
#[serde(rename = "action")]
|
#[serde(rename = "action")]
|
||||||
Action {
|
Action {
|
||||||
line: u64,
|
line: u64,
|
||||||
|
@ -52,6 +52,10 @@ pub trait Serialize {
|
|||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// Unexpected end of input
|
/// Unexpected end of input
|
||||||
UnexpectedEof,
|
UnexpectedEof,
|
||||||
|
/// Invalid magic
|
||||||
|
InvalidMagic,
|
||||||
|
/// Unsupported version
|
||||||
|
UnsupportedVersion(u32),
|
||||||
/// Inconsistence between declared and actual length
|
/// Inconsistence between declared and actual length
|
||||||
InconsistentLength {
|
InconsistentLength {
|
||||||
/// Expected length of the definition
|
/// Expected length of the definition
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
use std::io;
|
use std::io;
|
||||||
|
use byteorder::{LittleEndian, ByteOrder};
|
||||||
|
|
||||||
use super::{Deserialize, Serialize, Error, Uint32};
|
use super::{Deserialize, Serialize, Error, Uint32};
|
||||||
use super::section::{
|
use super::section::{
|
||||||
Section, CodeSection, TypeSection, ImportSection, ExportSection, FunctionSection,
|
Section, CodeSection, TypeSection, ImportSection, ExportSection, FunctionSection,
|
||||||
GlobalSection, TableSection, ElementSection, DataSection, MemorySection
|
GlobalSection, TableSection, ElementSection, DataSection, MemorySection
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const WASM_MAGIC_NUMBER: [u8; 4] = [0x00, 0x61, 0x73, 0x6d];
|
||||||
|
|
||||||
/// WebAssembly module
|
/// WebAssembly module
|
||||||
pub struct Module {
|
pub struct Module {
|
||||||
magic: u32,
|
magic: u32,
|
||||||
@ -144,8 +148,18 @@ impl Deserialize for Module {
|
|||||||
|
|
||||||
fn deserialize<R: io::Read>(reader: &mut R) -> Result<Self, Self::Error> {
|
fn deserialize<R: io::Read>(reader: &mut R) -> Result<Self, Self::Error> {
|
||||||
let mut sections = Vec::new();
|
let mut sections = Vec::new();
|
||||||
let magic = Uint32::deserialize(reader)?;
|
|
||||||
let version = Uint32::deserialize(reader)?;
|
let mut magic = [0u8; 4];
|
||||||
|
reader.read(&mut magic)?;
|
||||||
|
if magic != WASM_MAGIC_NUMBER {
|
||||||
|
return Err(Error::InvalidMagic);
|
||||||
|
}
|
||||||
|
|
||||||
|
let version: u32 = Uint32::deserialize(reader)?.into();
|
||||||
|
|
||||||
|
if version != 1 {
|
||||||
|
return Err(Error::UnsupportedVersion(version));
|
||||||
|
}
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match Section::deserialize(reader) {
|
match Section::deserialize(reader) {
|
||||||
@ -156,8 +170,8 @@ impl Deserialize for Module {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Ok(Module {
|
Ok(Module {
|
||||||
magic: magic.into(),
|
magic: LittleEndian::read_u32(&magic),
|
||||||
version: version.into(),
|
version: version,
|
||||||
sections: sections,
|
sections: sections,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user