Skip to content

Commit 7bccd65

Browse files
cqundefinealimpfard
authored andcommitted
LibWasm: Make sure try_table creates a new frame while validating
The spec says that while validating this opcode a new label should be pushed. Fixes a crash in instance.wast on WPT.
1 parent 07c8654 commit 7bccd65

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

Libraries/LibWasm/AbstractMachine/Validator.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2091,6 +2091,16 @@ VALIDATE_INSTRUCTION(try_table)
20912091
{
20922092
auto& args = instruction.arguments().get<Instruction::TryTableArgs>();
20932093
auto block_type = TRY(validate(args.try_.block_type));
2094+
2095+
auto& parameters = block_type.parameters();
2096+
for (size_t i = 1; i <= parameters.size(); ++i)
2097+
TRY(stack.take(parameters[parameters.size() - i]));
2098+
2099+
m_frames.empend(block_type, FrameKind::TryTable, stack.size());
2100+
m_max_frame_size = max(m_max_frame_size, m_frames.size());
2101+
for (auto& parameter : parameters)
2102+
stack.append(parameter);
2103+
20942104
for (auto& catch_ : args.catches) {
20952105
auto label = catch_.target_label();
20962106
TRY(validate(label));

Libraries/LibWasm/AbstractMachine/Validator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ class Validator {
151151
If,
152152
Else,
153153
Function,
154+
TryTable,
154155
};
155156

156157
struct Frame {

0 commit comments

Comments
 (0)