From c86e89665b1113f396e7ce83215f3615a959b450 Mon Sep 17 00:00:00 2001 From: Diego <96022404+dzfrias@users.noreply.github.com> Date: Fri, 7 Jun 2024 18:44:13 -0700 Subject: [PATCH] LibWasm: Validate that names are UTF-8 --- Userland/Libraries/LibWasm/Parser/Parser.cpp | 7 ++++++- Userland/Libraries/LibWasm/Types.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) 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, };