summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/wasm/wasm-validator.cpp7
-rw-r--r--test/segment-overlap.wast6
-rw-r--r--test/segment-overlap.wast.from-wast5
-rw-r--r--test/segment-overlap.wast.fromBinary6
-rw-r--r--test/segment-overlap.wast.fromBinary.noDebugInfo6
5 files changed, 25 insertions, 5 deletions
diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp
index 4564191c2..ef70cc9e7 100644
--- a/src/wasm/wasm-validator.cpp
+++ b/src/wasm/wasm-validator.cpp
@@ -965,18 +965,15 @@ static void validateMemory(Module& module, ValidationInfo& info) {
info.shouldBeTrue(curr.max <= Memory::kMaxSize, "memory", "max memory must be <= 4GB");
info.shouldBeTrue(!curr.shared || curr.hasMax(), "memory", "shared memory must have max size");
if (curr.shared) info.shouldBeTrue(info.features & Feature::Atomics, "memory", "memory is shared, but atomics are disabled");
- Index mustBeGreaterOrEqual = 0;
for (auto& segment : curr.segments) {
if (!info.shouldBeEqual(segment.offset->type, i32, segment.offset, "segment offset should be i32")) continue;
info.shouldBeTrue(checkOffset(segment.offset, segment.data.size(), module.memory.initial * Memory::kPageSize), segment.offset, "segment offset should be reasonable");
Index size = segment.data.size();
- info.shouldBeTrue(size <= curr.initial * Memory::kPageSize, segment.data.size(), "segment size should fit in memory");
+ info.shouldBeTrue(size <= curr.initial * Memory::kPageSize, segment.data.size(), "segment size should fit in memory (initial)");
if (segment.offset->is<Const>()) {
Index start = segment.offset->cast<Const>()->value.geti32();
Index end = start + size;
- info.shouldBeTrue(end <= curr.initial * Memory::kPageSize, segment.data.size(), "segment size should fit in memory");
- info.shouldBeTrue(start >= mustBeGreaterOrEqual, segment.data.size(), "segment size should fit in memory");
- mustBeGreaterOrEqual = end;
+ info.shouldBeTrue(end <= curr.initial * Memory::kPageSize, segment.data.size(), "segment size should fit in memory (end)");
}
}
}
diff --git a/test/segment-overlap.wast b/test/segment-overlap.wast
new file mode 100644
index 000000000..dce86fd88
--- /dev/null
+++ b/test/segment-overlap.wast
@@ -0,0 +1,6 @@
+(module
+ (memory $0 10)
+ (data (i32.const 100) "\ff\ff\ff\ff\ff\ff\ff\ff") ;; overlaps with the next
+ (data (i32.const 104) "\00\00\00\00")
+)
+
diff --git a/test/segment-overlap.wast.from-wast b/test/segment-overlap.wast.from-wast
new file mode 100644
index 000000000..fbc15a9e4
--- /dev/null
+++ b/test/segment-overlap.wast.from-wast
@@ -0,0 +1,5 @@
+(module
+ (memory $0 10)
+ (data (i32.const 100) "\ff\ff\ff\ff\ff\ff\ff\ff")
+ (data (i32.const 104) "\00\00\00\00")
+)
diff --git a/test/segment-overlap.wast.fromBinary b/test/segment-overlap.wast.fromBinary
new file mode 100644
index 000000000..33c8fffca
--- /dev/null
+++ b/test/segment-overlap.wast.fromBinary
@@ -0,0 +1,6 @@
+(module
+ (memory $0 10)
+ (data (i32.const 100) "\ff\ff\ff\ff\ff\ff\ff\ff")
+ (data (i32.const 104) "\00\00\00\00")
+)
+
diff --git a/test/segment-overlap.wast.fromBinary.noDebugInfo b/test/segment-overlap.wast.fromBinary.noDebugInfo
new file mode 100644
index 000000000..33c8fffca
--- /dev/null
+++ b/test/segment-overlap.wast.fromBinary.noDebugInfo
@@ -0,0 +1,6 @@
+(module
+ (memory $0 10)
+ (data (i32.const 100) "\ff\ff\ff\ff\ff\ff\ff\ff")
+ (data (i32.const 104) "\00\00\00\00")
+)
+