Skip to content

Commit 8078b66

Browse files
authored
Update some documentation about longer names (#1667)
Adding some follow-up documentation to #1650
1 parent 56ee29d commit 8078b66

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

crates/wasmparser/src/binary_reader.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,9 @@ impl<'a> BinaryReader<'a> {
697697
}
698698

699699
/// Reads a WebAssembly string from the module.
700+
///
700701
/// # Errors
702+
///
701703
/// If `BinaryReader` has less than up to four bytes remaining, the string's
702704
/// length exceeds the remaining bytes, the string's length exceeds
703705
/// `limits::MAX_WASM_STRING_SIZE`, or the string contains invalid utf-8.
@@ -713,6 +715,10 @@ impl<'a> BinaryReader<'a> {
713715
}
714716

715717
/// Reads a unlimited WebAssembly string from the module.
718+
///
719+
/// Note that this is similar to [`BinaryReader::read_string`] except that
720+
/// it will not limit the size of the returned string by
721+
/// `limits::MAX_WASM_STRING_SIZE`.
716722
pub fn read_unlimited_string(&mut self) -> Result<&'a str> {
717723
let len = self.read_var_u32()? as usize;
718724
return self.internal_read_string(len);

crates/wasmparser/src/readers/core/names.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ pub struct Naming<'a> {
3333
impl<'a> FromReader<'a> for Naming<'a> {
3434
fn from_reader(reader: &mut BinaryReader<'a>) -> Result<Self> {
3535
let index = reader.read_var_u32()?;
36+
// This seems to match what browsers do where they don't limit the
37+
// length of names in the `name` section while they do limit the names
38+
// in the import and export section for example.
3639
let name = reader.read_unlimited_string()?;
3740
Ok(Naming { index, name })
3841
}

0 commit comments

Comments
 (0)