summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/binary-reader.cc1
-rw-r--r--test/binary/bad-data-without-memory.txt16
2 files changed, 17 insertions, 0 deletions
diff --git a/src/binary-reader.cc b/src/binary-reader.cc
index b5a5b2fd..45d70f1a 100644
--- a/src/binary-reader.cc
+++ b/src/binary-reader.cc
@@ -2623,6 +2623,7 @@ Result BinaryReader::ReadDataSection(Offset section_size) {
}
CALLBACK(BeginDataSegment, i, memory_index, flags);
if (!(flags & SegPassive)) {
+ ERROR_UNLESS(memories.size() > 0, "no memory to copy data to");
CALLBACK(BeginDataSegmentInitExpr, i);
CHECK_RESULT(ReadInitExpr(i, memories[0].IndexType()));
CALLBACK(EndDataSegmentInitExpr, i);
diff --git a/test/binary/bad-data-without-memory.txt b/test/binary/bad-data-without-memory.txt
new file mode 100644
index 00000000..6c7341a5
--- /dev/null
+++ b/test/binary/bad-data-without-memory.txt
@@ -0,0 +1,16 @@
+;;; TOOL: run-gen-wasm-bad
+magic
+version
+section(DATA) {
+ count[1]
+ memory_index[0]
+ offset[i32.const 0 end]
+ data[str("")]
+}
+section(DATACOUNT) { count[1] }
+(;; STDERR ;;;
+000000c: error: no memory to copy data to
+000000c: error: no memory to copy data to
+;;; STDERR ;;)
+
+