summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Smith <binji@chromium.org>2020-01-10 22:06:13 -0800
committerGitHub <noreply@github.com>2020-01-10 22:06:13 -0800
commitca00fec0c8378db44d335d1731afd71c70c404cc (patch)
tree43d8e26558518317ff02f7eba7895fdcb412ce06
parent710721e99bb37563cdad97f9b950770abe6064b7 (diff)
downloadwabt-ca00fec0c8378db44d335d1731afd71c70c404cc.tar.gz
wabt-ca00fec0c8378db44d335d1731afd71c70c404cc.tar.bz2
wabt-ca00fec0c8378db44d335d1731afd71c70c404cc.zip
Error on memory.init|data.drop without DataCount (#1297)
See #1176. This was working in the spec interpreter because of the way the segment indexes are handled, but it's better to handle it earlier in the binary reader.
-rw-r--r--src/binary-reader.cc5
-rw-r--r--test/binary/bad-data-drop-no-data-count.txt23
-rw-r--r--test/binary/bad-memory-init-no-data-count.txt31
-rwxr-xr-xtest/gen-wasm.py9
-rw-r--r--test/spec/bulk-memory-operations/binary.txt6
5 files changed, 70 insertions, 4 deletions
diff --git a/src/binary-reader.cc b/src/binary-reader.cc
index 518abe63..bf6222da 100644
--- a/src/binary-reader.cc
+++ b/src/binary-reader.cc
@@ -1433,6 +1433,8 @@ Result BinaryReader::ReadFunctionBody(Offset end_offset) {
case Opcode::MemoryInit: {
Index segment;
+ ERROR_IF(data_count_ == kInvalidIndex,
+ "memory.init requires data count section");
CHECK_RESULT(ReadIndex(&segment, "elem segment index"));
uint8_t reserved;
CHECK_RESULT(ReadU8(&reserved, "reserved memory index"));
@@ -1443,6 +1445,9 @@ Result BinaryReader::ReadFunctionBody(Offset end_offset) {
}
case Opcode::DataDrop:
+ ERROR_IF(data_count_ == kInvalidIndex,
+ "data.drop requires data count section");
+ // Fallthrough.
case Opcode::ElemDrop: {
Index segment;
CHECK_RESULT(ReadIndex(&segment, "segment index"));
diff --git a/test/binary/bad-data-drop-no-data-count.txt b/test/binary/bad-data-drop-no-data-count.txt
new file mode 100644
index 00000000..db148dba
--- /dev/null
+++ b/test/binary/bad-data-drop-no-data-count.txt
@@ -0,0 +1,23 @@
+;;; TOOL: run-gen-wasm-bad
+;;; ARGS1: --enable-bulk-memory
+;;; ARGS2: --enable-bulk-memory
+magic
+version
+section(TYPE) { count[1] function params[0] results[0] }
+section(FUNCTION) { count[1] type[0] }
+section(CODE) {
+ count[1]
+ func {
+ locals[0]
+ data.drop 0
+ }
+}
+section(DATA) {
+ count[1]
+ flags[1]
+ data[str("")]
+}
+(;; STDERR ;;;
+0000019: error: data.drop requires data count section
+0000019: error: data.drop requires data count section
+;;; STDERR ;;)
diff --git a/test/binary/bad-memory-init-no-data-count.txt b/test/binary/bad-memory-init-no-data-count.txt
new file mode 100644
index 00000000..b182b91e
--- /dev/null
+++ b/test/binary/bad-memory-init-no-data-count.txt
@@ -0,0 +1,31 @@
+;;; TOOL: run-gen-wasm-bad
+;;; ARGS1: --enable-bulk-memory
+;;; ARGS2: --enable-bulk-memory
+magic
+version
+section(TYPE) { count[1] function params[0] results[0] }
+section(FUNCTION) { count[1] type[0] }
+section(MEMORY) {
+ count[1]
+ has_max[0]
+ initial[leb_u32(0)]
+}
+section(CODE) {
+ count[1]
+ func {
+ locals[0]
+ i32.const leb_i32(0)
+ i32.const leb_i32(0)
+ i32.const leb_i32(0)
+ memory.init 0 0
+ }
+}
+section(DATA) {
+ count[1]
+ flags[1]
+ data[str("")]
+}
+(;; STDERR ;;;
+0000024: error: memory.init requires data count section
+0000024: error: memory.init requires data count section
+;;; STDERR ;;)
diff --git a/test/gen-wasm.py b/test/gen-wasm.py
index cef26a8f..26d58fda 100755
--- a/test/gen-wasm.py
+++ b/test/gen-wasm.py
@@ -255,6 +255,15 @@ NAMED_VALUES = {
"i64.reinterpret/f64": 0xbd,
"f32.reinterpret/i32": 0xbe,
"f64.reinterpret/i64": 0xbf,
+
+ # bulk memory
+ "memory.init": (0xfc, 0x08),
+ "data.drop": (0xfc, 0x09),
+ "memory.copy": (0xfc, 0x0a),
+ "memory.fill": (0xfc, 0x0b),
+ "table.init": (0xfc, 0x0c),
+ "elem.drop": (0xfc, 0x0d),
+ "table.copy": (0xfc, 0x0e),
}
keywords = {
diff --git a/test/spec/bulk-memory-operations/binary.txt b/test/spec/bulk-memory-operations/binary.txt
index b660a411..3b2eb85d 100644
--- a/test/spec/bulk-memory-operations/binary.txt
+++ b/test/spec/bulk-memory-operations/binary.txt
@@ -133,11 +133,9 @@ out/test/spec/bulk-memory-operations/binary.wast:664: assert_malformed passed:
out/test/spec/bulk-memory-operations/binary.wast:674: assert_malformed passed:
000000e: error: data section without memory section
out/test/spec/bulk-memory-operations/binary.wast:684: assert_malformed passed:
- error: invalid data_segment_index: 0 (max 0)
- 0000026: error: OnMemoryInitExpr callback failed
+ 0000024: error: memory.init requires data count section
out/test/spec/bulk-memory-operations/binary.wast:706: assert_malformed passed:
- error: invalid data_segment_index: 0 (max 0)
- 000001f: error: OnDataDropExpr callback failed
+ 000001e: error: data.drop requires data count section
out/test/spec/bulk-memory-operations/binary.wast:725: assert_malformed passed:
0000024: error: expected ref.null or ref.func in passive element segment
0000025: error: expected END opcode after element expression