LibWasm: Turn memory read failures into traps
This commit is contained in:
parent
c31a4e9013
commit
7966168fea
Notes:
sideshowbarker
2024-07-18 17:22:54 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/7966168fea9 Pull-request: https://github.com/SerenityOS/serenity/pull/7395 Reviewed-by: https://github.com/linusg
2 changed files with 12 additions and 6 deletions
Userland/Libraries/LibWasm/AbstractMachine
|
@ -211,32 +211,35 @@ void Interpreter::call_address(Configuration& configuration, FunctionAddress add
|
|||
} while (false)
|
||||
|
||||
template<typename T>
|
||||
static T read_value(ReadonlyBytes data)
|
||||
T Interpreter::read_value(ReadonlyBytes data)
|
||||
{
|
||||
T value;
|
||||
InputMemoryStream stream { data };
|
||||
auto ok = IsSigned<T> ? 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<float>(ReadonlyBytes data)
|
||||
float Interpreter::read_value<float>(ReadonlyBytes data)
|
||||
{
|
||||
InputMemoryStream stream { data };
|
||||
LittleEndian<u32> raw_value;
|
||||
stream >> raw_value;
|
||||
VERIFY(!stream.has_any_error());
|
||||
if (stream.handle_any_error())
|
||||
m_do_trap = true;
|
||||
return bit_cast<float>(static_cast<u32>(raw_value));
|
||||
}
|
||||
|
||||
template<>
|
||||
double read_value<double>(ReadonlyBytes data)
|
||||
double Interpreter::read_value<double>(ReadonlyBytes data)
|
||||
{
|
||||
InputMemoryStream stream { data };
|
||||
LittleEndian<u64> raw_value;
|
||||
stream >> raw_value;
|
||||
VERIFY(!stream.has_any_error());
|
||||
if (stream.handle_any_error())
|
||||
m_do_trap = true;
|
||||
return bit_cast<double>(static_cast<u64>(raw_value));
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,9 @@ private:
|
|||
template<typename V, typename T>
|
||||
MakeSigned<T> checked_signed_truncate(V);
|
||||
|
||||
template<typename T>
|
||||
T read_value(ReadonlyBytes data);
|
||||
|
||||
Vector<NonnullOwnPtr<Value>> pop_values(Configuration& configuration, size_t count);
|
||||
bool trap_if_not(bool value)
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue