Skip to content

Commit 021389c

Browse files
authored
Increase MAX_WASM_STRING_SIZE slightly (#1650)
* 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
1 parent 3895cb7 commit 021389c

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

crates/wasmparser/src/binary_reader.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,14 @@ impl<'a> BinaryReader<'a> {
688688
Ok(Ieee64(value))
689689
}
690690

691+
/// (internal) Reads a fixed-size WebAssembly string from the module.
692+
fn internal_read_string(&mut self, len: usize) -> Result<&'a str> {
693+
let bytes = self.read_bytes(len)?;
694+
str::from_utf8(bytes).map_err(|_| {
695+
BinaryReaderError::new("malformed UTF-8 encoding", self.original_position() - 1)
696+
})
697+
}
698+
691699
/// Reads a WebAssembly string from the module.
692700
/// # Errors
693701
/// If `BinaryReader` has less than up to four bytes remaining, the string's
@@ -701,10 +709,13 @@ impl<'a> BinaryReader<'a> {
701709
self.original_position() - 1,
702710
));
703711
}
704-
let bytes = self.read_bytes(len)?;
705-
str::from_utf8(bytes).map_err(|_| {
706-
BinaryReaderError::new("malformed UTF-8 encoding", self.original_position() - 1)
707-
})
712+
return self.internal_read_string(len);
713+
}
714+
715+
/// Reads a unlimited WebAssembly string from the module.
716+
pub fn read_unlimited_string(&mut self) -> Result<&'a str> {
717+
let len = self.read_var_u32()? as usize;
718+
return self.internal_read_string(len);
708719
}
709720

710721
#[cold]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ 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-
let name = reader.read_string()?;
36+
let name = reader.read_unlimited_string()?;
3737
Ok(Naming { index, name })
3838
}
3939
}

0 commit comments

Comments
 (0)