Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions src/binary-reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ class BinaryReader {
[[nodiscard]] Result ReadType(Type* out_value, const char* desc);
[[nodiscard]] Result ReadRefType(Type* out_value, const char* desc);
[[nodiscard]] Result ReadExternalKind(ExternalKind* out_value,
const char* desc);
const char* desc,
const char* type);
[[nodiscard]] Result ReadStr(std::string_view* out_str, const char* desc);
[[nodiscard]] Result ReadBytes(const void** out_data,
Address* out_data_size,
Expand Down Expand Up @@ -398,10 +399,11 @@ Result BinaryReader::ReadRefType(Type* out_value, const char* desc) {
}

Result BinaryReader::ReadExternalKind(ExternalKind* out_value,
const char* desc) {
const char* desc,
const char* type) {
uint8_t value = 0;
CHECK_RESULT(ReadU8(&value, desc));
ERROR_UNLESS(value < kExternalKindCount, "invalid export external kind: %d",
ERROR_UNLESS(value < kExternalKindCount, "invalid %s external kind: %d", type,
value);
*out_value = static_cast<ExternalKind>(value);
return Result::Ok;
Expand Down Expand Up @@ -2696,13 +2698,10 @@ Result BinaryReader::ReadImportSection(Offset section_size) {
std::string_view field_name;
CHECK_RESULT(ReadStr(&field_name, "import field name"));

uint8_t kind_u8;
CHECK_RESULT(ReadU8(&kind_u8, "import kind"));
ERROR_UNLESS(kind_u8 < kExternalKindCount, "malformed import kind: %d",
kind_u8);
ExternalKind kind = static_cast<ExternalKind>(kind_u8);

ExternalKind kind;
CHECK_RESULT(ReadExternalKind(&kind, "import kind", "import"));
CALLBACK(OnImport, i, kind, module_name, field_name);

switch (kind) {
case ExternalKind::Func: {
Index sig_index;
Expand Down Expand Up @@ -2872,7 +2871,7 @@ Result BinaryReader::ReadExportSection(Offset section_size) {
CHECK_RESULT(ReadStr(&name, "export item name"));

ExternalKind kind;
CHECK_RESULT(ReadExternalKind(&kind, "export kind"));
CHECK_RESULT(ReadExternalKind(&kind, "export kind", "export"));

Index item_index;
CHECK_RESULT(ReadIndex(&item_index, "export item index"));
Expand Down Expand Up @@ -2930,7 +2929,7 @@ Result BinaryReader::ReadElemSection(Offset section_size) {
CHECK_RESULT(ReadRefType(&elem_type, "table elem type"));
} else {
ExternalKind kind;
CHECK_RESULT(ReadExternalKind(&kind, "export kind"));
CHECK_RESULT(ReadExternalKind(&kind, "export kind", "export"));
ERROR_UNLESS(kind == ExternalKind::Func,
"segment elem type must be func (%s)",
elem_type.GetName().c_str());
Expand Down
4 changes: 2 additions & 2 deletions test/binary/bad-import-kind.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ magic
version
section(IMPORT) { count[1] str("module") str("func") dummy[5] }
(;; STDERR ;;;
0000018: error: malformed import kind: 5
0000018: error: malformed import kind: 5
0000018: error: invalid import external kind: 5
0000018: error: invalid import external kind: 5
;;; STDERR ;;)
5 changes: 5 additions & 0 deletions test/parse/branch-hints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@
)

(;; STDOUT ;;;

branch-hints.wasm: file format wasm 0x1

Section Details:

Custom:
- name: "metadata.code.branch_hint"
- func[0]:
Expand All @@ -75,7 +78,9 @@ Custom:
- 0000000: 01 .
- meta[7]:
- 0000000: 00 .

Code Disassembly:

000057 func[0]:
000058: 04 7f | local[0..3] type=i32
00005a: 41 00 | i32.const 0
Expand Down
8 changes: 4 additions & 4 deletions test/spec/binary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ out/test/spec/binary.wast:680: assert_malformed passed:
out/test/spec/binary.wast:690: assert_malformed passed:
000000e: error: invalid import tag kind: exceptions not allowed
out/test/spec/binary.wast:701: assert_malformed passed:
000000e: error: malformed import kind: 5
000000e: error: invalid import external kind: 5
out/test/spec/binary.wast:711: assert_malformed passed:
000000e: error: malformed import kind: 5
000000e: error: invalid import external kind: 5
out/test/spec/binary.wast:722: assert_malformed passed:
000000e: error: malformed import kind: 128
000000e: error: invalid import external kind: 128
out/test/spec/binary.wast:732: assert_malformed passed:
000000e: error: malformed import kind: 128
000000e: error: invalid import external kind: 128
out/test/spec/binary.wast:745: assert_malformed passed:
0000027: error: unable to read u32 leb128: string length
out/test/spec/binary.wast:764: assert_malformed passed:
Expand Down
12 changes: 6 additions & 6 deletions test/spec/exception-handling/binary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,17 @@ out/test/spec/exception-handling/binary.wast:650: assert_malformed passed:
out/test/spec/exception-handling/binary.wast:661: assert_malformed passed:
000000e: error: unfinished section (expected end: 0x11)
out/test/spec/exception-handling/binary.wast:680: assert_malformed passed:
000000e: error: malformed import kind: 5
000000e: error: invalid import external kind: 5
out/test/spec/exception-handling/binary.wast:690: assert_malformed passed:
000000e: error: malformed import kind: 5
000000e: error: invalid import external kind: 5
out/test/spec/exception-handling/binary.wast:701: assert_malformed passed:
000000e: error: malformed import kind: 5
000000e: error: invalid import external kind: 5
out/test/spec/exception-handling/binary.wast:711: assert_malformed passed:
000000e: error: malformed import kind: 5
000000e: error: invalid import external kind: 5
out/test/spec/exception-handling/binary.wast:722: assert_malformed passed:
000000e: error: malformed import kind: 128
000000e: error: invalid import external kind: 128
out/test/spec/exception-handling/binary.wast:732: assert_malformed passed:
000000e: error: malformed import kind: 128
000000e: error: invalid import external kind: 128
out/test/spec/exception-handling/binary.wast:745: assert_malformed passed:
0000027: error: unable to read u32 leb128: string length
out/test/spec/exception-handling/binary.wast:764: assert_malformed passed:
Expand Down
8 changes: 4 additions & 4 deletions test/spec/function-references/binary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ out/test/spec/function-references/binary.wast:680: assert_malformed passed:
out/test/spec/function-references/binary.wast:690: assert_malformed passed:
000000e: error: invalid import tag kind: exceptions not allowed
out/test/spec/function-references/binary.wast:701: assert_malformed passed:
000000e: error: malformed import kind: 5
000000e: error: invalid import external kind: 5
out/test/spec/function-references/binary.wast:711: assert_malformed passed:
000000e: error: malformed import kind: 5
000000e: error: invalid import external kind: 5
out/test/spec/function-references/binary.wast:722: assert_malformed passed:
000000e: error: malformed import kind: 128
000000e: error: invalid import external kind: 128
out/test/spec/function-references/binary.wast:732: assert_malformed passed:
000000e: error: malformed import kind: 128
000000e: error: invalid import external kind: 128
out/test/spec/function-references/binary.wast:745: assert_malformed passed:
0000027: error: unable to read u32 leb128: string length
out/test/spec/function-references/binary.wast:764: assert_malformed passed:
Expand Down
12 changes: 6 additions & 6 deletions test/spec/memory64/binary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,17 @@ out/test/spec/memory64/binary.wast:459: assert_malformed passed:
out/test/spec/memory64/binary.wast:470: assert_malformed passed:
000000e: error: unfinished section (expected end: 0x11)
out/test/spec/memory64/binary.wast:489: assert_malformed passed:
000000e: error: malformed import kind: 5
000000e: error: invalid import external kind: 5
out/test/spec/memory64/binary.wast:499: assert_malformed passed:
000000e: error: malformed import kind: 5
000000e: error: invalid import external kind: 5
out/test/spec/memory64/binary.wast:510: assert_malformed passed:
000000e: error: malformed import kind: 5
000000e: error: invalid import external kind: 5
out/test/spec/memory64/binary.wast:520: assert_malformed passed:
000000e: error: malformed import kind: 5
000000e: error: invalid import external kind: 5
out/test/spec/memory64/binary.wast:531: assert_malformed passed:
000000e: error: malformed import kind: 128
000000e: error: invalid import external kind: 128
out/test/spec/memory64/binary.wast:541: assert_malformed passed:
000000e: error: malformed import kind: 128
000000e: error: invalid import external kind: 128
out/test/spec/memory64/binary.wast:554: assert_malformed passed:
0000027: error: unable to read u32 leb128: string length
out/test/spec/memory64/binary.wast:573: assert_malformed passed:
Expand Down
8 changes: 4 additions & 4 deletions test/spec/multi-memory/binary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ out/test/spec/multi-memory/binary.wast:489: assert_malformed passed:
out/test/spec/multi-memory/binary.wast:499: assert_malformed passed:
000000e: error: invalid import tag kind: exceptions not allowed
out/test/spec/multi-memory/binary.wast:510: assert_malformed passed:
000000e: error: malformed import kind: 5
000000e: error: invalid import external kind: 5
out/test/spec/multi-memory/binary.wast:520: assert_malformed passed:
000000e: error: malformed import kind: 5
000000e: error: invalid import external kind: 5
out/test/spec/multi-memory/binary.wast:531: assert_malformed passed:
000000e: error: malformed import kind: 128
000000e: error: invalid import external kind: 128
out/test/spec/multi-memory/binary.wast:541: assert_malformed passed:
000000e: error: malformed import kind: 128
000000e: error: invalid import external kind: 128
out/test/spec/multi-memory/binary.wast:554: assert_malformed passed:
0000027: error: unable to read u32 leb128: string length
out/test/spec/multi-memory/binary.wast:573: assert_malformed passed:
Expand Down
Loading