diff --git a/Userland/Libraries/LibWasm/Parser/Parser.cpp b/Userland/Libraries/LibWasm/Parser/Parser.cpp index 4c32c386798..4e8283157aa 100644 --- a/Userland/Libraries/LibWasm/Parser/Parser.cpp +++ b/Userland/Libraries/LibWasm/Parser/Parser.cpp @@ -79,7 +79,10 @@ static ParseResult parse_name(Stream& stream) { ScopeLogger logger; auto data = TRY(parse_vector(stream)); - return ByteString::copy(data); + auto string = ByteString::copy(data); + if (!Utf8View(string).validate(Utf8View::AllowSurrogates::No)) + return ParseError::InvalidUtf8; + return string; } template @@ -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"; } diff --git a/Userland/Libraries/LibWasm/Types.h b/Userland/Libraries/LibWasm/Types.h index 0a2c7456ae8..891fb5925d8 100644 --- a/Userland/Libraries/LibWasm/Types.h +++ b/Userland/Libraries/LibWasm/Types.h @@ -55,6 +55,7 @@ enum class ParseError { HugeAllocationRequested, OutOfMemory, SectionSizeMismatch, + InvalidUtf8, // FIXME: This should not exist! NotImplemented, };