Index: src/compiler/wasm-compiler.cc |
diff --git a/src/compiler/wasm-compiler.cc b/src/compiler/wasm-compiler.cc |
index b1eb3e6acdacb005304b2e374706e1a492536327..38fef2e472e7c8a287fd81d968b08ca7f06e26c0 100644 |
--- a/src/compiler/wasm-compiler.cc |
+++ b/src/compiler/wasm-compiler.cc |
@@ -2770,19 +2770,30 @@ void WasmGraphBuilder::BoundsCheckMem(MachineType memtype, Node* index, |
// Check against the effective size. |
size_t effective_size; |
- if (offset >= size || (static_cast<uint64_t>(offset) + memsize) > size) { |
+ if (size == 0) { |
effective_size = 0; |
+ } else if (offset >= size || |
+ (static_cast<uint64_t>(offset) + memsize) > size) { |
titzer
2016/09/28 18:09:51
Can you please add a comment here what is going on
gdeepti
2016/09/28 20:29:15
Done.
|
+ effective_size = size - memsize + 1; |
+ Node* cond = graph()->NewNode(jsgraph()->machine()->Uint32LessThan(), |
+ jsgraph()->IntPtrConstant(offset), |
+ jsgraph()->RelocatableInt32Constant( |
+ static_cast<uint32_t>(effective_size), |
+ RelocInfo::WASM_MEMORY_SIZE_REFERENCE)); |
+ trap_->AddTrapIfFalse(wasm::kTrapMemOutOfBounds, cond, position); |
+ DCHECK(offset >= effective_size); |
+ effective_size = offset - effective_size; |
} else { |
effective_size = size - offset - memsize + 1; |
- } |
- CHECK(effective_size <= kMaxUInt32); |
- |
- Uint32Matcher m(index); |
- if (m.HasValue()) { |
- uint32_t value = m.Value(); |
- if (value < effective_size) { |
- // The bounds check will always succeed. |
- return; |
+ CHECK(effective_size <= kMaxUInt32); |
+ |
+ Uint32Matcher m(index); |
+ if (m.HasValue()) { |
+ uint32_t value = m.Value(); |
+ if (value < effective_size) { |
+ // The bounds check will always succeed. |
+ return; |
+ } |
} |
} |