LibWasm: Validate that names are UTF-8

This commit is contained in:
Diego 2024-06-07 18:44:13 -07:00 committed by Ali Mohammad Pur
parent 7560b640f3
commit c86e89665b
Notes: sideshowbarker 2024-07-17 03:30:41 +09:00
2 changed files with 7 additions and 1 deletions

View File

@ -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";
}

View File

@ -55,6 +55,7 @@ enum class ParseError {
HugeAllocationRequested,
OutOfMemory,
SectionSizeMismatch,
InvalidUtf8,
// FIXME: This should not exist!
NotImplemented,
};