From 5303e7708bd2edc05c609252abcc5baae9e7ca33 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 29 Aug 2017 06:16:22 -0700 Subject: [PATCH] Handle wasmparser errors gracefully. --- lib/wasm/src/module_translator.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/wasm/src/module_translator.rs b/lib/wasm/src/module_translator.rs index 10dbbbc43b..11acbb1b4a 100644 --- a/lib/wasm/src/module_translator.rs +++ b/lib/wasm/src/module_translator.rs @@ -1,6 +1,6 @@ //! Translation skeletton that traverses the whole WebAssembly module and call helper functions //! to deal with each part of it. -use wasmparser::{ParserState, SectionCode, ParserInput, Parser, WasmDecoder}; +use wasmparser::{ParserState, SectionCode, ParserInput, Parser, WasmDecoder, BinaryReaderError}; use sections_translator::{SectionParsingError, parse_function_signatures, parse_import_section, parse_function_section, parse_export_section, parse_memory_section, parse_global_section, parse_table_section, parse_elements_section, @@ -64,6 +64,9 @@ pub fn translate_module(data: &Vec, let mut parser = Parser::new(data.as_slice()); match *parser.read() { ParserState::BeginWasm { .. } => {} + ParserState::Error(BinaryReaderError { message, offset }) => { + return Err(format!("at offset {}: {}", offset, message)); + } ref s @ _ => panic!("modules should begin properly: {:?}", s), } let mut signatures = None;