summaryrefslogtreecommitdiff
path: root/src/wasm/wasm-validator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/wasm/wasm-validator.cpp')
-rw-r--r--src/wasm/wasm-validator.cpp25
1 files changed, 17 insertions, 8 deletions
diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp
index 6bcdb0e7c..7e9c30c77 100644
--- a/src/wasm/wasm-validator.cpp
+++ b/src/wasm/wasm-validator.cpp
@@ -2818,7 +2818,7 @@ static void validateMemory(Module& module, ValidationInfo& info) {
"memory is shared, but atomics are disabled");
}
for (auto& segment : curr.segments) {
- Index size = segment.data.size();
+ auto size = segment.data.size();
if (segment.isPassive) {
info.shouldBeTrue(module.features.hasBulkMemory(),
segment.offset,
@@ -2828,11 +2828,20 @@ static void validateMemory(Module& module, ValidationInfo& info) {
segment.offset,
"passive segment should not have an offset");
} else {
- if (!info.shouldBeEqual(segment.offset->type,
- Type(Type::i32),
- segment.offset,
- "segment offset should be i32")) {
- continue;
+ if (curr.is64()) {
+ if (!info.shouldBeEqual(segment.offset->type,
+ Type(Type::i64),
+ segment.offset,
+ "segment offset should be i64")) {
+ continue;
+ }
+ } else {
+ if (!info.shouldBeEqual(segment.offset->type,
+ Type(Type::i32),
+ segment.offset,
+ "segment offset should be i32")) {
+ continue;
+ }
}
info.shouldBeTrue(checkSegmentOffset(segment.offset,
segment.data.size(),
@@ -2840,8 +2849,8 @@ static void validateMemory(Module& module, ValidationInfo& info) {
segment.offset,
"memory segment offset should be reasonable");
if (segment.offset->is<Const>()) {
- Index start = segment.offset->cast<Const>()->value.geti32();
- Index end = start + size;
+ auto start = segment.offset->cast<Const>()->value.getUnsigned();
+ auto end = start + size;
info.shouldBeTrue(end <= curr.initial * Memory::kPageSize,
segment.data.size(),
"segment size should fit in memory (end)");