Skip to content

Commit

Permalink
Increase MAX_WASM_STRING_SIZE slightly (#1650)
Browse files Browse the repository at this point in the history
* Increase MAX_WASM_STRING_SIZE slightly

* Revert "Increase MAX_WASM_STRING_SIZE slightly"

This reverts commit 2f36947.

* Reads a string of unlimited length during parse custom name section

* Reads a string of unlimited length during parse custom name section
  • Loading branch information
trzeciak authored Jul 12, 2024
1 parent 3895cb7 commit 021389c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 15 additions & 4 deletions crates/wasmparser/src/binary_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,14 @@ impl<'a> BinaryReader<'a> {
Ok(Ieee64(value))
}

/// (internal) Reads a fixed-size WebAssembly string from the module.
fn internal_read_string(&mut self, len: usize) -> Result<&'a str> {
let bytes = self.read_bytes(len)?;
str::from_utf8(bytes).map_err(|_| {
BinaryReaderError::new("malformed UTF-8 encoding", self.original_position() - 1)
})
}

/// Reads a WebAssembly string from the module.
/// # Errors
/// If `BinaryReader` has less than up to four bytes remaining, the string's
Expand All @@ -701,10 +709,13 @@ impl<'a> BinaryReader<'a> {
self.original_position() - 1,
));
}
let bytes = self.read_bytes(len)?;
str::from_utf8(bytes).map_err(|_| {
BinaryReaderError::new("malformed UTF-8 encoding", self.original_position() - 1)
})
return self.internal_read_string(len);
}

/// Reads a unlimited WebAssembly string from the module.
pub fn read_unlimited_string(&mut self) -> Result<&'a str> {
let len = self.read_var_u32()? as usize;
return self.internal_read_string(len);
}

#[cold]
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmparser/src/readers/core/names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ 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()?;
let name = reader.read_string()?;
let name = reader.read_unlimited_string()?;
Ok(Naming { index, name })
}
}
Expand Down

0 comments on commit 021389c

Please sign in to comment.