Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(453)

Unified Diff: src/wasm/wasm-module.cc

Issue 2483053005: [wasm] Check data segments for zero-sized memory. (Closed)
Patch Set: Use a different formatter string Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/cctest/wasm/test-run-wasm-module.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/wasm/wasm-module.cc
diff --git a/src/wasm/wasm-module.cc b/src/wasm/wasm-module.cc
index 4fbfa22f5f41550a5386167052f5d4ae3127db77..b16c0f97b0d7bdeb7ab4dc8fcc14814227be343e 100644
--- a/src/wasm/wasm-module.cc
+++ b/src/wasm/wasm-module.cc
@@ -1153,6 +1153,8 @@ class WasmInstanceBuilder {
RelocateMemoryReferencesInCode(code_table, old_mem_start, mem_start,
old_mem_size, mem_size);
compiled_module_->set_memory(memory_);
+ } else {
+ LoadDataSegments(nullptr, 0);
}
//--------------------------------------------------------------------------
@@ -1349,7 +1351,7 @@ class WasmInstanceBuilder {
return result;
}
- uint32_t EvalUint32InitExpr(WasmInitExpr& expr) {
+ uint32_t EvalUint32InitExpr(const WasmInitExpr& expr) {
switch (expr.kind) {
case WasmInitExpr::kI32Const:
return expr.val.i32_const;
@@ -1366,15 +1368,18 @@ class WasmInstanceBuilder {
// Load data segments into the memory.
void LoadDataSegments(Address mem_addr, size_t mem_size) {
Handle<SeqOneByteString> module_bytes = compiled_module_->module_bytes();
- for (auto segment : module_->data_segments) {
- uint32_t dest_offset = EvalUint32InitExpr(segment.dest_addr);
+ for (const WasmDataSegment& segment : module_->data_segments) {
uint32_t source_size = segment.source_size;
+ // Segments of size == 0 are just nops.
+ if (source_size == 0) continue;
+ uint32_t dest_offset = EvalUint32InitExpr(segment.dest_addr);
if (dest_offset >= mem_size || source_size >= mem_size ||
dest_offset > (mem_size - source_size)) {
- thrower_->RangeError(
- "data segment (start = %u, size = %u) does not fit into memory "
- "(size = %zu)",
- dest_offset, source_size, mem_size);
+ thrower_->TypeError("data segment (start = %" PRIu32 ", size = %" PRIu32
+ ") does not fit into memory "
+ "(size = %" PRIu64 ")",
+ dest_offset, source_size,
+ static_cast<uint64_t>(mem_size));
return;
}
byte* dest = mem_addr + dest_offset;
« no previous file with comments | « no previous file | test/cctest/wasm/test-run-wasm-module.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698