mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-20 13:28:13 +03:00
LibWasm: Validate that names are UTF-8
This commit is contained in:
parent
7560b640f3
commit
c86e89665b
Notes:
sideshowbarker
2024-07-17 03:30:41 +09:00
Author: https://github.com/dzfrias Commit: https://github.com/LadybirdBrowser/ladybird/commit/c86e89665b Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/96 Reviewed-by: https://github.com/alimpfard ✅
@ -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 New Issue
Block a user