Skip to content

Commit ff5111f

Browse files
authored
Use read_unlimited_string for more strings (#2345)
Effectively for anything that resides in a custom section use the `read_unlimited_string` string helper since the same restrictions for strings in the "main module" don't necessarily apply to custom sections.
1 parent dafe42f commit ff5111f

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl<'a> Subsection<'a> for ComponentName<'a> {
4545
let offset = reader.original_position();
4646
Ok(match id {
4747
0 => {
48-
let name = reader.read_string()?;
48+
let name = reader.read_unlimited_string()?;
4949
if !reader.eof() {
5050
return Err(BinaryReaderError::new(
5151
"trailing data at the end of a name",

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl<'a> CoreDumpSection<'a> {
2929
if reader.read_u8()? != 0 {
3030
bail!(pos, "invalid start byte for core dump name");
3131
}
32-
let name = reader.read_string()?;
32+
let name = reader.read_unlimited_string()?;
3333
if !reader.eof() {
3434
bail!(
3535
reader.original_position(),
@@ -69,7 +69,7 @@ impl<'a> CoreDumpModulesSection<'a> {
6969
if reader.read_u8()? != 0 {
7070
bail!(pos, "invalid start byte for coremodule");
7171
}
72-
modules.push(reader.read_string()?);
72+
modules.push(reader.read_unlimited_string()?);
7373
}
7474
if !reader.eof() {
7575
bail!(
@@ -181,7 +181,7 @@ impl<'a> CoreDumpStackSection<'a> {
181181
if reader.read_u8()? != 0 {
182182
bail!(pos, "invalid start byte for core dump stack name");
183183
}
184-
let name = reader.read_string()?;
184+
let name = reader.read_unlimited_string()?;
185185
let mut frames = vec![];
186186
for _ in 0..reader.read_var_u32()? {
187187
frames.push(CoreDumpStackFrame::from_reader(&mut reader)?);

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,14 @@ impl<'a> Subsection<'a> for Dylink0Subsection<'a> {
7878
}),
7979
WASM_DYLINK_NEEDED => Self::Needed(
8080
(0..reader.read_var_u32()?)
81-
.map(|_| reader.read_string())
81+
.map(|_| reader.read_unlimited_string())
8282
.collect::<Result<_, _>>()?,
8383
),
8484
WASM_DYLINK_EXPORT_INFO => Self::ExportInfo(
8585
(0..reader.read_var_u32()?)
8686
.map(|_| {
8787
Ok(ExportInfo {
88-
name: reader.read_string()?,
88+
name: reader.read_unlimited_string()?,
8989
flags: reader.read()?,
9090
})
9191
})
@@ -95,16 +95,16 @@ impl<'a> Subsection<'a> for Dylink0Subsection<'a> {
9595
(0..reader.read_var_u32()?)
9696
.map(|_| {
9797
Ok(ImportInfo {
98-
module: reader.read_string()?,
99-
field: reader.read_string()?,
98+
module: reader.read_unlimited_string()?,
99+
field: reader.read_unlimited_string()?,
100100
flags: reader.read()?,
101101
})
102102
})
103103
.collect::<Result<_, _>>()?,
104104
),
105105
WASM_DYLINK_RUNTIME_PATH => Self::RuntimePath(
106106
(0..reader.read_var_u32()?)
107-
.map(|_| reader.read_string())
107+
.map(|_| reader.read_unlimited_string())
108108
.collect::<Result<_, _>>()?,
109109
),
110110
ty => Self::Unknown {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub struct ProducersField<'a> {
4646
impl<'a> FromReader<'a> for ProducersField<'a> {
4747
fn from_reader(reader: &mut BinaryReader<'a>) -> Result<Self> {
4848
let offset = reader.original_position();
49-
let name = reader.read_string()?;
49+
let name = reader.read_unlimited_string()?;
5050
match name {
5151
"language" | "sdk" | "processed-by" => {}
5252
_ => bail!(offset, "invalid producers field name: `{name}`"),
@@ -77,8 +77,8 @@ pub struct ProducersFieldValue<'a> {
7777

7878
impl<'a> FromReader<'a> for ProducersFieldValue<'a> {
7979
fn from_reader(reader: &mut BinaryReader<'a>) -> Result<Self> {
80-
let name = reader.read_string()?;
81-
let version = reader.read_string()?;
80+
let name = reader.read_unlimited_string()?;
81+
let version = reader.read_unlimited_string()?;
8282
Ok(ProducersFieldValue { name, version })
8383
}
8484
}

0 commit comments

Comments
 (0)