summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/binary-reader.cc4
-rw-r--r--test/binary/bad-section-code-leb128.txt10
2 files changed, 12 insertions, 2 deletions
diff --git a/src/binary-reader.cc b/src/binary-reader.cc
index 217253f5..c410aca9 100644
--- a/src/binary-reader.cc
+++ b/src/binary-reader.cc
@@ -2360,9 +2360,9 @@ Result BinaryReader::ReadSections() {
bool seen_section_code[static_cast<int>(BinarySection::Last) + 1] = {false};
for (; state_.offset < state_.size; ++section_index) {
- uint32_t section_code;
+ uint8_t section_code;
Offset section_size;
- CHECK_RESULT(ReadU32Leb128(&section_code, "section code"));
+ CHECK_RESULT(ReadU8(&section_code, "section code"));
CHECK_RESULT(ReadOffset(&section_size, "section size"));
ReadEndRestoreGuard guard(this);
read_end_ = state_.offset + section_size;
diff --git a/test/binary/bad-section-code-leb128.txt b/test/binary/bad-section-code-leb128.txt
new file mode 100644
index 00000000..9b876775
--- /dev/null
+++ b/test/binary/bad-section-code-leb128.txt
@@ -0,0 +1,10 @@
+;;; TOOL: run-gen-wasm-bad
+magic
+version
+section_code[0x81 0] ;; Section code is not LEB128 encoded
+section_size[1]
+type_count[0]
+(;; STDERR ;;;
+000000a: error: invalid section code: 129
+000000a: error: invalid section code: 129
+;;; STDERR ;;)