Skip to content

Commit

Permalink
Update some documentation about longer names (#1667)
Browse files Browse the repository at this point in the history
Adding some follow-up documentation to #1650
  • Loading branch information
alexcrichton authored Jul 12, 2024
1 parent 56ee29d commit 8078b66
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions crates/wasmparser/src/binary_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions crates/wasmparser/src/readers/core/names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ pub struct Naming<'a> {
impl<'a> FromReader<'a> for Naming<'a> {
fn from_reader(reader: &mut BinaryReader<'a>) -> Result<Self> {
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 })
}
Expand Down

0 comments on commit 8078b66

Please sign in to comment.