From afd8d90f3237e0cffaabb05becbff16f8c8fdd25 Mon Sep 17 00:00:00 2001 From: Diego <96022404+dzfrias@users.noreply.github.com> Date: Mon, 8 Jul 2024 19:04:48 -0700 Subject: [PATCH] LibWasm: Error when parsed section lengths are invalidated --- Userland/Libraries/LibWasm/Parser/Parser.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibWasm/Parser/Parser.cpp b/Userland/Libraries/LibWasm/Parser/Parser.cpp index 464e689d9b7..e0bb54d5cd4 100644 --- a/Userland/Libraries/LibWasm/Parser/Parser.cpp +++ b/Userland/Libraries/LibWasm/Parser/Parser.cpp @@ -1413,10 +1413,8 @@ ParseResult Module::parse(Stream& stream) return with_eof_check(stream, ParseError::InvalidModuleVersion); Vector sections; - for (;;) { + while (!stream.is_eof()) { auto section_id_or_error = stream.read_value(); - if (stream.is_eof()) - break; if (section_id_or_error.is_error()) return with_eof_check(stream, ParseError::ExpectedIndex); @@ -1472,7 +1470,7 @@ ParseResult Module::parse(Stream& stream) default: return with_eof_check(stream, ParseError::InvalidIndex); } - if (!section_stream.is_eof()) + if (section_stream.remaining() != 0) return ParseError::SectionSizeMismatch; }