mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-29 16:21:29 +00:00
LibWasm: Check section lengths when parsing
Sections in WebAssembly give their length in bytes after they're declared. This commit makes sure that length is upheld.
This commit is contained in:
parent
ecc9c5409d
commit
d1cfddc177
Notes:
sideshowbarker
2024-07-17 01:00:06 +09:00
Author: https://github.com/dzfrias Commit: https://github.com/SerenityOS/serenity/commit/d1cfddc177 Pull-request: https://github.com/SerenityOS/serenity/pull/24515
|
@ -1429,46 +1429,48 @@ ParseResult<Module> Module::parse(Stream& stream)
|
||||||
switch (section_id) {
|
switch (section_id) {
|
||||||
case CustomSection::section_id:
|
case CustomSection::section_id:
|
||||||
sections.append(TRY(CustomSection::parse(section_stream)));
|
sections.append(TRY(CustomSection::parse(section_stream)));
|
||||||
continue;
|
break;
|
||||||
case TypeSection::section_id:
|
case TypeSection::section_id:
|
||||||
sections.append(TRY(TypeSection::parse(section_stream)));
|
sections.append(TRY(TypeSection::parse(section_stream)));
|
||||||
continue;
|
break;
|
||||||
case ImportSection::section_id:
|
case ImportSection::section_id:
|
||||||
sections.append(TRY(ImportSection::parse(section_stream)));
|
sections.append(TRY(ImportSection::parse(section_stream)));
|
||||||
continue;
|
break;
|
||||||
case FunctionSection::section_id:
|
case FunctionSection::section_id:
|
||||||
sections.append(TRY(FunctionSection::parse(section_stream)));
|
sections.append(TRY(FunctionSection::parse(section_stream)));
|
||||||
continue;
|
break;
|
||||||
case TableSection::section_id:
|
case TableSection::section_id:
|
||||||
sections.append(TRY(TableSection::parse(section_stream)));
|
sections.append(TRY(TableSection::parse(section_stream)));
|
||||||
continue;
|
break;
|
||||||
case MemorySection::section_id:
|
case MemorySection::section_id:
|
||||||
sections.append(TRY(MemorySection::parse(section_stream)));
|
sections.append(TRY(MemorySection::parse(section_stream)));
|
||||||
continue;
|
break;
|
||||||
case GlobalSection::section_id:
|
case GlobalSection::section_id:
|
||||||
sections.append(TRY(GlobalSection::parse(section_stream)));
|
sections.append(TRY(GlobalSection::parse(section_stream)));
|
||||||
continue;
|
break;
|
||||||
case ExportSection::section_id:
|
case ExportSection::section_id:
|
||||||
sections.append(TRY(ExportSection::parse(section_stream)));
|
sections.append(TRY(ExportSection::parse(section_stream)));
|
||||||
continue;
|
break;
|
||||||
case StartSection::section_id:
|
case StartSection::section_id:
|
||||||
sections.append(TRY(StartSection::parse(section_stream)));
|
sections.append(TRY(StartSection::parse(section_stream)));
|
||||||
continue;
|
break;
|
||||||
case ElementSection::section_id:
|
case ElementSection::section_id:
|
||||||
sections.append(TRY(ElementSection::parse(section_stream)));
|
sections.append(TRY(ElementSection::parse(section_stream)));
|
||||||
continue;
|
break;
|
||||||
case CodeSection::section_id:
|
case CodeSection::section_id:
|
||||||
sections.append(TRY(CodeSection::parse(section_stream)));
|
sections.append(TRY(CodeSection::parse(section_stream)));
|
||||||
continue;
|
break;
|
||||||
case DataSection::section_id:
|
case DataSection::section_id:
|
||||||
sections.append(TRY(DataSection::parse(section_stream)));
|
sections.append(TRY(DataSection::parse(section_stream)));
|
||||||
continue;
|
break;
|
||||||
case DataCountSection::section_id:
|
case DataCountSection::section_id:
|
||||||
sections.append(TRY(DataCountSection::parse(section_stream)));
|
sections.append(TRY(DataCountSection::parse(section_stream)));
|
||||||
continue;
|
break;
|
||||||
default:
|
default:
|
||||||
return with_eof_check(stream, ParseError::InvalidIndex);
|
return with_eof_check(stream, ParseError::InvalidIndex);
|
||||||
}
|
}
|
||||||
|
if (!section_stream.is_eof())
|
||||||
|
return ParseError::SectionSizeMismatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Module { move(sections) };
|
return Module { move(sections) };
|
||||||
|
@ -1542,6 +1544,8 @@ ByteString parse_error_to_byte_string(ParseError error)
|
||||||
return "Expected a signed integer immediate";
|
return "Expected a signed integer immediate";
|
||||||
case ParseError::InvalidImmediate:
|
case ParseError::InvalidImmediate:
|
||||||
return "A parsed instruction immediate was invalid for the instruction it was used for";
|
return "A parsed instruction immediate was invalid for the instruction it was used for";
|
||||||
|
case ParseError::SectionSizeMismatch:
|
||||||
|
return "A parsed section did not fulfill its expected size";
|
||||||
case ParseError::UnknownInstruction:
|
case ParseError::UnknownInstruction:
|
||||||
return "A parsed instruction was not known to this parser";
|
return "A parsed instruction was not known to this parser";
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,7 @@ enum class ParseError {
|
||||||
InvalidType,
|
InvalidType,
|
||||||
HugeAllocationRequested,
|
HugeAllocationRequested,
|
||||||
OutOfMemory,
|
OutOfMemory,
|
||||||
|
SectionSizeMismatch,
|
||||||
// FIXME: This should not exist!
|
// FIXME: This should not exist!
|
||||||
NotImplemented,
|
NotImplemented,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue