Skip to content

Commit 96c0e2c

Browse files
committed
[IRBuilder] Validate tuple arities
Throw errors if tuple arity immediates are less than 2 or if tuple index immediates are out of bounds.
1 parent ca22d1b commit 96c0e2c

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/wasm/wasm-ir-builder.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,6 +1545,9 @@ Result<> IRBuilder::makeThrowRef() {
15451545
}
15461546

15471547
Result<> IRBuilder::makeTupleMake(uint32_t arity) {
1548+
if (arity < 2) {
1549+
return Err{"tuple arity must be at least 2"};
1550+
}
15481551
TupleMake curr(wasm.allocator);
15491552
curr.operands.resize(arity);
15501553
CHECK_ERR(visitTupleMake(&curr));
@@ -1553,13 +1556,22 @@ Result<> IRBuilder::makeTupleMake(uint32_t arity) {
15531556
}
15541557

15551558
Result<> IRBuilder::makeTupleExtract(uint32_t arity, uint32_t index) {
1559+
if (index >= arity) {
1560+
return Err{"tuple index out of bounds"};
1561+
}
1562+
if (arity < 2) {
1563+
return Err{"tuple arity must be at least 2"};
1564+
}
15561565
TupleExtract curr;
15571566
CHECK_ERR(visitTupleExtract(&curr, arity));
15581567
push(builder.makeTupleExtract(curr.tuple, index));
15591568
return Ok{};
15601569
}
15611570

15621571
Result<> IRBuilder::makeTupleDrop(uint32_t arity) {
1572+
if (arity < 2) {
1573+
return Err{"tuple arity must be at least 2"};
1574+
}
15631575
Drop curr;
15641576
CHECK_ERR(visitDrop(&curr, arity));
15651577
push(builder.makeDrop(curr.value));

0 commit comments

Comments
 (0)