Skip to content

Commit c68fe0d

Browse files
authored
Binary fuzz fix: disallow popping from outside a block (#1305)
* remove unneeded code to handle a br to the return from the function. Now that we use getBlockOrSingleton there, it does that for us anyhow * fix a fuzz bug of popping from outside a block
1 parent 94cbe63 commit c68fe0d

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/wasm/wasm-binary.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2175,6 +2175,9 @@ BinaryConsts::ASTNodes WasmBinaryBuilder::readExpression(Expression*& curr) {
21752175
}
21762176

21772177
void WasmBinaryBuilder::pushBlockElements(Block* curr, size_t start, size_t end) {
2178+
assert(start <= expressionStack.size());
2179+
assert(start <= end);
2180+
assert(end <= expressionStack.size());
21782181
// the first dropped element may be consumed by code later - it was on the stack first,
21792182
// and is the only thing left on the stack. there must be just one thing on the stack
21802183
// since we are at the end of a block context. note that we may need to drop more than
@@ -2255,6 +2258,9 @@ Expression* WasmBinaryBuilder::getBlockOrSingleton(WasmType type) {
22552258
auto start = expressionStack.size();
22562259
processExpressions();
22572260
size_t end = expressionStack.size();
2261+
if (end < start) {
2262+
throw ParseException("block cannot pop from outside");
2263+
}
22582264
breakStack.pop_back();
22592265
auto* block = allocator.alloc<Block>();
22602266
pushBlockElements(block, start, end);

0 commit comments

Comments
 (0)