From 7966168fea9c5404c41818bf809d21c79db0313e Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Tue, 18 May 2021 01:39:12 +0430 Subject: LibWasm: Turn memory read failures into traps --- .../Libraries/LibWasm/AbstractMachine/Interpreter.cpp | 15 +++++++++------ Userland/Libraries/LibWasm/AbstractMachine/Interpreter.h | 3 +++ 2 files changed, 12 insertions(+), 6 deletions(-) (limited to 'Userland/Libraries/LibWasm/AbstractMachine') diff --git a/Userland/Libraries/LibWasm/AbstractMachine/Interpreter.cpp b/Userland/Libraries/LibWasm/AbstractMachine/Interpreter.cpp index ccf59c3374..bba01e621e 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/Interpreter.cpp +++ b/Userland/Libraries/LibWasm/AbstractMachine/Interpreter.cpp @@ -211,32 +211,35 @@ void Interpreter::call_address(Configuration& configuration, FunctionAddress add } while (false) template -static T read_value(ReadonlyBytes data) +T Interpreter::read_value(ReadonlyBytes data) { T value; InputMemoryStream stream { data }; auto ok = IsSigned ? LEB128::read_signed(stream, value) : LEB128::read_unsigned(stream, value); - VERIFY(ok); + if (stream.handle_any_error() || !ok) + m_do_trap = true; return value; } template<> -float read_value(ReadonlyBytes data) +float Interpreter::read_value(ReadonlyBytes data) { InputMemoryStream stream { data }; LittleEndian raw_value; stream >> raw_value; - VERIFY(!stream.has_any_error()); + if (stream.handle_any_error()) + m_do_trap = true; return bit_cast(static_cast(raw_value)); } template<> -double read_value(ReadonlyBytes data) +double Interpreter::read_value(ReadonlyBytes data) { InputMemoryStream stream { data }; LittleEndian raw_value; stream >> raw_value; - VERIFY(!stream.has_any_error()); + if (stream.handle_any_error()) + m_do_trap = true; return bit_cast(static_cast(raw_value)); } diff --git a/Userland/Libraries/LibWasm/AbstractMachine/Interpreter.h b/Userland/Libraries/LibWasm/AbstractMachine/Interpreter.h index 0e06650bf5..7f5dfcdb5c 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/Interpreter.h +++ b/Userland/Libraries/LibWasm/AbstractMachine/Interpreter.h @@ -27,6 +27,9 @@ private: template MakeSigned checked_signed_truncate(V); + template + T read_value(ReadonlyBytes data); + Vector> pop_values(Configuration& configuration, size_t count); bool trap_if_not(bool value) { -- cgit v1.2.3