Skip to content

Commit 47a27b1

Browse files
authored
accept overlapping segments (#1289)
1 parent 4231ff2 commit 47a27b1

5 files changed

Lines changed: 25 additions & 5 deletions

src/wasm/wasm-validator.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -965,18 +965,15 @@ static void validateMemory(Module& module, ValidationInfo& info) {
965965
info.shouldBeTrue(curr.max <= Memory::kMaxSize, "memory", "max memory must be <= 4GB");
966966
info.shouldBeTrue(!curr.shared || curr.hasMax(), "memory", "shared memory must have max size");
967967
if (curr.shared) info.shouldBeTrue(info.features & Feature::Atomics, "memory", "memory is shared, but atomics are disabled");
968-
Index mustBeGreaterOrEqual = 0;
969968
for (auto& segment : curr.segments) {
970969
if (!info.shouldBeEqual(segment.offset->type, i32, segment.offset, "segment offset should be i32")) continue;
971970
info.shouldBeTrue(checkOffset(segment.offset, segment.data.size(), module.memory.initial * Memory::kPageSize), segment.offset, "segment offset should be reasonable");
972971
Index size = segment.data.size();
973-
info.shouldBeTrue(size <= curr.initial * Memory::kPageSize, segment.data.size(), "segment size should fit in memory");
972+
info.shouldBeTrue(size <= curr.initial * Memory::kPageSize, segment.data.size(), "segment size should fit in memory (initial)");
974973
if (segment.offset->is<Const>()) {
975974
Index start = segment.offset->cast<Const>()->value.geti32();
976975
Index end = start + size;
977-
info.shouldBeTrue(end <= curr.initial * Memory::kPageSize, segment.data.size(), "segment size should fit in memory");
978-
info.shouldBeTrue(start >= mustBeGreaterOrEqual, segment.data.size(), "segment size should fit in memory");
979-
mustBeGreaterOrEqual = end;
976+
info.shouldBeTrue(end <= curr.initial * Memory::kPageSize, segment.data.size(), "segment size should fit in memory (end)");
980977
}
981978
}
982979
}

test/segment-overlap.wast

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
(module
2+
(memory $0 10)
3+
(data (i32.const 100) "\ff\ff\ff\ff\ff\ff\ff\ff") ;; overlaps with the next
4+
(data (i32.const 104) "\00\00\00\00")
5+
)
6+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
(module
2+
(memory $0 10)
3+
(data (i32.const 100) "\ff\ff\ff\ff\ff\ff\ff\ff")
4+
(data (i32.const 104) "\00\00\00\00")
5+
)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
(module
2+
(memory $0 10)
3+
(data (i32.const 100) "\ff\ff\ff\ff\ff\ff\ff\ff")
4+
(data (i32.const 104) "\00\00\00\00")
5+
)
6+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
(module
2+
(memory $0 10)
3+
(data (i32.const 100) "\ff\ff\ff\ff\ff\ff\ff\ff")
4+
(data (i32.const 104) "\00\00\00\00")
5+
)
6+

0 commit comments

Comments
 (0)