mirror of
https://github.com/fluencelabs/parity-wasm
synced 2025-04-25 23:32:15 +00:00
Fix too many locals problem.
This commit is contained in:
parent
256b7f934d
commit
84ea83f40e
@ -23,7 +23,7 @@ pub fn spec(path: &str) {
|
|||||||
match kind {
|
match kind {
|
||||||
CommandKind::AssertMalformed { module, .. } => {
|
CommandKind::AssertMalformed { module, .. } => {
|
||||||
match deserialize_buffer::<Module>(&module.into_vec()) {
|
match deserialize_buffer::<Module>(&module.into_vec()) {
|
||||||
Ok(_) => panic!("Expected invalid module definition, got some module!"),
|
Ok(_) => panic!("Expected invalid module definition, got some module! at line {}", line),
|
||||||
Err(e) => println!("assert_invalid at line {} - success ({:?})", line, e),
|
Err(e) => println!("assert_invalid at line {} - success ({:?})", line, e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,6 +120,14 @@ impl Deserialize for FuncBody {
|
|||||||
// todo: maybe use reader.take(section_length)
|
// todo: maybe use reader.take(section_length)
|
||||||
let mut body_reader = SectionReader::new(reader)?;
|
let mut body_reader = SectionReader::new(reader)?;
|
||||||
let locals: Vec<Local> = CountedList::<Local>::deserialize(&mut body_reader)?.into_inner();
|
let locals: Vec<Local> = CountedList::<Local>::deserialize(&mut body_reader)?.into_inner();
|
||||||
|
|
||||||
|
// The specification obliges us to count the total number of local variables while
|
||||||
|
// decoding the binary format.
|
||||||
|
locals
|
||||||
|
.iter()
|
||||||
|
.try_fold(0u32, |acc, &Local { count, .. }| acc.checked_add(count))
|
||||||
|
.ok_or_else(|| Error::TooManyLocals)?;
|
||||||
|
|
||||||
let instructions = Instructions::deserialize(&mut body_reader)?;
|
let instructions = Instructions::deserialize(&mut body_reader)?;
|
||||||
body_reader.close()?;
|
body_reader.close()?;
|
||||||
Ok(FuncBody { locals: locals, instructions: instructions })
|
Ok(FuncBody { locals: locals, instructions: instructions })
|
||||||
|
@ -145,6 +145,8 @@ pub enum Error {
|
|||||||
InconsistentCode,
|
InconsistentCode,
|
||||||
/// Only flags 0, 1, and 2 are accepted on segments
|
/// Only flags 0, 1, and 2 are accepted on segments
|
||||||
InvalidSegmentFlags(u32),
|
InvalidSegmentFlags(u32),
|
||||||
|
/// Sum of counts of locals is greater than 2^32.
|
||||||
|
TooManyLocals,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Error {
|
impl fmt::Display for Error {
|
||||||
@ -181,6 +183,7 @@ impl fmt::Display for Error {
|
|||||||
Error::UnknownFunctionForm(ref form) => write!(f, "Unknown function form ({})", form),
|
Error::UnknownFunctionForm(ref form) => write!(f, "Unknown function form ({})", form),
|
||||||
Error::InconsistentCode => write!(f, "Number of function body entries and signatures does not match"),
|
Error::InconsistentCode => write!(f, "Number of function body entries and signatures does not match"),
|
||||||
Error::InvalidSegmentFlags(n) => write!(f, "Invalid segment flags: {}", n),
|
Error::InvalidSegmentFlags(n) => write!(f, "Invalid segment flags: {}", n),
|
||||||
|
Error::TooManyLocals => write!(f, "Too many locals"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -218,6 +221,7 @@ impl ::std::error::Error for Error {
|
|||||||
Error::UnknownFunctionForm(_) => "Unknown function form",
|
Error::UnknownFunctionForm(_) => "Unknown function form",
|
||||||
Error::InconsistentCode => "Number of function body entries and signatures does not match",
|
Error::InconsistentCode => "Number of function body entries and signatures does not match",
|
||||||
Error::InvalidSegmentFlags(_) => "Invalid segment flags",
|
Error::InvalidSegmentFlags(_) => "Invalid segment flags",
|
||||||
|
Error::TooManyLocals => "Too many locals",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user