diff options
author | Sam Clegg <sbc@chromium.org> | 2018-11-15 10:20:12 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-15 10:20:12 -0800 |
commit | f1666bd5eb86324867b50a9aa3d039832183f8d1 (patch) | |
tree | 5e4842d06658a913a0d560bddeebf929f4012f23 | |
parent | 622cba9c49378f89ca94e05cbbe2af0b0c62ab44 (diff) | |
download | binaryen-f1666bd5eb86324867b50a9aa3d039832183f8d1.tar.gz binaryen-f1666bd5eb86324867b50a9aa3d039832183f8d1.tar.bz2 binaryen-f1666bd5eb86324867b50a9aa3d039832183f8d1.zip |
Fix segment size validation for imported memories (#1745)
Without this wasm-opt can't operation on emscripten-produced
SIDE_MODULES's which have zero sized memory imports.
Technically is not a validation failure if you have segments that
are larger than your initial memory, regardless of whether you
import them.
For non-imported memories it can be helpful though, so leaving it
in to catch those errors.
-rw-r--r-- | src/wasm/wasm-validator.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index fbd31b920..769f17d59 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -974,9 +974,14 @@ static void validateMemory(Module& module, ValidationInfo& info) { if (curr.shared) info.shouldBeTrue(info.features & Feature::Atomics, "memory", "memory is shared, but atomics are disabled"); 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"); + info.shouldBeTrue(checkOffset(segment.offset, segment.data.size(), curr.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 (initial)"); + // If the memory is imported we don't actually know its initial size. + // Specifically wasm dll's import a zero sized memory which is perfectly + // valid. + if (!curr.imported()) { + 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; |