diff --git a/crates/wasmparser/src/binary_reader.rs b/crates/wasmparser/src/binary_reader.rs index 7f77662dcc..c93187df5d 100644 --- a/crates/wasmparser/src/binary_reader.rs +++ b/crates/wasmparser/src/binary_reader.rs @@ -697,7 +697,9 @@ impl<'a> BinaryReader<'a> { } /// Reads a WebAssembly string from the module. + /// /// # Errors + /// /// If `BinaryReader` has less than up to four bytes remaining, the string's /// length exceeds the remaining bytes, the string's length exceeds /// `limits::MAX_WASM_STRING_SIZE`, or the string contains invalid utf-8. @@ -713,6 +715,10 @@ impl<'a> BinaryReader<'a> { } /// Reads a unlimited WebAssembly string from the module. + /// + /// Note that this is similar to [`BinaryReader::read_string`] except that + /// it will not limit the size of the returned string by + /// `limits::MAX_WASM_STRING_SIZE`. pub fn read_unlimited_string(&mut self) -> Result<&'a str> { let len = self.read_var_u32()? as usize; return self.internal_read_string(len); diff --git a/crates/wasmparser/src/readers/core/names.rs b/crates/wasmparser/src/readers/core/names.rs index ef192acb91..d53211ad8a 100644 --- a/crates/wasmparser/src/readers/core/names.rs +++ b/crates/wasmparser/src/readers/core/names.rs @@ -33,6 +33,9 @@ pub struct Naming<'a> { impl<'a> FromReader<'a> for Naming<'a> { fn from_reader(reader: &mut BinaryReader<'a>) -> Result { let index = reader.read_var_u32()?; + // This seems to match what browsers do where they don't limit the + // length of names in the `name` section while they do limit the names + // in the import and export section for example. let name = reader.read_unlimited_string()?; Ok(Naming { index, name }) }