summaryrefslogtreecommitdiff
path: root/src/ir/table-utils.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/ir/table-utils.h')
-rw-r--r--src/ir/table-utils.h9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/ir/table-utils.h b/src/ir/table-utils.h
index a94691e9f..5299ba3e1 100644
--- a/src/ir/table-utils.h
+++ b/src/ir/table-utils.h
@@ -20,6 +20,7 @@
#include "ir/element-utils.h"
#include "ir/literal-utils.h"
#include "ir/module-utils.h"
+#include "support/stdckdint.h"
#include "wasm-traversal.h"
#include "wasm.h"
@@ -40,7 +41,13 @@ struct FlatTable {
return;
}
Index start = offset->cast<Const>()->value.geti32();
- Index end = start + segment->data.size();
+ Index size = segment->data.size();
+ Index end;
+ if (std::ckd_add(&end, start, size) || end > table.initial) {
+ // Overflow.
+ valid = false;
+ return;
+ }
if (end > names.size()) {
names.resize(end);
}