summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2024-03-07 09:59:58 -0800
committerGitHub <noreply@github.com>2024-03-07 09:59:58 -0800
commitf3942e02f56503cb5b4eeecc6a3bda07c54b3c5f (patch)
tree0c2e2a7e41c95e58fd58bf81dc28ab7c5325bc65
parentab9e3f75fcaae429e236bd50641e0d69e63cfdc2 (diff)
downloadbinaryen-f3942e02f56503cb5b4eeecc6a3bda07c54b3c5f.tar.gz
binaryen-f3942e02f56503cb5b4eeecc6a3bda07c54b3c5f.tar.bz2
binaryen-f3942e02f56503cb5b4eeecc6a3bda07c54b3c5f.zip
[IRBuilder] Validate tuple arities (#6384)
Throw errors if tuple arity immediates are less than 2 or if tuple index immediates are out of bounds.
-rw-r--r--src/wasm/wasm-ir-builder.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/wasm/wasm-ir-builder.cpp b/src/wasm/wasm-ir-builder.cpp
index a7c743970..4bc80d25c 100644
--- a/src/wasm/wasm-ir-builder.cpp
+++ b/src/wasm/wasm-ir-builder.cpp
@@ -1545,6 +1545,9 @@ Result<> IRBuilder::makeThrowRef() {
}
Result<> IRBuilder::makeTupleMake(uint32_t arity) {
+ if (arity < 2) {
+ return Err{"tuple arity must be at least 2"};
+ }
TupleMake curr(wasm.allocator);
curr.operands.resize(arity);
CHECK_ERR(visitTupleMake(&curr));
@@ -1553,6 +1556,12 @@ Result<> IRBuilder::makeTupleMake(uint32_t arity) {
}
Result<> IRBuilder::makeTupleExtract(uint32_t arity, uint32_t index) {
+ if (index >= arity) {
+ return Err{"tuple index out of bounds"};
+ }
+ if (arity < 2) {
+ return Err{"tuple arity must be at least 2"};
+ }
TupleExtract curr;
CHECK_ERR(visitTupleExtract(&curr, arity));
push(builder.makeTupleExtract(curr.tuple, index));
@@ -1560,6 +1569,9 @@ Result<> IRBuilder::makeTupleExtract(uint32_t arity, uint32_t index) {
}
Result<> IRBuilder::makeTupleDrop(uint32_t arity) {
+ if (arity < 2) {
+ return Err{"tuple arity must be at least 2"};
+ }
Drop curr;
CHECK_ERR(visitDrop(&curr, arity));
push(builder.makeDrop(curr.value));