MCPcopy Create free account
hub / github.com/WebAssembly/wabt / TEST

Function TEST

src/test-binary-reader.cc:39–75  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37} // End of anonymous namespace
38
39TEST(BinaryReader, DisabledOpcodes) {
40 // Use the default features.
41 ReadBinaryOptions options;
42
43 // Loop through all opcodes.
44 for (uint32_t i = 0; i < static_cast<uint32_t>(Opcode::Invalid); ++i) {
45 Opcode opcode(static_cast<Opcode::Enum>(i));
46 if (opcode.IsEnabled(options.features)) {
47 continue;
48 }
49
50 // Use a shorter name to make the clang-formatted table below look nicer.
51 std::vector<uint8_t> b = opcode.GetBytes();
52 assert(b.size() <= 3);
53 b.resize(3);
54
55 uint8_t data[] = {
56 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, // magic + version
57 0x01, 0x04, 0x01, 0x60, 0x00, 0x00, // type section: 1 type, (func)
58 0x03, 0x02, 0x01, 0x00, // func section: 1 func, type 0
59 0x0a, 0x07, 0x01, 0x05, 0x00, // code section: 1 func, 0 locals
60 b[0], b[1], b[2], // The instruction, padded with zeroes
61 0x0b, // end
62 };
63 const size_t size = sizeof(data);
64
65 BinaryReaderError reader;
66 Result result = ReadBinary(data, size, &reader, options);
67 EXPECT_EQ(Result::Error, result);
68
69 // This relies on the binary reader checking whether the opcode is allowed
70 // before reading any further data needed by the instruction.
71 const std::string& message = reader.first_error.message;
72 EXPECT_EQ(0u, message.find("unexpected opcode"))
73 << "Got error message: " << message;
74 }
75}
76
77TEST(BinaryReader, InvalidFunctionBodySize) {
78 // A wasm module where the function body size extends past the end of the

Callers

nothing calls this directly

Calls 6

ReadBinaryFunction · 0.85
IsEnabledMethod · 0.80
GetBytesMethod · 0.80
resizeMethod · 0.80
findMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected