From 2f654ca6dd7c86f701bc0c17158eb538f4032b02 Mon Sep 17 00:00:00 2001 From: Brian Carroll Date: Fri, 8 Apr 2022 16:52:36 +0100 Subject: [PATCH] wasm: more meaningful error when NameSection is missing --- compiler/gen_wasm/src/wasm_module/sections.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/compiler/gen_wasm/src/wasm_module/sections.rs b/compiler/gen_wasm/src/wasm_module/sections.rs index 4d30809e1f..12a3f2da24 100644 --- a/compiler/gen_wasm/src/wasm_module/sections.rs +++ b/compiler/gen_wasm/src/wasm_module/sections.rs @@ -1155,6 +1155,10 @@ impl<'a> NameSection<'a> { } pub fn parse(arena: &'a Bump, module_bytes: &[u8], cursor: &mut usize) -> Self { + if *cursor >= module_bytes.len() { + internal_error!("NameSection not found in preloaded object file"); + } + // Custom section ID let section_id_byte = module_bytes[*cursor]; if section_id_byte != Self::ID as u8 {