From 5ca13a70a581d07e2410324b12dc104670002a14 Mon Sep 17 00:00:00 2001 From: laizy Date: Tue, 16 Jul 2019 13:19:39 +0800 Subject: [PATCH] check no other sections after data section --- cranelift/wasm/src/module_translator.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cranelift/wasm/src/module_translator.rs b/cranelift/wasm/src/module_translator.rs index 72f257acea..669f9154e8 100644 --- a/cranelift/wasm/src/module_translator.rs +++ b/cranelift/wasm/src/module_translator.rs @@ -1,6 +1,6 @@ //! Translation skeleton that traverses the whole WebAssembly module and call helper functions //! to deal with each part of it. -use crate::environ::{ModuleEnvironment, WasmResult}; +use crate::environ::{ModuleEnvironment, WasmError, WasmResult}; use crate::sections_translator::{ parse_code_section, parse_data_section, parse_element_section, parse_export_section, parse_function_section, parse_global_section, parse_import_section, parse_memory_section, @@ -139,5 +139,13 @@ pub fn translate_module<'data>( parse_data_section(data, environ)?; } + reader.skip_custom_sections()?; + if !reader.eof() { + return Err(WasmError::InvalidWebAssembly { + message: "sections must occur at most once and in the prescribed order", + offset: reader.current_position(), + }); + } + Ok(()) }