mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 06:14:46 +00:00
wasm_module: when parsing, and a linking section is not found, reset the cursor
This commit is contained in:
parent
9fef0c319f
commit
473dd371b0
1 changed files with 6 additions and 0 deletions
|
@ -212,10 +212,12 @@ type RelocCtx<'a> = (&'a Bump, &'static str);
|
||||||
|
|
||||||
impl<'a> Parse<RelocCtx<'a>> for RelocationSection<'a> {
|
impl<'a> Parse<RelocCtx<'a>> for RelocationSection<'a> {
|
||||||
fn parse(ctx: RelocCtx<'a>, bytes: &[u8], cursor: &mut usize) -> Result<Self, ParseError> {
|
fn parse(ctx: RelocCtx<'a>, bytes: &[u8], cursor: &mut usize) -> Result<Self, ParseError> {
|
||||||
|
let cursor_reset = *cursor;
|
||||||
let (arena, name) = ctx;
|
let (arena, name) = ctx;
|
||||||
|
|
||||||
if *cursor >= bytes.len() || bytes[*cursor] != SectionId::Custom as u8 {
|
if *cursor >= bytes.len() || bytes[*cursor] != SectionId::Custom as u8 {
|
||||||
// The section we're looking for is missing, which is the same as being empty.
|
// The section we're looking for is missing, which is the same as being empty.
|
||||||
|
*cursor = cursor_reset;
|
||||||
return Ok(RelocationSection::new(arena, name));
|
return Ok(RelocationSection::new(arena, name));
|
||||||
}
|
}
|
||||||
*cursor += 1;
|
*cursor += 1;
|
||||||
|
@ -224,6 +226,7 @@ impl<'a> Parse<RelocCtx<'a>> for RelocationSection<'a> {
|
||||||
let actual_name = <&'a str>::parse(arena, bytes, cursor)?;
|
let actual_name = <&'a str>::parse(arena, bytes, cursor)?;
|
||||||
if actual_name != name {
|
if actual_name != name {
|
||||||
// The section we're looking for is missing, which is the same as being empty.
|
// The section we're looking for is missing, which is the same as being empty.
|
||||||
|
*cursor = cursor_reset;
|
||||||
return Ok(RelocationSection::new(arena, name));
|
return Ok(RelocationSection::new(arena, name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -626,7 +629,9 @@ impl<'a> LinkingSection<'a> {
|
||||||
|
|
||||||
impl<'a> Parse<&'a Bump> for LinkingSection<'a> {
|
impl<'a> Parse<&'a Bump> for LinkingSection<'a> {
|
||||||
fn parse(arena: &'a Bump, bytes: &[u8], cursor: &mut usize) -> Result<Self, ParseError> {
|
fn parse(arena: &'a Bump, bytes: &[u8], cursor: &mut usize) -> Result<Self, ParseError> {
|
||||||
|
let cursor_reset = *cursor;
|
||||||
if *cursor >= bytes.len() || bytes[*cursor] != SectionId::Custom as u8 {
|
if *cursor >= bytes.len() || bytes[*cursor] != SectionId::Custom as u8 {
|
||||||
|
*cursor = cursor_reset;
|
||||||
return Ok(LinkingSection::new(arena));
|
return Ok(LinkingSection::new(arena));
|
||||||
}
|
}
|
||||||
*cursor += 1;
|
*cursor += 1;
|
||||||
|
@ -636,6 +641,7 @@ impl<'a> Parse<&'a Bump> for LinkingSection<'a> {
|
||||||
// Don't fail if it's the wrong section. Let the WasmModule validate presence/absence of sections
|
// Don't fail if it's the wrong section. Let the WasmModule validate presence/absence of sections
|
||||||
let actual_name = <&'a str>::parse(arena, bytes, cursor)?;
|
let actual_name = <&'a str>::parse(arena, bytes, cursor)?;
|
||||||
if actual_name != Self::NAME {
|
if actual_name != Self::NAME {
|
||||||
|
*cursor = cursor_reset;
|
||||||
return Ok(LinkingSection::new(arena));
|
return Ok(LinkingSection::new(arena));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue