mirror of
https://github.com/SerenityOS/serenity
synced 2024-09-06 17:06:31 +00:00
LibWasm: Validate that names are UTF-8
This commit is contained in:
parent
9721b63d13
commit
11d81d6487
|
@ -79,7 +79,10 @@ static ParseResult<ByteString> parse_name(Stream& stream)
|
|||
{
|
||||
ScopeLogger<WASM_BINPARSER_DEBUG> logger;
|
||||
auto data = TRY(parse_vector<u8>(stream));
|
||||
return ByteString::copy(data);
|
||||
auto string = ByteString::copy(data);
|
||||
if (!Utf8View(string).validate(Utf8View::AllowSurrogates::No))
|
||||
return ParseError::InvalidUtf8;
|
||||
return string;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
@ -1546,6 +1549,8 @@ ByteString parse_error_to_byte_string(ParseError error)
|
|||
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::InvalidUtf8:
|
||||
return "A parsed string was not valid UTF-8";
|
||||
case ParseError::UnknownInstruction:
|
||||
return "A parsed instruction was not known to this parser";
|
||||
}
|
||||
|
|
|
@ -55,6 +55,7 @@ enum class ParseError {
|
|||
HugeAllocationRequested,
|
||||
OutOfMemory,
|
||||
SectionSizeMismatch,
|
||||
InvalidUtf8,
|
||||
// FIXME: This should not exist!
|
||||
NotImplemented,
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue