2017-05-11 08:51:54 +00:00
|
|
|
// Copyright 2017 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "test/unittests/test-utils.h"
|
|
|
|
|
|
|
|
#include "src/objects-inl.h"
|
|
|
|
|
|
|
|
#include "src/wasm/module-decoder.h"
|
|
|
|
#include "src/wasm/streaming-decoder.h"
|
|
|
|
|
|
|
|
#include "src/objects/descriptor-array.h"
|
|
|
|
#include "src/objects/dictionary.h"
|
|
|
|
#include "test/common/wasm/wasm-macro-gen.h"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace wasm {
|
|
|
|
|
2017-09-14 17:34:15 +00:00
|
|
|
class MockStreamingProcessor : public StreamingProcessor {
|
|
|
|
public:
|
|
|
|
bool ProcessModuleHeader(Vector<const uint8_t> bytes,
|
|
|
|
uint32_t offset) override {
|
|
|
|
// TODO(ahaas): Share code with the module-decoder.
|
|
|
|
Decoder decoder(bytes.begin(), bytes.end());
|
|
|
|
uint32_t magic_word = decoder.consume_u32("wasm magic");
|
|
|
|
if (decoder.failed() || magic_word != kWasmMagic) {
|
|
|
|
ok_ = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
uint32_t magic_version = decoder.consume_u32("wasm version");
|
|
|
|
if (decoder.failed() || magic_version != kWasmVersion) {
|
|
|
|
ok_ = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// Process all sections but the code section.
|
|
|
|
bool ProcessSection(SectionCode section_code, Vector<const uint8_t> bytes,
|
|
|
|
uint32_t offset) override {
|
|
|
|
++num_sections_;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-11-07 10:27:10 +00:00
|
|
|
bool ProcessCodeSectionHeader(size_t num_functions, uint32_t offset,
|
|
|
|
std::shared_ptr<WireBytesStorage>) override {
|
2017-09-14 17:34:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Process a function body.
|
|
|
|
bool ProcessFunctionBody(Vector<const uint8_t> bytes,
|
|
|
|
uint32_t offset) override {
|
|
|
|
++num_functions_;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnFinishedChunk() override {}
|
|
|
|
|
|
|
|
// Finish the processing of the stream.
|
2018-06-28 14:29:04 +00:00
|
|
|
void OnFinishedStream(OwnedVector<uint8_t> bytes) override {
|
2017-09-14 17:34:15 +00:00
|
|
|
received_bytes_ = std::move(bytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Report an error detected in the StreamingDecoder.
|
|
|
|
void OnError(DecodeResult result) override { ok_ = false; }
|
|
|
|
|
|
|
|
void OnAbort() override {}
|
|
|
|
|
2018-10-12 15:16:19 +00:00
|
|
|
bool Deserialize(Vector<const uint8_t> module_bytes,
|
|
|
|
Vector<const uint8_t> wire_bytes) override {
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2017-09-14 17:34:15 +00:00
|
|
|
size_t num_sections() const { return num_sections_; }
|
|
|
|
size_t num_functions() const { return num_functions_; }
|
|
|
|
bool ok() const { return ok_; }
|
2018-06-28 14:29:04 +00:00
|
|
|
Vector<const uint8_t> received_bytes() const {
|
|
|
|
return received_bytes_.as_vector();
|
2017-09-14 17:34:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
size_t num_sections_ = 0;
|
|
|
|
size_t num_functions_ = 0;
|
|
|
|
bool ok_ = true;
|
2018-06-28 14:29:04 +00:00
|
|
|
OwnedVector<uint8_t> received_bytes_;
|
2017-09-14 17:34:15 +00:00
|
|
|
};
|
|
|
|
|
2017-05-11 08:51:54 +00:00
|
|
|
class WasmStreamingDecoderTest : public ::testing::Test {
|
|
|
|
public:
|
2017-09-14 17:34:15 +00:00
|
|
|
void ExpectVerifies(Vector<const uint8_t> data, size_t expected_sections,
|
|
|
|
size_t expected_functions) {
|
2017-05-11 08:51:54 +00:00
|
|
|
for (int split = 0; split <= data.length(); ++split) {
|
2017-09-14 17:34:15 +00:00
|
|
|
// Use a unique_ptr so that the StreamingDecoder can own the processor.
|
|
|
|
std::unique_ptr<MockStreamingProcessor> p(new MockStreamingProcessor());
|
|
|
|
MockStreamingProcessor* processor = p.get();
|
|
|
|
StreamingDecoder stream(std::move(p));
|
2017-05-11 08:51:54 +00:00
|
|
|
stream.OnBytesReceived(data.SubVector(0, split));
|
|
|
|
stream.OnBytesReceived(data.SubVector(split, data.length()));
|
2017-09-14 17:34:15 +00:00
|
|
|
stream.Finish();
|
|
|
|
EXPECT_TRUE(processor->ok());
|
|
|
|
EXPECT_EQ(expected_sections, processor->num_sections());
|
|
|
|
EXPECT_EQ(expected_functions, processor->num_functions());
|
|
|
|
EXPECT_EQ(data, processor->received_bytes());
|
2017-05-11 08:51:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExpectFailure(Vector<const uint8_t> data) {
|
|
|
|
for (int split = 0; split <= data.length(); ++split) {
|
2017-09-14 17:34:15 +00:00
|
|
|
std::unique_ptr<MockStreamingProcessor> p(new MockStreamingProcessor());
|
|
|
|
MockStreamingProcessor* processor = p.get();
|
|
|
|
StreamingDecoder stream(std::move(p));
|
2017-05-11 08:51:54 +00:00
|
|
|
stream.OnBytesReceived(data.SubVector(0, split));
|
|
|
|
stream.OnBytesReceived(data.SubVector(split, data.length()));
|
2017-09-14 17:34:15 +00:00
|
|
|
stream.Finish();
|
|
|
|
EXPECT_FALSE(processor->ok());
|
2017-05-11 08:51:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(WasmStreamingDecoderTest, EmptyStream) {
|
2017-09-14 17:34:15 +00:00
|
|
|
std::unique_ptr<MockStreamingProcessor> p(new MockStreamingProcessor());
|
|
|
|
MockStreamingProcessor* processor = p.get();
|
|
|
|
StreamingDecoder stream(std::move(p));
|
|
|
|
stream.Finish();
|
|
|
|
EXPECT_FALSE(processor->ok());
|
2017-05-11 08:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmStreamingDecoderTest, IncompleteModuleHeader) {
|
|
|
|
const uint8_t data[] = {U32_LE(kWasmMagic), U32_LE(kWasmVersion)};
|
|
|
|
{
|
2017-09-14 17:34:15 +00:00
|
|
|
std::unique_ptr<MockStreamingProcessor> p(new MockStreamingProcessor());
|
|
|
|
MockStreamingProcessor* processor = p.get();
|
|
|
|
StreamingDecoder stream(std::move(p));
|
2017-05-11 08:51:54 +00:00
|
|
|
stream.OnBytesReceived(Vector<const uint8_t>(data, 1));
|
2017-09-14 17:34:15 +00:00
|
|
|
stream.Finish();
|
|
|
|
EXPECT_FALSE(processor->ok());
|
2017-05-11 08:51:54 +00:00
|
|
|
}
|
|
|
|
for (int length = 1; length < static_cast<int>(arraysize(data)); ++length) {
|
|
|
|
ExpectFailure(Vector<const uint8_t>(data, length));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmStreamingDecoderTest, MagicAndVersion) {
|
|
|
|
const uint8_t data[] = {U32_LE(kWasmMagic), U32_LE(kWasmVersion)};
|
2017-12-01 10:51:10 +00:00
|
|
|
ExpectVerifies(ArrayVector(data), 0, 0);
|
2017-05-11 08:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmStreamingDecoderTest, BadMagic) {
|
|
|
|
for (uint32_t x = 1; x; x <<= 1) {
|
|
|
|
const uint8_t data[] = {U32_LE(kWasmMagic ^ x), U32_LE(kWasmVersion)};
|
2017-12-01 10:51:10 +00:00
|
|
|
ExpectFailure(ArrayVector(data));
|
2017-05-11 08:51:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmStreamingDecoderTest, BadVersion) {
|
|
|
|
for (uint32_t x = 1; x; x <<= 1) {
|
|
|
|
const uint8_t data[] = {U32_LE(kWasmMagic), U32_LE(kWasmVersion ^ x)};
|
2017-12-01 10:51:10 +00:00
|
|
|
ExpectFailure(ArrayVector(data));
|
2017-05-11 08:51:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmStreamingDecoderTest, OneSection) {
|
|
|
|
const uint8_t data[] = {
|
|
|
|
U32_LE(kWasmMagic), // --
|
|
|
|
U32_LE(kWasmVersion), // --
|
|
|
|
0x1, // Section ID
|
|
|
|
0x6, // Section Length
|
|
|
|
0x0, // Payload
|
|
|
|
0x0, // 2
|
|
|
|
0x0, // 3
|
|
|
|
0x0, // 4
|
|
|
|
0x0, // 5
|
|
|
|
0x0 // 6
|
|
|
|
};
|
2017-12-01 10:51:10 +00:00
|
|
|
ExpectVerifies(ArrayVector(data), 1, 0);
|
2017-05-11 08:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmStreamingDecoderTest, OneSection_b) {
|
|
|
|
const uint8_t data[] = {
|
|
|
|
U32_LE(kWasmMagic), // --
|
|
|
|
U32_LE(kWasmVersion), // --
|
|
|
|
0x1, // Section ID
|
|
|
|
0x86, // Section Length = 6 (LEB)
|
|
|
|
0x0, // --
|
|
|
|
0x0, // Payload
|
|
|
|
0x0, // 2
|
|
|
|
0x0, // 3
|
|
|
|
0x0, // 4
|
|
|
|
0x0, // 5
|
|
|
|
0x0 // 6
|
|
|
|
};
|
2017-12-01 10:51:10 +00:00
|
|
|
ExpectVerifies(ArrayVector(data), 1, 0);
|
2017-05-11 08:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmStreamingDecoderTest, OneShortSection) {
|
|
|
|
// Short section means that section length + payload is less than 5 bytes,
|
|
|
|
// which is the maximum size of the length field.
|
|
|
|
const uint8_t data[] = {
|
|
|
|
U32_LE(kWasmMagic), // --
|
|
|
|
U32_LE(kWasmVersion), // --
|
|
|
|
0x1, // Section ID
|
|
|
|
0x2, // Section Length
|
|
|
|
0x0, // Payload
|
|
|
|
0x0 // 2
|
|
|
|
};
|
2017-12-01 10:51:10 +00:00
|
|
|
ExpectVerifies(ArrayVector(data), 1, 0);
|
2017-05-11 08:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmStreamingDecoderTest, OneShortSection_b) {
|
|
|
|
const uint8_t data[] = {
|
|
|
|
U32_LE(kWasmMagic), // --
|
|
|
|
U32_LE(kWasmVersion), // --
|
|
|
|
0x1, // Section ID
|
|
|
|
0x82, // Section Length = 2 (LEB)
|
|
|
|
0x80, // --
|
|
|
|
0x0, // --
|
|
|
|
0x0, // Payload
|
|
|
|
0x0 // 2
|
|
|
|
};
|
2017-12-01 10:51:10 +00:00
|
|
|
ExpectVerifies(ArrayVector(data), 1, 0);
|
2017-05-11 08:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmStreamingDecoderTest, OneEmptySection) {
|
|
|
|
const uint8_t data[] = {
|
|
|
|
U32_LE(kWasmMagic), // --
|
|
|
|
U32_LE(kWasmVersion), // --
|
|
|
|
0x1, // Section ID
|
|
|
|
0x0 // Section Length
|
|
|
|
};
|
2017-12-01 10:51:10 +00:00
|
|
|
ExpectVerifies(ArrayVector(data), 1, 0);
|
2017-05-11 08:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmStreamingDecoderTest, OneSectionNotEnoughPayload1) {
|
|
|
|
const uint8_t data[] = {
|
|
|
|
U32_LE(kWasmMagic), // --
|
|
|
|
U32_LE(kWasmVersion), // --
|
|
|
|
0x1, // Section ID
|
|
|
|
0x6, // Section Length
|
|
|
|
0x0, // Payload
|
|
|
|
0x0, // 2
|
|
|
|
0x0, // 3
|
|
|
|
0x0, // 4
|
|
|
|
0x0 // 5
|
|
|
|
};
|
2017-12-01 10:51:10 +00:00
|
|
|
ExpectFailure(ArrayVector(data));
|
2017-05-11 08:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmStreamingDecoderTest, OneSectionNotEnoughPayload2) {
|
|
|
|
const uint8_t data[] = {
|
|
|
|
U32_LE(kWasmMagic), // --
|
|
|
|
U32_LE(kWasmVersion), // --
|
|
|
|
0x1, // Section ID
|
|
|
|
0x6, // Section Length
|
|
|
|
0x0 // Payload
|
|
|
|
};
|
2017-12-01 10:51:10 +00:00
|
|
|
ExpectFailure(ArrayVector(data));
|
2017-05-11 08:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmStreamingDecoderTest, OneSectionInvalidLength) {
|
|
|
|
const uint8_t data[] = {
|
|
|
|
U32_LE(kWasmMagic), // --
|
|
|
|
U32_LE(kWasmVersion), // --
|
|
|
|
0x1, // Section ID
|
|
|
|
0x80, // Section Length (0 in LEB)
|
|
|
|
0x80, // --
|
|
|
|
0x80, // --
|
|
|
|
0x80, // --
|
|
|
|
0x80, // --
|
|
|
|
};
|
2017-12-01 10:51:10 +00:00
|
|
|
ExpectFailure(ArrayVector(data));
|
2017-05-11 08:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmStreamingDecoderTest, TwoLongSections) {
|
|
|
|
const uint8_t data[] = {
|
|
|
|
U32_LE(kWasmMagic), // --
|
|
|
|
U32_LE(kWasmVersion), // --
|
|
|
|
0x1, // Section ID
|
|
|
|
0x6, // Section Length
|
|
|
|
0x0, // Payload
|
|
|
|
0x0, // 2
|
|
|
|
0x0, // 3
|
|
|
|
0x0, // 4
|
|
|
|
0x0, // 5
|
|
|
|
0x0, // 6
|
|
|
|
0x2, // Section ID
|
|
|
|
0x7, // Section Length
|
|
|
|
0x0, // Payload
|
|
|
|
0x0, // 2
|
|
|
|
0x0, // 3
|
|
|
|
0x0, // 4
|
|
|
|
0x0, // 5
|
|
|
|
0x0, // 6
|
|
|
|
0x0 // 7
|
|
|
|
};
|
2017-12-01 10:51:10 +00:00
|
|
|
ExpectVerifies(ArrayVector(data), 2, 0);
|
2017-05-11 08:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmStreamingDecoderTest, TwoShortSections) {
|
|
|
|
const uint8_t data[] = {
|
|
|
|
U32_LE(kWasmMagic), // --
|
|
|
|
U32_LE(kWasmVersion), // --
|
|
|
|
0x1, // Section ID
|
|
|
|
0x1, // Section Length
|
|
|
|
0x0, // Payload
|
|
|
|
0x2, // Section ID
|
|
|
|
0x2, // Section Length
|
|
|
|
0x0, // Payload
|
|
|
|
0x0, // 2
|
|
|
|
};
|
2017-12-01 10:51:10 +00:00
|
|
|
ExpectVerifies(ArrayVector(data), 2, 0);
|
2017-05-11 08:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmStreamingDecoderTest, TwoSectionsShortLong) {
|
|
|
|
const uint8_t data[] = {
|
|
|
|
U32_LE(kWasmMagic), // --
|
|
|
|
U32_LE(kWasmVersion), // --
|
|
|
|
0x1, // Section ID
|
|
|
|
0x1, // Section Length
|
|
|
|
0x0, // Payload
|
|
|
|
0x2, // Section ID
|
|
|
|
0x7, // Section Length
|
|
|
|
0x0, // Payload
|
|
|
|
0x0, // 2
|
|
|
|
0x0, // 3
|
|
|
|
0x0, // 4
|
|
|
|
0x0, // 5
|
|
|
|
0x0, // 6
|
|
|
|
0x0 // 7
|
|
|
|
};
|
2017-12-01 10:51:10 +00:00
|
|
|
ExpectVerifies(ArrayVector(data), 2, 0);
|
2017-05-11 08:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmStreamingDecoderTest, TwoEmptySections) {
|
|
|
|
const uint8_t data[] = {
|
|
|
|
U32_LE(kWasmMagic), // --
|
|
|
|
U32_LE(kWasmVersion), // --
|
|
|
|
0x1, // Section ID
|
|
|
|
0x0, // Section Length
|
|
|
|
0x2, // Section ID
|
|
|
|
0x0 // Section Length
|
|
|
|
};
|
2017-12-01 10:51:10 +00:00
|
|
|
ExpectVerifies(ArrayVector(data), 2, 0);
|
2017-05-11 08:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmStreamingDecoderTest, OneFunction) {
|
|
|
|
const uint8_t data[] = {
|
|
|
|
U32_LE(kWasmMagic), // --
|
|
|
|
U32_LE(kWasmVersion), // --
|
|
|
|
kCodeSectionCode, // Section ID
|
|
|
|
0x8, // Section Length
|
|
|
|
0x1, // Number of Functions
|
|
|
|
0x6, // Function Length
|
|
|
|
0x0, // Function
|
|
|
|
0x0, // 2
|
|
|
|
0x0, // 3
|
|
|
|
0x0, // 4
|
|
|
|
0x0, // 5
|
|
|
|
0x0, // 6
|
|
|
|
};
|
2017-12-01 10:51:10 +00:00
|
|
|
ExpectVerifies(ArrayVector(data), 0, 1);
|
2017-05-11 08:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmStreamingDecoderTest, OneShortFunction) {
|
|
|
|
const uint8_t data[] = {
|
|
|
|
U32_LE(kWasmMagic), // --
|
|
|
|
U32_LE(kWasmVersion), // --
|
|
|
|
kCodeSectionCode, // Section ID
|
|
|
|
0x3, // Section Length
|
|
|
|
0x1, // Number of Functions
|
|
|
|
0x1, // Function Length
|
|
|
|
0x0, // Function
|
|
|
|
};
|
2017-12-01 10:51:10 +00:00
|
|
|
ExpectVerifies(ArrayVector(data), 0, 1);
|
2017-05-11 08:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmStreamingDecoderTest, EmptyFunction) {
|
|
|
|
const uint8_t data[] = {
|
|
|
|
U32_LE(kWasmMagic), // --
|
|
|
|
U32_LE(kWasmVersion), // --
|
|
|
|
kCodeSectionCode, // Section ID
|
|
|
|
0x2, // Section Length
|
|
|
|
0x1, // Number of Functions
|
|
|
|
0x0, // Function Length
|
|
|
|
};
|
2017-12-01 10:51:10 +00:00
|
|
|
ExpectFailure(ArrayVector(data));
|
2017-05-11 08:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmStreamingDecoderTest, TwoFunctions) {
|
|
|
|
const uint8_t data[] = {
|
|
|
|
U32_LE(kWasmMagic), // --
|
|
|
|
U32_LE(kWasmVersion), // --
|
|
|
|
kCodeSectionCode, // Section ID
|
|
|
|
0x10, // Section Length
|
|
|
|
0x2, // Number of Functions
|
|
|
|
0x6, // Function Length
|
|
|
|
0x0, // Function
|
|
|
|
0x0, // 2
|
|
|
|
0x0, // 3
|
|
|
|
0x0, // 4
|
|
|
|
0x0, // 5
|
|
|
|
0x0, // 6
|
|
|
|
0x7, // Function Length
|
|
|
|
0x0, // Function
|
|
|
|
0x0, // 2
|
|
|
|
0x0, // 3
|
|
|
|
0x0, // 4
|
|
|
|
0x0, // 5
|
|
|
|
0x0, // 6
|
|
|
|
0x0, // 7
|
|
|
|
};
|
2017-12-01 10:51:10 +00:00
|
|
|
ExpectVerifies(ArrayVector(data), 0, 2);
|
2017-05-11 08:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmStreamingDecoderTest, TwoFunctions_b) {
|
|
|
|
const uint8_t data[] = {
|
|
|
|
U32_LE(kWasmMagic), // --
|
|
|
|
U32_LE(kWasmVersion), // --
|
|
|
|
kCodeSectionCode, // Section ID
|
2017-12-02 00:30:37 +00:00
|
|
|
0xB, // Section Length
|
2017-05-11 08:51:54 +00:00
|
|
|
0x2, // Number of Functions
|
|
|
|
0x1, // Function Length
|
|
|
|
0x0, // Function
|
|
|
|
0x7, // Function Length
|
|
|
|
0x0, // Function
|
|
|
|
0x0, // 2
|
|
|
|
0x0, // 3
|
|
|
|
0x0, // 4
|
|
|
|
0x0, // 5
|
|
|
|
0x0, // 6
|
|
|
|
0x0, // 7
|
|
|
|
};
|
2017-12-01 10:51:10 +00:00
|
|
|
ExpectVerifies(ArrayVector(data), 0, 2);
|
2017-09-14 17:34:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmStreamingDecoderTest, CodeSectionLengthZero) {
|
|
|
|
const uint8_t data[] = {
|
|
|
|
U32_LE(kWasmMagic), // --
|
|
|
|
U32_LE(kWasmVersion), // --
|
|
|
|
kCodeSectionCode, // Section ID
|
|
|
|
0x0, // Section Length
|
|
|
|
};
|
2017-12-01 10:51:10 +00:00
|
|
|
ExpectFailure(ArrayVector(data));
|
2017-05-11 08:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmStreamingDecoderTest, CodeSectionLengthTooHigh) {
|
|
|
|
const uint8_t data[] = {
|
|
|
|
U32_LE(kWasmMagic), // --
|
|
|
|
U32_LE(kWasmVersion), // --
|
|
|
|
kCodeSectionCode, // Section ID
|
2017-12-02 00:30:37 +00:00
|
|
|
0xD, // Section Length
|
2017-05-11 08:51:54 +00:00
|
|
|
0x2, // Number of Functions
|
|
|
|
0x7, // Function Length
|
|
|
|
0x0, // Function
|
|
|
|
0x0, // 2
|
|
|
|
0x0, // 3
|
|
|
|
0x0, // 4
|
|
|
|
0x0, // 5
|
|
|
|
0x0, // 6
|
|
|
|
0x0, // 7
|
|
|
|
0x1, // Function Length
|
|
|
|
0x0, // Function
|
|
|
|
};
|
2017-12-01 10:51:10 +00:00
|
|
|
ExpectFailure(ArrayVector(data));
|
2017-05-11 08:51:54 +00:00
|
|
|
}
|
|
|
|
|
2017-11-15 12:14:26 +00:00
|
|
|
TEST_F(WasmStreamingDecoderTest, CodeSectionLengthTooHighZeroFunctions) {
|
|
|
|
const uint8_t data[] = {
|
|
|
|
U32_LE(kWasmMagic), // --
|
|
|
|
U32_LE(kWasmVersion), // --
|
|
|
|
kCodeSectionCode, // Section ID
|
2017-12-02 00:30:37 +00:00
|
|
|
0xD, // Section Length
|
2017-11-15 12:14:26 +00:00
|
|
|
0x0, // Number of Functions
|
|
|
|
};
|
|
|
|
ExpectFailure(ArrayVector(data));
|
|
|
|
}
|
|
|
|
|
2017-05-11 08:51:54 +00:00
|
|
|
TEST_F(WasmStreamingDecoderTest, CodeSectionLengthTooLow) {
|
|
|
|
const uint8_t data[] = {
|
|
|
|
U32_LE(kWasmMagic), // --
|
|
|
|
U32_LE(kWasmVersion), // --
|
|
|
|
kCodeSectionCode, // Section ID
|
|
|
|
0x9, // Section Length
|
|
|
|
0x2, // Number of Functions
|
|
|
|
0x7, // Function Length
|
|
|
|
0x0, // Function
|
|
|
|
0x0, // 2
|
|
|
|
0x0, // 3
|
|
|
|
0x0, // 4
|
|
|
|
0x0, // 5
|
|
|
|
0x0, // 6
|
|
|
|
0x0, // 7
|
|
|
|
0x1, // Function Length
|
|
|
|
0x0, // Function
|
|
|
|
};
|
2017-12-01 10:51:10 +00:00
|
|
|
ExpectFailure(ArrayVector(data));
|
2017-05-11 08:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmStreamingDecoderTest, CodeSectionLengthTooLowEndsInNumFunctions) {
|
|
|
|
const uint8_t data[] = {
|
|
|
|
U32_LE(kWasmMagic), // --
|
|
|
|
U32_LE(kWasmVersion), // --
|
|
|
|
kCodeSectionCode, // Section ID
|
|
|
|
0x1, // Section Length
|
|
|
|
0x82, // Number of Functions
|
|
|
|
0x80, // --
|
|
|
|
0x00, // --
|
|
|
|
0x7, // Function Length
|
|
|
|
0x0, // Function
|
|
|
|
0x0, // 2
|
|
|
|
0x0, // 3
|
|
|
|
0x0, // 4
|
|
|
|
0x0, // 5
|
|
|
|
0x0, // 6
|
|
|
|
0x0, // 7
|
|
|
|
0x1, // Function Length
|
|
|
|
0x0, // Function
|
|
|
|
};
|
2017-12-01 10:51:10 +00:00
|
|
|
ExpectFailure(ArrayVector(data));
|
2017-05-11 08:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmStreamingDecoderTest, CodeSectionLengthTooLowEndsInFunctionLength) {
|
|
|
|
const uint8_t data[] = {
|
|
|
|
U32_LE(kWasmMagic), // --
|
|
|
|
U32_LE(kWasmVersion), // --
|
|
|
|
kCodeSectionCode, // Section ID
|
|
|
|
0x5, // Section Length
|
|
|
|
0x82, // Number of Functions
|
|
|
|
0x80, // --
|
|
|
|
0x00, // --
|
|
|
|
0x87, // Function Length
|
|
|
|
0x80, // --
|
|
|
|
0x00, // --
|
|
|
|
0x0, // Function
|
|
|
|
0x0, // 2
|
|
|
|
0x0, // 3
|
|
|
|
0x0, // 4
|
|
|
|
0x0, // 5
|
|
|
|
0x0, // 6
|
|
|
|
0x0, // 7
|
|
|
|
0x1, // Function Length
|
|
|
|
0x0, // Function
|
|
|
|
};
|
2017-12-01 10:51:10 +00:00
|
|
|
ExpectFailure(ArrayVector(data));
|
2017-05-11 08:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmStreamingDecoderTest, NumberOfFunctionsTooHigh) {
|
|
|
|
const uint8_t data[] = {
|
|
|
|
U32_LE(kWasmMagic), // --
|
|
|
|
U32_LE(kWasmVersion), // --
|
|
|
|
kCodeSectionCode, // Section ID
|
2017-12-02 00:30:37 +00:00
|
|
|
0xB, // Section Length
|
2017-05-11 08:51:54 +00:00
|
|
|
0x4, // Number of Functions
|
|
|
|
0x7, // Function Length
|
|
|
|
0x0, // Function
|
|
|
|
0x0, // 2
|
|
|
|
0x0, // 3
|
|
|
|
0x0, // 4
|
|
|
|
0x0, // 5
|
|
|
|
0x0, // 6
|
|
|
|
0x0, // 7
|
|
|
|
0x1, // Function Length
|
|
|
|
0x0, // Function
|
|
|
|
};
|
2017-12-01 10:51:10 +00:00
|
|
|
ExpectFailure(ArrayVector(data));
|
2017-05-11 08:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmStreamingDecoderTest, NumberOfFunctionsTooLow) {
|
|
|
|
const uint8_t data[] = {
|
|
|
|
U32_LE(kWasmMagic), // --
|
|
|
|
U32_LE(kWasmVersion), // --
|
|
|
|
kCodeSectionCode, // Section ID
|
2017-12-02 00:30:37 +00:00
|
|
|
0xE, // Section Length
|
2017-05-11 08:51:54 +00:00
|
|
|
0x2, // Number of Functions
|
|
|
|
0x1, // Function Length
|
|
|
|
0x0, // Function
|
|
|
|
0x2, // Function Length
|
|
|
|
0x0, // Function
|
|
|
|
0x0, // 2
|
|
|
|
0x7, // Function Length
|
|
|
|
0x0, // Function
|
|
|
|
0x0, // 2
|
|
|
|
0x0, // 3
|
|
|
|
0x0, // 4
|
|
|
|
0x0, // 5
|
|
|
|
0x0, // 6
|
|
|
|
0x0, // 7
|
|
|
|
};
|
2017-12-01 10:51:10 +00:00
|
|
|
ExpectFailure(ArrayVector(data));
|
2017-05-11 08:51:54 +00:00
|
|
|
}
|
2017-10-05 14:35:34 +00:00
|
|
|
|
|
|
|
TEST_F(WasmStreamingDecoderTest, TwoCodeSections) {
|
|
|
|
const uint8_t data[] = {
|
|
|
|
U32_LE(kWasmMagic), // --
|
|
|
|
U32_LE(kWasmVersion), // --
|
|
|
|
kCodeSectionCode, // Section ID
|
|
|
|
0x3, // Section Length
|
|
|
|
0x1, // Number of Functions
|
|
|
|
0x1, // Function Length
|
|
|
|
0x0, // Function
|
|
|
|
kCodeSectionCode, // Section ID
|
|
|
|
0x3, // Section Length
|
|
|
|
0x1, // Number of Functions
|
|
|
|
0x1, // Function Length
|
|
|
|
0x0, // Function
|
|
|
|
};
|
2017-12-01 10:51:10 +00:00
|
|
|
ExpectFailure(ArrayVector(data));
|
2017-10-05 14:35:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmStreamingDecoderTest, UnknownSection) {
|
|
|
|
const uint8_t data[] = {
|
|
|
|
U32_LE(kWasmMagic), // --
|
|
|
|
U32_LE(kWasmVersion), // --
|
|
|
|
kCodeSectionCode, // Section ID
|
|
|
|
0x3, // Section Length
|
|
|
|
0x1, // Number of Functions
|
|
|
|
0x1, // Function Length
|
|
|
|
0x0, // Function
|
|
|
|
kUnknownSectionCode, // Section ID
|
|
|
|
0x3, // Section Length
|
|
|
|
0x1, // Name Length
|
|
|
|
0x1, // Name
|
|
|
|
0x0, // Content
|
|
|
|
};
|
2017-12-01 10:51:10 +00:00
|
|
|
ExpectVerifies(ArrayVector(data), 1, 1);
|
2017-10-05 14:35:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmStreamingDecoderTest, UnknownSectionSandwich) {
|
|
|
|
const uint8_t data[] = {
|
|
|
|
U32_LE(kWasmMagic), // --
|
|
|
|
U32_LE(kWasmVersion), // --
|
|
|
|
kCodeSectionCode, // Section ID
|
|
|
|
0x3, // Section Length
|
|
|
|
0x1, // Number of Functions
|
|
|
|
0x1, // Function Length
|
|
|
|
0x0, // Function
|
|
|
|
kUnknownSectionCode, // Section ID
|
|
|
|
0x3, // Section Length
|
|
|
|
0x1, // Name Length
|
|
|
|
0x1, // Name
|
|
|
|
0x0, // Content
|
|
|
|
kCodeSectionCode, // Section ID
|
|
|
|
0x3, // Section Length
|
|
|
|
0x1, // Number of Functions
|
|
|
|
0x1, // Function Length
|
|
|
|
0x0, // Function
|
|
|
|
};
|
2017-12-01 10:51:10 +00:00
|
|
|
ExpectFailure(ArrayVector(data));
|
2017-10-05 14:35:34 +00:00
|
|
|
}
|
|
|
|
|
2017-05-11 08:51:54 +00:00
|
|
|
} // namespace wasm
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|