2015-12-11 12:26:16 +00:00
|
|
|
// Copyright 2015 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"
|
|
|
|
|
2016-06-21 12:52:57 +00:00
|
|
|
#include "src/handles.h"
|
|
|
|
#include "src/objects-inl.h"
|
2015-12-11 12:26:16 +00:00
|
|
|
#include "src/wasm/module-decoder.h"
|
2016-02-28 00:37:11 +00:00
|
|
|
#include "src/wasm/wasm-macro-gen.h"
|
2015-12-11 12:26:16 +00:00
|
|
|
#include "src/wasm/wasm-opcodes.h"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace wasm {
|
|
|
|
|
2016-02-28 00:37:11 +00:00
|
|
|
#define EMPTY_FUNCTION(sig_index) 0, SIG_INDEX(sig_index), U16_LE(0)
|
2016-05-13 08:44:28 +00:00
|
|
|
#define SIZEOF_EMPTY_FUNCTION ((size_t)5)
|
2016-03-09 22:50:36 +00:00
|
|
|
#define EMPTY_BODY 0
|
2016-04-29 09:39:26 +00:00
|
|
|
#define SIZEOF_EMPTY_BODY ((size_t)1)
|
2016-03-09 22:50:36 +00:00
|
|
|
#define NOP_BODY 2, 0, kExprNop
|
2016-04-29 09:39:26 +00:00
|
|
|
#define SIZEOF_NOP_BODY ((size_t)3)
|
2016-03-10 12:36:42 +00:00
|
|
|
|
2016-04-29 09:39:26 +00:00
|
|
|
#define SIG_ENTRY_i_i SIG_ENTRY_x_x(kLocalI32, kLocalI32)
|
|
|
|
|
|
|
|
#define UNKNOWN_EMPTY_SECTION_NAME 1, '\0'
|
|
|
|
#define UNKNOWN_SECTION_NAME 4, 'l', 'u', 'l', 'z'
|
|
|
|
|
|
|
|
#define SECTION(NAME, EXTRA_SIZE) WASM_SECTION_##NAME, U32V_1(EXTRA_SIZE)
|
|
|
|
|
|
|
|
#define SIGNATURES_SECTION(count, ...) \
|
|
|
|
SECTION(SIGNATURES, 1 + 3 * (count)), U32V_1(count), __VA_ARGS__
|
|
|
|
#define FUNCTION_SIGNATURES_SECTION(count, ...) \
|
|
|
|
SECTION(FUNCTION_SIGNATURES, 1 + (count)), U32V_1(count), __VA_ARGS__
|
|
|
|
|
|
|
|
#define FOO_STRING 3, 'f', 'o', 'o'
|
|
|
|
#define NO_LOCAL_NAMES 0
|
|
|
|
|
|
|
|
#define EMPTY_SIGNATURES_SECTION SECTION(SIGNATURES, 1), 0
|
|
|
|
#define EMPTY_FUNCTION_SIGNATURES_SECTION SECTION(FUNCTION_SIGNATURES, 1), 0
|
|
|
|
#define EMPTY_FUNCTION_BODIES_SECTION SECTION(FUNCTION_BODIES, 1), 0
|
|
|
|
#define EMPTY_NAMES_SECTION SECTION(NAMES, 1), 0
|
|
|
|
|
2016-05-25 16:12:09 +00:00
|
|
|
#define X1(...) __VA_ARGS__
|
|
|
|
#define X2(...) __VA_ARGS__, __VA_ARGS__
|
|
|
|
#define X3(...) __VA_ARGS__, __VA_ARGS__, __VA_ARGS__
|
|
|
|
#define X4(...) __VA_ARGS__, __VA_ARGS__, __VA_ARGS__, __VA_ARGS__
|
|
|
|
|
|
|
|
#define ONE_EMPTY_FUNCTION WASM_SECTION_FUNCTION_SIGNATURES, 1 + 1 * 1, 1, X1(0)
|
|
|
|
|
|
|
|
#define TWO_EMPTY_FUNCTIONS \
|
|
|
|
WASM_SECTION_FUNCTION_SIGNATURES, 1 + 2 * 1, 2, X2(0)
|
|
|
|
|
|
|
|
#define THREE_EMPTY_FUNCTIONS \
|
|
|
|
WASM_SECTION_FUNCTION_SIGNATURES, 1 + 3 * 1, 3, X3(0)
|
|
|
|
|
|
|
|
#define FOUR_EMPTY_FUNCTIONS \
|
|
|
|
WASM_SECTION_FUNCTION_SIGNATURES, 1 + 4 * 1, 4, X4(0)
|
|
|
|
|
|
|
|
#define ONE_EMPTY_BODY \
|
|
|
|
WASM_SECTION_FUNCTION_BODIES, 1 + 1 * (1 + SIZEOF_EMPTY_BODY), 1, \
|
|
|
|
X1(SIZEOF_EMPTY_BODY, EMPTY_BODY)
|
|
|
|
|
|
|
|
#define TWO_EMPTY_BODIES \
|
|
|
|
WASM_SECTION_FUNCTION_BODIES, 1 + 2 * (1 + SIZEOF_EMPTY_BODY), 2, \
|
|
|
|
X2(SIZEOF_EMPTY_BODY, EMPTY_BODY)
|
|
|
|
|
|
|
|
#define THREE_EMPTY_BODIES \
|
|
|
|
WASM_SECTION_FUNCTION_BODIES, 1 + 3 * (1 + SIZEOF_EMPTY_BODY), 3, \
|
|
|
|
X3(SIZEOF_EMPTY_BODY, EMPTY_BODY)
|
|
|
|
|
|
|
|
#define FOUR_EMPTY_BODIES \
|
|
|
|
WASM_SECTION_FUNCTION_BODIES, 1 + 4 * (1 + SIZEOF_EMPTY_BODY), 4, \
|
|
|
|
X4(SIZEOF_EMPTY_BODY, EMPTY_BODY)
|
|
|
|
|
2016-04-29 09:39:26 +00:00
|
|
|
#define SIGNATURES_SECTION_VOID_VOID \
|
|
|
|
SECTION(SIGNATURES, 1 + SIZEOF_SIG_ENTRY_v_v), 1, SIG_ENTRY_v_v
|
2016-02-27 01:52:30 +00:00
|
|
|
|
2015-12-11 12:26:16 +00:00
|
|
|
#define EXPECT_VERIFIES(data) \
|
|
|
|
do { \
|
|
|
|
ModuleResult result = DecodeModule(data, data + arraysize(data)); \
|
|
|
|
EXPECT_TRUE(result.ok()); \
|
2015-12-17 11:38:28 +00:00
|
|
|
if (result.val) delete result.val; \
|
2015-12-11 12:26:16 +00:00
|
|
|
} while (false)
|
|
|
|
|
2016-02-28 00:37:11 +00:00
|
|
|
#define EXPECT_FAILURE_LEN(data, length) \
|
|
|
|
do { \
|
|
|
|
ModuleResult result = DecodeModule(data, data + length); \
|
|
|
|
EXPECT_FALSE(result.ok()); \
|
|
|
|
if (result.val) delete result.val; \
|
2015-12-11 12:26:16 +00:00
|
|
|
} while (false)
|
|
|
|
|
2016-02-28 00:37:11 +00:00
|
|
|
#define EXPECT_FAILURE(data) EXPECT_FAILURE_LEN(data, sizeof(data))
|
|
|
|
|
|
|
|
#define EXPECT_OFF_END_FAILURE(data, min, max) \
|
|
|
|
do { \
|
|
|
|
for (size_t length = min; length < max; length++) { \
|
|
|
|
EXPECT_FAILURE_LEN(data, length); \
|
|
|
|
} \
|
|
|
|
} while (false)
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-04-21 11:18:41 +00:00
|
|
|
#define EXPECT_OK(result) \
|
|
|
|
do { \
|
|
|
|
EXPECT_TRUE(result.ok()); \
|
|
|
|
if (!result.ok()) { \
|
|
|
|
if (result.val) delete result.val; \
|
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
} while (false)
|
|
|
|
|
2016-03-10 12:36:42 +00:00
|
|
|
static size_t SizeOfVarInt(size_t value) {
|
|
|
|
size_t size = 0;
|
|
|
|
do {
|
|
|
|
size++;
|
|
|
|
value = value >> 7;
|
|
|
|
} while (value > 0);
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2015-12-11 12:26:16 +00:00
|
|
|
struct LocalTypePair {
|
|
|
|
uint8_t code;
|
|
|
|
LocalType type;
|
|
|
|
} kLocalTypes[] = {{kLocalI32, kAstI32},
|
|
|
|
{kLocalI64, kAstI64},
|
|
|
|
{kLocalF32, kAstF32},
|
|
|
|
{kLocalF64, kAstF64}};
|
|
|
|
|
[wasm] Adding metrics for Asm/Wasm.
Collecting:
Time histograms for: instantiate, decode module, decode function, compile, compile function.
Memory histograms for: decode peak, instantiate peak, compile function peak, min mem pages, max mem pages, function bytes, module bytes.
Range histograms of: functions per module.
BUG= https://code.google.com/p/v8/issues/detail?id=4203
BUG= https://bugs.chromium.org/p/chromium/issues/detail?id=575167
TEST=None
R=ahaas@chromium.org,bmeurer@chromium.org
LOG=N
Review URL: https://codereview.chromium.org/1866873002
Cr-Commit-Position: refs/heads/master@{#35467}
2016-04-14 07:28:22 +00:00
|
|
|
class WasmModuleVerifyTest : public TestWithIsolateAndZone {
|
2016-02-28 00:37:11 +00:00
|
|
|
public:
|
|
|
|
ModuleResult DecodeModule(const byte* module_start, const byte* module_end) {
|
|
|
|
// Add the WASM magic and version number automatically.
|
|
|
|
size_t size = static_cast<size_t>(module_end - module_start);
|
|
|
|
byte header[] = {WASM_MODULE_HEADER};
|
|
|
|
size_t total = sizeof(header) + size;
|
|
|
|
auto temp = new byte[total];
|
|
|
|
memcpy(temp, header, sizeof(header));
|
|
|
|
memcpy(temp + sizeof(header), module_start, size);
|
[wasm] Adding metrics for Asm/Wasm.
Collecting:
Time histograms for: instantiate, decode module, decode function, compile, compile function.
Memory histograms for: decode peak, instantiate peak, compile function peak, min mem pages, max mem pages, function bytes, module bytes.
Range histograms of: functions per module.
BUG= https://code.google.com/p/v8/issues/detail?id=4203
BUG= https://bugs.chromium.org/p/chromium/issues/detail?id=575167
TEST=None
R=ahaas@chromium.org,bmeurer@chromium.org
LOG=N
Review URL: https://codereview.chromium.org/1866873002
Cr-Commit-Position: refs/heads/master@{#35467}
2016-04-14 07:28:22 +00:00
|
|
|
ModuleResult result = DecodeWasmModule(isolate(), zone(), temp,
|
|
|
|
temp + total, false, kWasmOrigin);
|
2016-02-28 00:37:11 +00:00
|
|
|
delete[] temp;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
ModuleResult DecodeModuleNoHeader(const byte* module_start,
|
|
|
|
const byte* module_end) {
|
[wasm] Adding metrics for Asm/Wasm.
Collecting:
Time histograms for: instantiate, decode module, decode function, compile, compile function.
Memory histograms for: decode peak, instantiate peak, compile function peak, min mem pages, max mem pages, function bytes, module bytes.
Range histograms of: functions per module.
BUG= https://code.google.com/p/v8/issues/detail?id=4203
BUG= https://bugs.chromium.org/p/chromium/issues/detail?id=575167
TEST=None
R=ahaas@chromium.org,bmeurer@chromium.org
LOG=N
Review URL: https://codereview.chromium.org/1866873002
Cr-Commit-Position: refs/heads/master@{#35467}
2016-04-14 07:28:22 +00:00
|
|
|
return DecodeWasmModule(isolate(), zone(), module_start, module_end, false,
|
2016-02-28 00:37:11 +00:00
|
|
|
kWasmOrigin);
|
|
|
|
}
|
|
|
|
};
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-02-28 00:37:11 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, WrongMagic) {
|
|
|
|
for (uint32_t x = 1; x; x <<= 1) {
|
|
|
|
const byte data[] = {U32_LE(kWasmMagic ^ x), U32_LE(kWasmVersion),
|
2016-03-10 12:36:42 +00:00
|
|
|
SECTION(END, 0)};
|
2016-02-28 00:37:11 +00:00
|
|
|
ModuleResult result = DecodeModuleNoHeader(data, data + sizeof(data));
|
|
|
|
EXPECT_FALSE(result.ok());
|
2015-12-17 11:38:28 +00:00
|
|
|
if (result.val) delete result.val;
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
2016-02-28 00:37:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, WrongVersion) {
|
|
|
|
for (uint32_t x = 1; x; x <<= 1) {
|
|
|
|
const byte data[] = {U32_LE(kWasmMagic), U32_LE(kWasmVersion ^ x),
|
2016-03-10 12:36:42 +00:00
|
|
|
SECTION(END, 0)};
|
2016-02-28 00:37:11 +00:00
|
|
|
ModuleResult result = DecodeModuleNoHeader(data, data + sizeof(data));
|
|
|
|
EXPECT_FALSE(result.ok());
|
2015-12-17 11:38:28 +00:00
|
|
|
if (result.val) delete result.val;
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-28 00:37:11 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, DecodeEmpty) {
|
2016-03-10 12:36:42 +00:00
|
|
|
static const byte data[] = {SECTION(END, 0)};
|
2016-02-28 00:37:11 +00:00
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, OneGlobal) {
|
2016-02-19 14:58:25 +00:00
|
|
|
static const byte data[] = {
|
2016-04-21 11:18:41 +00:00
|
|
|
SECTION(GLOBALS, 5), // --
|
2015-12-11 12:26:16 +00:00
|
|
|
1,
|
2016-03-10 12:36:42 +00:00
|
|
|
NAME_LENGTH(1),
|
2016-07-21 12:34:28 +00:00
|
|
|
'g', // name
|
|
|
|
kLocalI32, // local type
|
|
|
|
0, // exported
|
2015-12-11 12:26:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
{
|
|
|
|
// Should decode to exactly one global.
|
|
|
|
ModuleResult result = DecodeModule(data, data + arraysize(data));
|
2016-04-21 11:18:41 +00:00
|
|
|
EXPECT_OK(result);
|
2016-02-28 19:04:10 +00:00
|
|
|
EXPECT_EQ(1, result.val->globals.size());
|
|
|
|
EXPECT_EQ(0, result.val->functions.size());
|
|
|
|
EXPECT_EQ(0, result.val->data_segments.size());
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-05-24 16:32:03 +00:00
|
|
|
const WasmGlobal* global = &result.val->globals.back();
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-03-09 18:55:27 +00:00
|
|
|
EXPECT_EQ(1, global->name_length);
|
2016-07-21 12:34:28 +00:00
|
|
|
EXPECT_EQ(kAstI32, global->type);
|
2015-12-11 12:26:16 +00:00
|
|
|
EXPECT_EQ(0, global->offset);
|
2015-12-17 11:38:28 +00:00
|
|
|
EXPECT_FALSE(global->exported);
|
|
|
|
|
|
|
|
if (result.val) delete result.val;
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-02-28 00:37:11 +00:00
|
|
|
EXPECT_OFF_END_FAILURE(data, 1, sizeof(data));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-06-07 09:35:52 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, Global_invalid_type) {
|
|
|
|
static const byte data[] = {
|
|
|
|
SECTION(GLOBALS, 5), // --
|
|
|
|
1,
|
|
|
|
NAME_LENGTH(1),
|
|
|
|
'g', // name
|
|
|
|
64, // invalid memory type
|
|
|
|
0, // exported
|
|
|
|
};
|
|
|
|
|
|
|
|
ModuleResult result = DecodeModuleNoHeader(data, data + sizeof(data));
|
|
|
|
EXPECT_FALSE(result.ok());
|
|
|
|
if (result.val) delete result.val;
|
|
|
|
}
|
|
|
|
|
2015-12-11 12:26:16 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ZeroGlobals) {
|
2016-02-19 14:58:25 +00:00
|
|
|
static const byte data[] = {
|
2016-03-10 12:36:42 +00:00
|
|
|
SECTION(GLOBALS, 1), // --
|
|
|
|
0, // declare 0 globals
|
2015-12-11 12:26:16 +00:00
|
|
|
};
|
|
|
|
ModuleResult result = DecodeModule(data, data + arraysize(data));
|
2016-04-21 11:18:41 +00:00
|
|
|
EXPECT_OK(result);
|
2015-12-17 11:38:28 +00:00
|
|
|
if (result.val) delete result.val;
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void AppendUint32v(std::vector<byte>& buffer, uint32_t val) {
|
|
|
|
while (true) {
|
|
|
|
uint32_t next = val >> 7;
|
|
|
|
uint32_t out = val & 0x7f;
|
|
|
|
if (next) {
|
|
|
|
buffer.push_back(static_cast<byte>(0x80 | out));
|
|
|
|
val = next;
|
|
|
|
} else {
|
|
|
|
buffer.push_back(static_cast<byte>(out));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, NGlobals) {
|
2016-02-19 14:58:25 +00:00
|
|
|
static const byte data[] = {
|
2016-07-21 12:34:28 +00:00
|
|
|
NO_NAME, // name length
|
|
|
|
kLocalF32, // memory type
|
|
|
|
0, // exported
|
2015-12-11 12:26:16 +00:00
|
|
|
};
|
2016-02-28 00:37:11 +00:00
|
|
|
|
|
|
|
for (uint32_t i = 0; i < 1000000; i = i * 13 + 1) {
|
2015-12-11 12:26:16 +00:00
|
|
|
std::vector<byte> buffer;
|
2016-04-29 09:39:26 +00:00
|
|
|
size_t size = SizeOfVarInt(i) + i * sizeof(data);
|
|
|
|
const byte globals[] = {WASM_SECTION_GLOBALS, U32V_5(size)};
|
2016-03-10 12:36:42 +00:00
|
|
|
for (size_t g = 0; g != sizeof(globals); ++g) {
|
|
|
|
buffer.push_back(globals[g]);
|
|
|
|
}
|
|
|
|
AppendUint32v(buffer, i); // Number of globals.
|
2015-12-17 11:38:28 +00:00
|
|
|
for (uint32_t j = 0; j < i; j++) {
|
2016-02-28 00:37:11 +00:00
|
|
|
buffer.insert(buffer.end(), data, data + sizeof(data));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ModuleResult result = DecodeModule(&buffer[0], &buffer[0] + buffer.size());
|
2016-04-21 11:18:41 +00:00
|
|
|
EXPECT_OK(result);
|
2015-12-17 11:38:28 +00:00
|
|
|
if (result.val) delete result.val;
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-10 12:36:42 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, GlobalWithInvalidNameOffset) {
|
|
|
|
static const byte data[] = {
|
|
|
|
SECTION(GLOBALS, 7),
|
|
|
|
1, // declare one global
|
|
|
|
NO_NAME, // name offset
|
|
|
|
33, // memory type
|
|
|
|
0, // exported
|
|
|
|
};
|
|
|
|
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-09-01 09:52:23 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, GlobalWithInvalidNameLength) {
|
|
|
|
static const byte data[] = {
|
|
|
|
SECTION(GLOBALS, 5), // --
|
|
|
|
1,
|
|
|
|
NAME_LENGTH(56), // invalid length
|
|
|
|
'g', // name
|
|
|
|
kLocalI32, // memory type
|
|
|
|
0, // exported
|
|
|
|
};
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
2015-12-11 12:26:16 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, GlobalWithInvalidMemoryType) {
|
2016-02-19 14:58:25 +00:00
|
|
|
static const byte data[] = {
|
2016-03-10 12:36:42 +00:00
|
|
|
SECTION(GLOBALS, 7),
|
2016-03-09 18:55:27 +00:00
|
|
|
1, // declare one global
|
2016-03-10 12:36:42 +00:00
|
|
|
NO_NAME, // name offset
|
2016-03-09 18:55:27 +00:00
|
|
|
33, // memory type
|
|
|
|
0, // exported
|
2015-12-11 12:26:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, TwoGlobals) {
|
2016-02-19 14:58:25 +00:00
|
|
|
static const byte data[] = {
|
2016-04-21 11:18:41 +00:00
|
|
|
SECTION(GLOBALS, 7),
|
2015-12-11 12:26:16 +00:00
|
|
|
2,
|
2016-07-21 12:34:28 +00:00
|
|
|
NO_NAME, // #0: name length
|
|
|
|
kLocalF32, // type
|
|
|
|
0, // exported
|
|
|
|
NO_NAME, // #1: name length
|
|
|
|
kLocalF64, // type
|
|
|
|
1, // exported
|
2015-12-11 12:26:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
{
|
|
|
|
// Should decode to exactly two globals.
|
|
|
|
ModuleResult result = DecodeModule(data, data + arraysize(data));
|
2016-04-21 11:18:41 +00:00
|
|
|
EXPECT_OK(result);
|
2016-02-28 19:04:10 +00:00
|
|
|
EXPECT_EQ(2, result.val->globals.size());
|
|
|
|
EXPECT_EQ(0, result.val->functions.size());
|
|
|
|
EXPECT_EQ(0, result.val->data_segments.size());
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-05-24 16:32:03 +00:00
|
|
|
const WasmGlobal* g0 = &result.val->globals[0];
|
|
|
|
const WasmGlobal* g1 = &result.val->globals[1];
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-03-09 18:55:27 +00:00
|
|
|
EXPECT_EQ(0, g0->name_length);
|
2016-07-21 12:34:28 +00:00
|
|
|
EXPECT_EQ(kAstF32, g0->type);
|
2015-12-11 12:26:16 +00:00
|
|
|
EXPECT_EQ(0, g0->offset);
|
2015-12-17 11:38:28 +00:00
|
|
|
EXPECT_FALSE(g0->exported);
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-03-09 18:55:27 +00:00
|
|
|
EXPECT_EQ(0, g1->name_length);
|
2016-07-21 12:34:28 +00:00
|
|
|
EXPECT_EQ(kAstF64, g1->type);
|
2016-05-24 16:32:03 +00:00
|
|
|
EXPECT_EQ(8, g1->offset);
|
2015-12-17 11:38:28 +00:00
|
|
|
EXPECT_TRUE(g1->exported);
|
|
|
|
|
|
|
|
if (result.val) delete result.val;
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-02-28 00:37:11 +00:00
|
|
|
EXPECT_OFF_END_FAILURE(data, 1, sizeof(data));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, OneSignature) {
|
2016-02-27 01:52:30 +00:00
|
|
|
{
|
2016-04-29 09:39:26 +00:00
|
|
|
static const byte data[] = {SIGNATURES_SECTION_VOID_VOID};
|
2016-02-27 01:52:30 +00:00
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2016-04-29 09:39:26 +00:00
|
|
|
static const byte data[] = {SECTION(SIGNATURES, 1 + SIZEOF_SIG_ENTRY_x_x),
|
|
|
|
1, SIG_ENTRY_i_i};
|
2016-02-27 01:52:30 +00:00
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, MultipleSignatures) {
|
|
|
|
static const byte data[] = {
|
2016-04-29 09:39:26 +00:00
|
|
|
SECTION(SIGNATURES, 1 + SIZEOF_SIG_ENTRY_v_v + SIZEOF_SIG_ENTRY_x_x +
|
|
|
|
SIZEOF_SIG_ENTRY_x_xx), // --
|
|
|
|
3, // --
|
|
|
|
SIG_ENTRY_v_v, // void -> void
|
|
|
|
SIG_ENTRY_x_x(kLocalI32, kLocalF32), // f32 -> i32
|
|
|
|
SIG_ENTRY_x_xx(kLocalI32, kLocalF64, kLocalF64), // f64,f64 -> i32
|
2015-12-11 12:26:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ModuleResult result = DecodeModule(data, data + arraysize(data));
|
2016-04-21 11:18:41 +00:00
|
|
|
EXPECT_OK(result);
|
2016-02-28 19:04:10 +00:00
|
|
|
EXPECT_EQ(3, result.val->signatures.size());
|
|
|
|
if (result.val->signatures.size() == 3) {
|
|
|
|
EXPECT_EQ(0, result.val->signatures[0]->return_count());
|
|
|
|
EXPECT_EQ(1, result.val->signatures[1]->return_count());
|
|
|
|
EXPECT_EQ(1, result.val->signatures[2]->return_count());
|
|
|
|
|
|
|
|
EXPECT_EQ(0, result.val->signatures[0]->parameter_count());
|
|
|
|
EXPECT_EQ(1, result.val->signatures[1]->parameter_count());
|
|
|
|
EXPECT_EQ(2, result.val->signatures[2]->parameter_count());
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
2015-12-17 11:38:28 +00:00
|
|
|
if (result.val) delete result.val;
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-02-28 00:37:11 +00:00
|
|
|
EXPECT_OFF_END_FAILURE(data, 1, sizeof(data));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, OneDataSegment) {
|
2016-04-29 09:39:26 +00:00
|
|
|
const byte kDataSegmentSourceOffset = 30;
|
2015-12-11 12:26:16 +00:00
|
|
|
const byte data[] = {
|
2016-03-10 12:36:42 +00:00
|
|
|
SECTION(MEMORY, 3),
|
|
|
|
28,
|
|
|
|
28,
|
|
|
|
1,
|
|
|
|
SECTION(DATA_SEGMENTS, 8),
|
|
|
|
1,
|
2016-03-09 19:43:02 +00:00
|
|
|
U32V_3(0x9bbaa), // dest addr
|
|
|
|
U32V_1(3), // source size
|
2016-03-10 12:36:42 +00:00
|
|
|
'a',
|
|
|
|
'b',
|
|
|
|
'c' // data bytes
|
2015-12-11 12:26:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
{
|
2016-01-20 15:19:58 +00:00
|
|
|
EXPECT_VERIFIES(data);
|
2015-12-11 12:26:16 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + arraysize(data));
|
2016-04-21 11:18:41 +00:00
|
|
|
EXPECT_OK(result);
|
2016-02-28 19:04:10 +00:00
|
|
|
EXPECT_EQ(0, result.val->globals.size());
|
|
|
|
EXPECT_EQ(0, result.val->functions.size());
|
|
|
|
EXPECT_EQ(1, result.val->data_segments.size());
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-05-24 16:32:03 +00:00
|
|
|
const WasmDataSegment* segment = &result.val->data_segments.back();
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(0x9bbaa, segment->dest_addr);
|
2016-03-09 19:43:02 +00:00
|
|
|
EXPECT_EQ(kDataSegmentSourceOffset, segment->source_offset);
|
2015-12-11 12:26:16 +00:00
|
|
|
EXPECT_EQ(3, segment->source_size);
|
2015-12-17 11:38:28 +00:00
|
|
|
EXPECT_TRUE(segment->init);
|
|
|
|
|
|
|
|
if (result.val) delete result.val;
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-03-10 12:36:42 +00:00
|
|
|
EXPECT_OFF_END_FAILURE(data, 13, sizeof(data));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, TwoDataSegments) {
|
2016-04-29 09:39:26 +00:00
|
|
|
const byte kDataSegment0SourceOffset = 30;
|
|
|
|
const byte kDataSegment1SourceOffset = 30 + 8;
|
2016-03-09 19:43:02 +00:00
|
|
|
|
2015-12-11 12:26:16 +00:00
|
|
|
const byte data[] = {
|
2016-03-10 12:36:42 +00:00
|
|
|
SECTION(MEMORY, 3),
|
|
|
|
28,
|
|
|
|
28,
|
|
|
|
1,
|
2016-04-21 11:18:41 +00:00
|
|
|
SECTION(DATA_SEGMENTS, 23),
|
2016-03-10 12:36:42 +00:00
|
|
|
2, // segment count
|
|
|
|
U32V_3(0x7ffee), // #0: dest addr
|
|
|
|
U32V_1(4), // source size
|
|
|
|
1,
|
|
|
|
2,
|
|
|
|
3,
|
|
|
|
4, // data bytes
|
|
|
|
U32V_3(0x6ddcc), // #1: dest addr
|
|
|
|
U32V_1(10), // source size
|
|
|
|
1,
|
|
|
|
2,
|
|
|
|
3,
|
|
|
|
4,
|
|
|
|
5,
|
|
|
|
6,
|
|
|
|
7,
|
|
|
|
8,
|
|
|
|
9,
|
|
|
|
10 // data bytes
|
2015-12-11 12:26:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
{
|
|
|
|
ModuleResult result = DecodeModule(data, data + arraysize(data));
|
2016-04-21 11:18:41 +00:00
|
|
|
EXPECT_OK(result);
|
2016-02-28 19:04:10 +00:00
|
|
|
EXPECT_EQ(0, result.val->globals.size());
|
|
|
|
EXPECT_EQ(0, result.val->functions.size());
|
|
|
|
EXPECT_EQ(2, result.val->data_segments.size());
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-05-24 16:32:03 +00:00
|
|
|
const WasmDataSegment* s0 = &result.val->data_segments[0];
|
|
|
|
const WasmDataSegment* s1 = &result.val->data_segments[1];
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(0x7ffee, s0->dest_addr);
|
2016-03-09 19:43:02 +00:00
|
|
|
EXPECT_EQ(kDataSegment0SourceOffset, s0->source_offset);
|
2015-12-11 12:26:16 +00:00
|
|
|
EXPECT_EQ(4, s0->source_size);
|
2016-03-09 19:43:02 +00:00
|
|
|
EXPECT_TRUE(s0->init);
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(0x6ddcc, s1->dest_addr);
|
2016-03-09 19:43:02 +00:00
|
|
|
EXPECT_EQ(kDataSegment1SourceOffset, s1->source_offset);
|
2015-12-11 12:26:16 +00:00
|
|
|
EXPECT_EQ(10, s1->source_size);
|
2015-12-17 11:38:28 +00:00
|
|
|
EXPECT_TRUE(s1->init);
|
|
|
|
|
|
|
|
if (result.val) delete result.val;
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-03-10 12:36:42 +00:00
|
|
|
EXPECT_OFF_END_FAILURE(data, 13, sizeof(data));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-01-20 15:19:58 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, DataSegmentWithInvalidDest) {
|
|
|
|
const int source_size = 3;
|
|
|
|
|
2016-03-02 23:58:36 +00:00
|
|
|
for (byte mem_pages = 1; mem_pages < 16; mem_pages++) {
|
|
|
|
int mem_size = mem_pages * 0x10000; // 64k pages.
|
2016-01-20 15:19:58 +00:00
|
|
|
|
|
|
|
for (int dest_addr = mem_size - source_size;
|
|
|
|
dest_addr < mem_size + source_size; dest_addr++) {
|
2016-03-10 12:36:42 +00:00
|
|
|
byte data[] = {SECTION(MEMORY, 3),
|
|
|
|
mem_pages,
|
|
|
|
mem_pages,
|
|
|
|
1,
|
2016-04-21 11:18:41 +00:00
|
|
|
SECTION(DATA_SEGMENTS, 8),
|
2016-03-10 12:36:42 +00:00
|
|
|
1,
|
|
|
|
U32V_3(dest_addr),
|
|
|
|
U32V_1(source_size),
|
|
|
|
'a',
|
|
|
|
'b',
|
|
|
|
'c'};
|
2016-01-20 15:19:58 +00:00
|
|
|
|
|
|
|
if (dest_addr <= (mem_size - source_size)) {
|
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
} else {
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-11 12:26:16 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, OneIndirectFunction) {
|
|
|
|
static const byte data[] = {
|
|
|
|
// sig#0 -------------------------------------------------------
|
2016-04-29 09:39:26 +00:00
|
|
|
SIGNATURES_SECTION_VOID_VOID,
|
2016-05-25 16:12:09 +00:00
|
|
|
// funcs ------------------------------------------------------
|
|
|
|
ONE_EMPTY_FUNCTION,
|
2015-12-11 12:26:16 +00:00
|
|
|
// indirect table ----------------------------------------------
|
2016-03-10 12:36:42 +00:00
|
|
|
SECTION(FUNCTION_TABLE, 2), 1, U32V_1(0)};
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
ModuleResult result = DecodeModule(data, data + arraysize(data));
|
2016-04-21 11:18:41 +00:00
|
|
|
EXPECT_OK(result);
|
2015-12-11 12:26:16 +00:00
|
|
|
if (result.ok()) {
|
2016-02-28 19:04:10 +00:00
|
|
|
EXPECT_EQ(1, result.val->signatures.size());
|
|
|
|
EXPECT_EQ(1, result.val->functions.size());
|
2016-07-28 04:56:56 +00:00
|
|
|
EXPECT_EQ(1, result.val->function_tables.size());
|
|
|
|
EXPECT_EQ(1, result.val->function_tables[0].values.size());
|
|
|
|
EXPECT_EQ(0, result.val->function_tables[0].values[0]);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
2015-12-17 11:38:28 +00:00
|
|
|
if (result.val) delete result.val;
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, MultipleIndirectFunctions) {
|
|
|
|
static const byte data[] = {
|
|
|
|
// sig#0 -------------------------------------------------------
|
2016-04-29 09:39:26 +00:00
|
|
|
SECTION(SIGNATURES, 1 + SIZEOF_SIG_ENTRY_v_v + SIZEOF_SIG_ENTRY_v_x),
|
|
|
|
2, // --
|
|
|
|
SIG_ENTRY_v_v, // void -> void
|
|
|
|
SIG_ENTRY_v_x(kLocalI32), // void -> i32
|
2016-05-25 16:12:09 +00:00
|
|
|
// funcs ------------------------------------------------------
|
|
|
|
FOUR_EMPTY_FUNCTIONS,
|
2015-12-11 12:26:16 +00:00
|
|
|
// indirect table ----------------------------------------------
|
2016-03-10 12:36:42 +00:00
|
|
|
SECTION(FUNCTION_TABLE, 9), 8,
|
2016-03-08 22:54:43 +00:00
|
|
|
U32V_1(0), // --
|
|
|
|
U32V_1(1), // --
|
|
|
|
U32V_1(2), // --
|
|
|
|
U32V_1(3), // --
|
|
|
|
U32V_1(0), // --
|
|
|
|
U32V_1(1), // --
|
|
|
|
U32V_1(2), // --
|
|
|
|
U32V_1(3), // --
|
2016-05-25 16:12:09 +00:00
|
|
|
FOUR_EMPTY_BODIES};
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
ModuleResult result = DecodeModule(data, data + arraysize(data));
|
2016-04-21 11:18:41 +00:00
|
|
|
EXPECT_OK(result);
|
2015-12-11 12:26:16 +00:00
|
|
|
if (result.ok()) {
|
2016-02-28 19:04:10 +00:00
|
|
|
EXPECT_EQ(2, result.val->signatures.size());
|
|
|
|
EXPECT_EQ(4, result.val->functions.size());
|
2016-07-28 04:56:56 +00:00
|
|
|
EXPECT_EQ(1, result.val->function_tables.size());
|
|
|
|
EXPECT_EQ(8, result.val->function_tables[0].values.size());
|
2015-12-11 12:26:16 +00:00
|
|
|
for (int i = 0; i < 8; i++) {
|
2016-07-28 04:56:56 +00:00
|
|
|
EXPECT_EQ(i & 3, result.val->function_tables[0].values[i]);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
2015-12-17 11:38:28 +00:00
|
|
|
if (result.val) delete result.val;
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, IndirectFunctionNoFunctions) {
|
|
|
|
static const byte data[] = {
|
|
|
|
// sig#0 -------------------------------------------------------
|
2016-04-29 09:39:26 +00:00
|
|
|
SIGNATURES_SECTION_VOID_VOID,
|
2015-12-11 12:26:16 +00:00
|
|
|
// indirect table ----------------------------------------------
|
2016-03-10 12:36:42 +00:00
|
|
|
SECTION(FUNCTION_TABLE, 3), 1, 0, 0,
|
2015-12-11 12:26:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, IndirectFunctionInvalidIndex) {
|
|
|
|
static const byte data[] = {
|
|
|
|
// sig#0 -------------------------------------------------------
|
2016-04-29 09:39:26 +00:00
|
|
|
SIGNATURES_SECTION_VOID_VOID,
|
2015-12-11 12:26:16 +00:00
|
|
|
// functions ---------------------------------------------------
|
2016-05-25 16:12:09 +00:00
|
|
|
ONE_EMPTY_FUNCTION,
|
2015-12-11 12:26:16 +00:00
|
|
|
// indirect table ----------------------------------------------
|
2016-03-10 12:36:42 +00:00
|
|
|
SECTION(FUNCTION_TABLE, 3), 1, 1, 0,
|
2015-12-11 12:26:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
class WasmSignatureDecodeTest : public TestWithZone {};
|
|
|
|
|
|
|
|
TEST_F(WasmSignatureDecodeTest, Ok_v_v) {
|
2016-04-29 09:39:26 +00:00
|
|
|
static const byte data[] = {SIG_ENTRY_v_v};
|
2016-04-01 10:00:30 +00:00
|
|
|
base::AccountingAllocator allocator;
|
|
|
|
Zone zone(&allocator);
|
2015-12-11 12:26:16 +00:00
|
|
|
FunctionSig* sig =
|
|
|
|
DecodeWasmSignatureForTesting(&zone, data, data + arraysize(data));
|
|
|
|
|
|
|
|
EXPECT_TRUE(sig != nullptr);
|
|
|
|
EXPECT_EQ(0, sig->parameter_count());
|
|
|
|
EXPECT_EQ(0, sig->return_count());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmSignatureDecodeTest, Ok_t_v) {
|
|
|
|
for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
|
|
|
|
LocalTypePair ret_type = kLocalTypes[i];
|
2016-04-29 09:39:26 +00:00
|
|
|
const byte data[] = {SIG_ENTRY_x(ret_type.code)};
|
2015-12-11 12:26:16 +00:00
|
|
|
FunctionSig* sig =
|
|
|
|
DecodeWasmSignatureForTesting(zone(), data, data + arraysize(data));
|
|
|
|
|
|
|
|
EXPECT_TRUE(sig != nullptr);
|
|
|
|
EXPECT_EQ(0, sig->parameter_count());
|
|
|
|
EXPECT_EQ(1, sig->return_count());
|
|
|
|
EXPECT_EQ(ret_type.type, sig->GetReturn());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmSignatureDecodeTest, Ok_v_t) {
|
|
|
|
for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
|
|
|
|
LocalTypePair param_type = kLocalTypes[i];
|
2016-04-29 09:39:26 +00:00
|
|
|
const byte data[] = {SIG_ENTRY_v_x(param_type.code)};
|
2015-12-11 12:26:16 +00:00
|
|
|
FunctionSig* sig =
|
|
|
|
DecodeWasmSignatureForTesting(zone(), data, data + arraysize(data));
|
|
|
|
|
|
|
|
EXPECT_TRUE(sig != nullptr);
|
|
|
|
EXPECT_EQ(1, sig->parameter_count());
|
|
|
|
EXPECT_EQ(0, sig->return_count());
|
|
|
|
EXPECT_EQ(param_type.type, sig->GetParam(0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmSignatureDecodeTest, Ok_t_t) {
|
|
|
|
for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
|
|
|
|
LocalTypePair ret_type = kLocalTypes[i];
|
|
|
|
for (size_t j = 0; j < arraysize(kLocalTypes); j++) {
|
|
|
|
LocalTypePair param_type = kLocalTypes[j];
|
2016-04-29 09:39:26 +00:00
|
|
|
const byte data[] = {SIG_ENTRY_x_x(ret_type.code, param_type.code)};
|
2015-12-11 12:26:16 +00:00
|
|
|
FunctionSig* sig =
|
|
|
|
DecodeWasmSignatureForTesting(zone(), data, data + arraysize(data));
|
|
|
|
|
|
|
|
EXPECT_TRUE(sig != nullptr);
|
|
|
|
EXPECT_EQ(1, sig->parameter_count());
|
|
|
|
EXPECT_EQ(1, sig->return_count());
|
|
|
|
EXPECT_EQ(param_type.type, sig->GetParam(0));
|
|
|
|
EXPECT_EQ(ret_type.type, sig->GetReturn());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmSignatureDecodeTest, Ok_i_tt) {
|
|
|
|
for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
|
|
|
|
LocalTypePair p0_type = kLocalTypes[i];
|
|
|
|
for (size_t j = 0; j < arraysize(kLocalTypes); j++) {
|
|
|
|
LocalTypePair p1_type = kLocalTypes[j];
|
2016-04-29 09:39:26 +00:00
|
|
|
const byte data[] = {
|
|
|
|
SIG_ENTRY_x_xx(kLocalI32, p0_type.code, p1_type.code)};
|
2015-12-11 12:26:16 +00:00
|
|
|
FunctionSig* sig =
|
|
|
|
DecodeWasmSignatureForTesting(zone(), data, data + arraysize(data));
|
|
|
|
|
|
|
|
EXPECT_TRUE(sig != nullptr);
|
|
|
|
EXPECT_EQ(2, sig->parameter_count());
|
|
|
|
EXPECT_EQ(1, sig->return_count());
|
|
|
|
EXPECT_EQ(p0_type.type, sig->GetParam(0));
|
|
|
|
EXPECT_EQ(p1_type.type, sig->GetParam(1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmSignatureDecodeTest, Fail_off_end) {
|
|
|
|
byte data[256];
|
|
|
|
for (int p = 0; p <= 255; p = p + 1 + p * 3) {
|
|
|
|
for (int i = 0; i <= p; i++) data[i] = kLocalI32;
|
|
|
|
data[0] = static_cast<byte>(p);
|
|
|
|
|
|
|
|
for (int i = 0; i < p + 1; i++) {
|
|
|
|
// Should fall off the end for all signatures.
|
|
|
|
FunctionSig* sig = DecodeWasmSignatureForTesting(zone(), data, data + i);
|
|
|
|
EXPECT_EQ(nullptr, sig);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmSignatureDecodeTest, Fail_invalid_type) {
|
|
|
|
byte kInvalidType = 76;
|
2016-04-29 09:39:26 +00:00
|
|
|
for (size_t i = 0; i < SIZEOF_SIG_ENTRY_x_xx; i++) {
|
|
|
|
byte data[] = {SIG_ENTRY_x_xx(kLocalI32, kLocalI32, kLocalI32)};
|
2015-12-11 12:26:16 +00:00
|
|
|
data[i] = kInvalidType;
|
|
|
|
FunctionSig* sig =
|
|
|
|
DecodeWasmSignatureForTesting(zone(), data, data + arraysize(data));
|
|
|
|
EXPECT_EQ(nullptr, sig);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-29 09:39:26 +00:00
|
|
|
TEST_F(WasmSignatureDecodeTest, Fail_invalid_ret_type1) {
|
|
|
|
static const byte data[] = {SIG_ENTRY_x_x(kLocalVoid, kLocalI32)};
|
|
|
|
FunctionSig* sig =
|
|
|
|
DecodeWasmSignatureForTesting(zone(), data, data + arraysize(data));
|
|
|
|
EXPECT_EQ(nullptr, sig);
|
|
|
|
}
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-04-29 09:39:26 +00:00
|
|
|
TEST_F(WasmSignatureDecodeTest, Fail_invalid_param_type1) {
|
|
|
|
static const byte data[] = {SIG_ENTRY_x_x(kLocalI32, kLocalVoid)};
|
|
|
|
FunctionSig* sig =
|
|
|
|
DecodeWasmSignatureForTesting(zone(), data, data + arraysize(data));
|
|
|
|
EXPECT_EQ(nullptr, sig);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmSignatureDecodeTest, Fail_invalid_param_type2) {
|
|
|
|
static const byte data[] = {SIG_ENTRY_x_xx(kLocalI32, kLocalI32, kLocalVoid)};
|
|
|
|
FunctionSig* sig =
|
|
|
|
DecodeWasmSignatureForTesting(zone(), data, data + arraysize(data));
|
|
|
|
EXPECT_EQ(nullptr, sig);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
[wasm] Adding metrics for Asm/Wasm.
Collecting:
Time histograms for: instantiate, decode module, decode function, compile, compile function.
Memory histograms for: decode peak, instantiate peak, compile function peak, min mem pages, max mem pages, function bytes, module bytes.
Range histograms of: functions per module.
BUG= https://code.google.com/p/v8/issues/detail?id=4203
BUG= https://bugs.chromium.org/p/chromium/issues/detail?id=575167
TEST=None
R=ahaas@chromium.org,bmeurer@chromium.org
LOG=N
Review URL: https://codereview.chromium.org/1866873002
Cr-Commit-Position: refs/heads/master@{#35467}
2016-04-14 07:28:22 +00:00
|
|
|
class WasmFunctionVerifyTest : public TestWithIsolateAndZone {};
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
TEST_F(WasmFunctionVerifyTest, Ok_v_v_empty) {
|
2016-02-19 14:58:25 +00:00
|
|
|
static const byte data[] = {
|
2016-04-29 09:39:26 +00:00
|
|
|
SIG_ENTRY_v_v, // signature entry
|
|
|
|
4, // locals
|
|
|
|
3,
|
|
|
|
kLocalI32, // --
|
|
|
|
4,
|
|
|
|
kLocalI64, // --
|
|
|
|
5,
|
|
|
|
kLocalF32, // --
|
|
|
|
6,
|
|
|
|
kLocalF64, // --
|
|
|
|
kExprNop // body
|
2015-12-11 12:26:16 +00:00
|
|
|
};
|
|
|
|
|
[wasm] Adding metrics for Asm/Wasm.
Collecting:
Time histograms for: instantiate, decode module, decode function, compile, compile function.
Memory histograms for: decode peak, instantiate peak, compile function peak, min mem pages, max mem pages, function bytes, module bytes.
Range histograms of: functions per module.
BUG= https://code.google.com/p/v8/issues/detail?id=4203
BUG= https://bugs.chromium.org/p/chromium/issues/detail?id=575167
TEST=None
R=ahaas@chromium.org,bmeurer@chromium.org
LOG=N
Review URL: https://codereview.chromium.org/1866873002
Cr-Commit-Position: refs/heads/master@{#35467}
2016-04-14 07:28:22 +00:00
|
|
|
FunctionResult result = DecodeWasmFunction(isolate(), zone(), nullptr, data,
|
2015-12-11 12:26:16 +00:00
|
|
|
data + arraysize(data));
|
2016-04-21 11:18:41 +00:00
|
|
|
EXPECT_OK(result);
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
if (result.val && result.ok()) {
|
|
|
|
WasmFunction* function = result.val;
|
|
|
|
EXPECT_EQ(0, function->sig->parameter_count());
|
|
|
|
EXPECT_EQ(0, function->sig->return_count());
|
|
|
|
EXPECT_EQ(0, function->name_offset);
|
2016-04-29 09:39:26 +00:00
|
|
|
EXPECT_EQ(SIZEOF_SIG_ENTRY_v_v, function->code_start_offset);
|
2015-12-11 12:26:16 +00:00
|
|
|
EXPECT_EQ(arraysize(data), function->code_end_offset);
|
2016-03-07 21:04:07 +00:00
|
|
|
// TODO(titzer): verify encoding of local declarations
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
2015-12-17 11:38:28 +00:00
|
|
|
|
|
|
|
if (result.val) delete result.val;
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
2016-01-08 00:35:57 +00:00
|
|
|
|
2016-03-10 12:36:42 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, SectionWithoutNameLength) {
|
|
|
|
const byte data[] = {1};
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, TheLoneliestOfValidModulesTheTrulyEmptyOne) {
|
2016-01-08 00:35:57 +00:00
|
|
|
const byte data[] = {
|
2016-03-10 12:36:42 +00:00
|
|
|
0, // Empty section name.
|
|
|
|
// No section name, no content, nothing but sadness.
|
2016-04-29 09:39:26 +00:00
|
|
|
0, // No section content.
|
2016-01-08 00:35:57 +00:00
|
|
|
};
|
2016-03-10 12:36:42 +00:00
|
|
|
EXPECT_VERIFIES(data);
|
2016-01-08 00:35:57 +00:00
|
|
|
}
|
|
|
|
|
2016-03-10 12:36:42 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, OnlyUnknownSectionEmpty) {
|
|
|
|
const byte data[] = {
|
2016-04-29 09:39:26 +00:00
|
|
|
UNKNOWN_SECTION_NAME, 0,
|
2016-03-10 12:36:42 +00:00
|
|
|
};
|
|
|
|
EXPECT_VERIFIES(data);
|
2016-01-08 00:35:57 +00:00
|
|
|
}
|
|
|
|
|
2016-03-10 12:36:42 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, OnlyUnknownSectionNonEmpty) {
|
|
|
|
const byte data[] = {
|
2016-04-29 09:39:26 +00:00
|
|
|
UNKNOWN_SECTION_NAME,
|
|
|
|
5, // section size
|
|
|
|
0xff,
|
|
|
|
0xff,
|
|
|
|
0xff,
|
|
|
|
0xff,
|
|
|
|
0xff, // section data
|
2016-01-08 00:35:57 +00:00
|
|
|
};
|
2016-03-10 12:36:42 +00:00
|
|
|
EXPECT_VERIFIES(data);
|
2016-01-08 00:35:57 +00:00
|
|
|
}
|
|
|
|
|
2016-03-10 12:36:42 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, SignatureFollowedByEmptyUnknownSection) {
|
|
|
|
const byte data[] = {
|
2016-04-29 09:39:26 +00:00
|
|
|
// signatures
|
|
|
|
SIGNATURES_SECTION_VOID_VOID,
|
2016-03-10 12:36:42 +00:00
|
|
|
// -----------------------------------------------------------
|
2016-04-29 09:39:26 +00:00
|
|
|
UNKNOWN_SECTION_NAME,
|
|
|
|
0 // empty section
|
2016-01-08 00:35:57 +00:00
|
|
|
};
|
2016-03-10 12:36:42 +00:00
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, SignatureFollowedByUnknownSection) {
|
|
|
|
const byte data[] = {
|
2016-04-29 09:39:26 +00:00
|
|
|
// signatures
|
|
|
|
SIGNATURES_SECTION_VOID_VOID,
|
2016-03-10 12:36:42 +00:00
|
|
|
// -----------------------------------------------------------
|
2016-04-29 09:39:26 +00:00
|
|
|
UNKNOWN_SECTION_NAME,
|
|
|
|
5, // section size
|
2016-03-10 12:36:42 +00:00
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff,
|
|
|
|
};
|
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, SignatureFollowedByUnknownSectionWithLongLEB) {
|
|
|
|
const byte data[] = {
|
2016-04-29 09:39:26 +00:00
|
|
|
// signatures
|
|
|
|
SIGNATURES_SECTION_VOID_VOID,
|
2016-03-10 12:36:42 +00:00
|
|
|
// -----------------------------------------------------------
|
2016-04-29 09:39:26 +00:00
|
|
|
UNKNOWN_SECTION_NAME, 0x81, 0x80, 0x80, 0x80,
|
|
|
|
0x00, // section size: 1 but in a 5-byte LEB
|
|
|
|
0,
|
2016-03-10 12:36:42 +00:00
|
|
|
};
|
|
|
|
EXPECT_VERIFIES(data);
|
2016-01-08 00:35:57 +00:00
|
|
|
}
|
|
|
|
|
2016-03-03 16:52:10 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, UnknownSectionOverflow) {
|
2016-02-19 14:58:25 +00:00
|
|
|
static const byte data[] = {
|
2016-04-29 09:39:26 +00:00
|
|
|
UNKNOWN_EMPTY_SECTION_NAME,
|
|
|
|
9, // section size
|
|
|
|
1,
|
|
|
|
2,
|
|
|
|
3,
|
|
|
|
4,
|
|
|
|
5,
|
|
|
|
6,
|
|
|
|
7,
|
|
|
|
8,
|
|
|
|
9,
|
|
|
|
10, // 10 byte section
|
2016-01-08 00:35:57 +00:00
|
|
|
};
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
2016-03-03 16:52:10 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, UnknownSectionUnderflow) {
|
2016-02-19 14:58:25 +00:00
|
|
|
static const byte data[] = {
|
2016-04-29 09:39:26 +00:00
|
|
|
UNKNOWN_EMPTY_SECTION_NAME,
|
|
|
|
0xff,
|
|
|
|
0xff,
|
|
|
|
0xff,
|
|
|
|
0xff,
|
|
|
|
0x0f, // Section size LEB128 0xffffffff
|
|
|
|
1,
|
|
|
|
2,
|
|
|
|
3,
|
|
|
|
4, // 4 byte section
|
2016-01-08 00:35:57 +00:00
|
|
|
};
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
2016-03-03 16:52:10 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, UnknownSectionLoop) {
|
2016-01-08 00:35:57 +00:00
|
|
|
// Would infinite loop decoding if wrapping and allowed.
|
2016-02-19 14:58:25 +00:00
|
|
|
static const byte data[] = {
|
2016-04-29 09:39:26 +00:00
|
|
|
UNKNOWN_EMPTY_SECTION_NAME,
|
|
|
|
1,
|
|
|
|
2,
|
|
|
|
3,
|
|
|
|
4, // 4 byte section
|
|
|
|
0xfa,
|
|
|
|
0xff,
|
|
|
|
0xff,
|
|
|
|
0xff,
|
|
|
|
0x0f, // Section size LEB128 0xfffffffa
|
2016-01-08 00:35:57 +00:00
|
|
|
};
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
2016-03-03 16:52:10 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, UnknownSectionSkipped) {
|
|
|
|
static const byte data[] = {
|
2016-04-29 09:39:26 +00:00
|
|
|
UNKNOWN_EMPTY_SECTION_NAME,
|
|
|
|
1, // section size
|
|
|
|
0, // one byte section
|
2016-04-21 11:18:41 +00:00
|
|
|
SECTION(GLOBALS, 4),
|
2016-03-03 16:52:10 +00:00
|
|
|
1,
|
2016-07-21 12:34:28 +00:00
|
|
|
0, // name length
|
|
|
|
kLocalI32, // memory type
|
|
|
|
0, // exported
|
2016-03-03 16:52:10 +00:00
|
|
|
};
|
|
|
|
ModuleResult result = DecodeModule(data, data + arraysize(data));
|
2016-04-21 11:18:41 +00:00
|
|
|
EXPECT_OK(result);
|
2016-03-03 16:52:10 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(1, result.val->globals.size());
|
|
|
|
EXPECT_EQ(0, result.val->functions.size());
|
|
|
|
EXPECT_EQ(0, result.val->data_segments.size());
|
|
|
|
|
2016-05-24 16:32:03 +00:00
|
|
|
const WasmGlobal* global = &result.val->globals.back();
|
2016-03-03 16:52:10 +00:00
|
|
|
|
2016-03-09 18:55:27 +00:00
|
|
|
EXPECT_EQ(0, global->name_length);
|
2016-07-21 12:34:28 +00:00
|
|
|
EXPECT_EQ(kAstI32, global->type);
|
2016-03-03 16:52:10 +00:00
|
|
|
EXPECT_EQ(0, global->offset);
|
|
|
|
EXPECT_FALSE(global->exported);
|
|
|
|
|
|
|
|
if (result.val) delete result.val;
|
|
|
|
}
|
|
|
|
|
2016-02-19 14:58:25 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ImportTable_empty) {
|
2016-03-10 12:36:42 +00:00
|
|
|
static const byte data[] = {SECTION(SIGNATURES, 1), 0,
|
|
|
|
SECTION(IMPORT_TABLE, 1), 0};
|
2016-02-19 14:58:25 +00:00
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
2016-04-21 11:18:41 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ImportTable_nosigs1) {
|
2016-03-10 12:36:42 +00:00
|
|
|
static const byte data[] = {SECTION(IMPORT_TABLE, 1), 0};
|
2016-04-21 11:18:41 +00:00
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, ImportTable_nosigs2) {
|
|
|
|
static const byte data[] = {
|
|
|
|
SECTION(IMPORT_TABLE, 6), 1, // sig table
|
|
|
|
IMPORT_SIG_INDEX(0), // sig index
|
|
|
|
NAME_LENGTH(1), 'm', // module name
|
|
|
|
NAME_LENGTH(1), 'f', // function name
|
|
|
|
};
|
2016-02-19 14:58:25 +00:00
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, ImportTable_invalid_sig) {
|
|
|
|
static const byte data[] = {
|
2016-04-29 09:39:26 +00:00
|
|
|
SECTION(SIGNATURES, 1), 0, // --
|
|
|
|
SECTION(IMPORT_TABLE, 6), 1, // --
|
|
|
|
IMPORT_SIG_INDEX(0), // sig index
|
|
|
|
NAME_LENGTH(1), 'm', // module name
|
|
|
|
NAME_LENGTH(1), 'f', // function name
|
2016-02-19 14:58:25 +00:00
|
|
|
};
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, ImportTable_one_sig) {
|
|
|
|
static const byte data[] = {
|
2016-04-29 09:39:26 +00:00
|
|
|
// signatures
|
|
|
|
SIGNATURES_SECTION_VOID_VOID,
|
2016-03-10 12:36:42 +00:00
|
|
|
SECTION(IMPORT_TABLE, 6),
|
2016-03-09 18:55:27 +00:00
|
|
|
1, // --
|
|
|
|
IMPORT_SIG_INDEX(0), // sig index
|
2016-03-10 12:36:42 +00:00
|
|
|
NAME_LENGTH(1),
|
|
|
|
'm', // module name
|
|
|
|
NAME_LENGTH(1),
|
|
|
|
'f', // function name
|
2016-02-19 14:58:25 +00:00
|
|
|
};
|
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
2016-03-08 19:55:36 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ImportTable_invalid_module) {
|
|
|
|
static const byte data[] = {
|
2016-04-29 09:39:26 +00:00
|
|
|
// signatures
|
|
|
|
SIGNATURES_SECTION_VOID_VOID,
|
2016-03-10 12:36:42 +00:00
|
|
|
SECTION(IMPORT_TABLE, 6),
|
2016-03-09 18:55:27 +00:00
|
|
|
1, // --
|
|
|
|
IMPORT_SIG_INDEX(0), // sig index
|
|
|
|
NO_NAME, // module name
|
2016-03-10 12:36:42 +00:00
|
|
|
NAME_LENGTH(1),
|
|
|
|
'f' // function name
|
2016-03-08 19:55:36 +00:00
|
|
|
};
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
2016-02-19 14:58:25 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ImportTable_off_end) {
|
|
|
|
static const byte data[] = {
|
2016-04-29 09:39:26 +00:00
|
|
|
// signatures
|
|
|
|
SIGNATURES_SECTION_VOID_VOID,
|
2016-03-10 12:36:42 +00:00
|
|
|
SECTION(IMPORT_TABLE, 6),
|
|
|
|
1,
|
2016-03-09 18:55:27 +00:00
|
|
|
IMPORT_SIG_INDEX(0), // sig index
|
2016-03-10 12:36:42 +00:00
|
|
|
NAME_LENGTH(1),
|
|
|
|
'm', // module name
|
|
|
|
NAME_LENGTH(1),
|
|
|
|
'f', // function name
|
2016-02-19 14:58:25 +00:00
|
|
|
};
|
|
|
|
|
2016-03-10 12:36:42 +00:00
|
|
|
EXPECT_OFF_END_FAILURE(data, 16, sizeof(data));
|
2016-02-19 14:58:25 +00:00
|
|
|
}
|
|
|
|
|
2016-03-09 22:50:36 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ExportTable_empty1) {
|
2016-05-25 16:12:09 +00:00
|
|
|
static const byte data[] = {// signatures
|
|
|
|
SIGNATURES_SECTION_VOID_VOID, ONE_EMPTY_FUNCTION,
|
|
|
|
SECTION(EXPORT_TABLE, 1),
|
|
|
|
0, // --
|
|
|
|
ONE_EMPTY_BODY};
|
|
|
|
|
|
|
|
ModuleResult result = DecodeModule(data, data + arraysize(data));
|
|
|
|
EXPECT_OK(result);
|
|
|
|
|
|
|
|
EXPECT_EQ(1, result.val->functions.size());
|
|
|
|
EXPECT_EQ(0, result.val->export_table.size());
|
|
|
|
|
|
|
|
if (result.val) delete result.val;
|
2016-02-27 01:52:30 +00:00
|
|
|
}
|
|
|
|
|
2016-03-09 22:50:36 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ExportTable_empty2) {
|
2016-04-29 09:39:26 +00:00
|
|
|
static const byte data[] = {
|
2016-05-25 16:12:09 +00:00
|
|
|
SECTION(SIGNATURES, 1), 0, SECTION(EXPORT_TABLE, 1), 0 // --
|
2016-04-29 09:39:26 +00:00
|
|
|
};
|
2016-03-09 22:50:36 +00:00
|
|
|
// TODO(titzer): current behavior treats empty functions section as missing.
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
2016-02-27 01:52:30 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ExportTable_NoFunctions1) {
|
2016-04-29 09:39:26 +00:00
|
|
|
static const byte data[] = {
|
|
|
|
SECTION(SIGNATURES, 1), 0, SECTION(EXPORT_TABLE, 1), 0 // --
|
|
|
|
};
|
2016-02-27 01:52:30 +00:00
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, ExportTable_NoFunctions2) {
|
2016-03-10 12:36:42 +00:00
|
|
|
static const byte data[] = {SECTION(EXPORT_TABLE, 1), 0};
|
2016-02-27 01:52:30 +00:00
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, ExportTableOne) {
|
2016-05-25 16:12:09 +00:00
|
|
|
static const byte data[] = {// signatures
|
|
|
|
SIGNATURES_SECTION_VOID_VOID,
|
|
|
|
ONE_EMPTY_FUNCTION,
|
|
|
|
SECTION(EXPORT_TABLE, 3),
|
|
|
|
1, // exports
|
|
|
|
FUNC_INDEX(0), // --
|
|
|
|
NO_NAME, // --
|
|
|
|
ONE_EMPTY_BODY};
|
|
|
|
ModuleResult result = DecodeModule(data, data + arraysize(data));
|
|
|
|
EXPECT_OK(result);
|
|
|
|
|
|
|
|
EXPECT_EQ(1, result.val->functions.size());
|
|
|
|
EXPECT_EQ(1, result.val->export_table.size());
|
|
|
|
|
|
|
|
if (result.val) delete result.val;
|
2016-02-27 01:52:30 +00:00
|
|
|
}
|
|
|
|
|
2016-09-06 09:50:12 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ExportNameWithInvalidStringLength) {
|
|
|
|
static const byte data[] = {// signatures
|
|
|
|
SIGNATURES_SECTION_VOID_VOID,
|
|
|
|
ONE_EMPTY_FUNCTION,
|
|
|
|
SECTION(EXPORT_TABLE, 12),
|
|
|
|
1, // exports
|
|
|
|
FUNC_INDEX(0), // --
|
|
|
|
NAME_LENGTH(84), // invalid string length
|
|
|
|
'e', // --
|
|
|
|
ONE_EMPTY_BODY};
|
|
|
|
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
2016-02-27 01:52:30 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ExportTableTwo) {
|
2016-05-25 16:12:09 +00:00
|
|
|
static const byte data[] = {// signatures
|
|
|
|
SIGNATURES_SECTION_VOID_VOID,
|
|
|
|
ONE_EMPTY_FUNCTION,
|
|
|
|
SECTION(EXPORT_TABLE, 12),
|
|
|
|
2, // exports
|
|
|
|
FUNC_INDEX(0), // --
|
|
|
|
NAME_LENGTH(4),
|
|
|
|
'n',
|
|
|
|
'a',
|
|
|
|
'm',
|
|
|
|
'e', // --
|
|
|
|
FUNC_INDEX(0), // --
|
|
|
|
NAME_LENGTH(3),
|
|
|
|
'n',
|
|
|
|
'o',
|
|
|
|
'm', // --
|
|
|
|
ONE_EMPTY_BODY};
|
|
|
|
|
|
|
|
ModuleResult result = DecodeModule(data, data + arraysize(data));
|
|
|
|
EXPECT_OK(result);
|
|
|
|
|
|
|
|
EXPECT_EQ(1, result.val->functions.size());
|
|
|
|
EXPECT_EQ(2, result.val->export_table.size());
|
|
|
|
|
|
|
|
if (result.val) delete result.val;
|
2016-02-27 01:52:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, ExportTableThree) {
|
2016-05-25 16:12:09 +00:00
|
|
|
static const byte data[] = {// signatures
|
|
|
|
SIGNATURES_SECTION_VOID_VOID,
|
|
|
|
THREE_EMPTY_FUNCTIONS,
|
|
|
|
SECTION(EXPORT_TABLE, 10),
|
|
|
|
3, // exports
|
|
|
|
FUNC_INDEX(0), // --
|
|
|
|
NAME_LENGTH(1),
|
|
|
|
'a', // --
|
|
|
|
FUNC_INDEX(1), // --
|
|
|
|
NAME_LENGTH(1),
|
|
|
|
'b', // --
|
|
|
|
FUNC_INDEX(2), // --
|
|
|
|
NAME_LENGTH(1),
|
|
|
|
'c', // --
|
|
|
|
THREE_EMPTY_BODIES};
|
|
|
|
ModuleResult result = DecodeModule(data, data + arraysize(data));
|
|
|
|
EXPECT_OK(result);
|
|
|
|
|
|
|
|
EXPECT_EQ(3, result.val->functions.size());
|
|
|
|
EXPECT_EQ(3, result.val->export_table.size());
|
|
|
|
|
|
|
|
if (result.val) delete result.val;
|
2016-02-27 01:52:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, ExportTableThreeOne) {
|
|
|
|
for (int i = 0; i < 6; i++) {
|
2016-05-25 16:12:09 +00:00
|
|
|
const byte data[] = {// signatures
|
|
|
|
SIGNATURES_SECTION_VOID_VOID,
|
|
|
|
THREE_EMPTY_FUNCTIONS,
|
|
|
|
SECTION(EXPORT_TABLE, 5),
|
|
|
|
1, // exports
|
|
|
|
FUNC_INDEX(i), // --
|
|
|
|
NAME_LENGTH(2),
|
|
|
|
'e',
|
|
|
|
'x', // --
|
|
|
|
THREE_EMPTY_BODIES};
|
2016-02-27 01:52:30 +00:00
|
|
|
|
|
|
|
if (i < 3) {
|
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
} else {
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, ExportTableOne_off_end) {
|
|
|
|
static const byte data[] = {
|
2016-04-29 09:39:26 +00:00
|
|
|
// signatures
|
|
|
|
SIGNATURES_SECTION_VOID_VOID,
|
2016-05-25 16:12:09 +00:00
|
|
|
ONE_EMPTY_FUNCTION,
|
2016-03-10 12:36:42 +00:00
|
|
|
SECTION(EXPORT_TABLE, 1 + 6),
|
|
|
|
1, // exports
|
|
|
|
FUNC_INDEX(0), // --
|
|
|
|
NO_NAME // --
|
2016-02-27 01:52:30 +00:00
|
|
|
};
|
|
|
|
|
2016-03-10 12:36:42 +00:00
|
|
|
for (int length = 33; length < sizeof(data); length++) {
|
2016-02-27 01:52:30 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + length);
|
|
|
|
EXPECT_FALSE(result.ok());
|
|
|
|
if (result.val) delete result.val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-09 22:50:36 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, FunctionSignatures_empty) {
|
2016-04-21 11:18:41 +00:00
|
|
|
static const byte data[] = {
|
|
|
|
SECTION(SIGNATURES, 1), 0, // --
|
|
|
|
SECTION(FUNCTION_SIGNATURES, 1), 0 // --
|
|
|
|
}; // --
|
2016-03-09 22:50:36 +00:00
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, FunctionSignatures_one) {
|
2016-04-21 11:18:41 +00:00
|
|
|
static const byte data[] = {
|
2016-04-29 09:39:26 +00:00
|
|
|
SIGNATURES_SECTION(1, SIG_ENTRY_v_v), // --
|
2016-04-21 11:18:41 +00:00
|
|
|
FUNCTION_SIGNATURES_SECTION(1, 0) // --
|
|
|
|
};
|
2016-03-09 22:50:36 +00:00
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, FunctionBodies_empty) {
|
2016-04-21 11:18:41 +00:00
|
|
|
static const byte data[] = {
|
|
|
|
EMPTY_SIGNATURES_SECTION, // --
|
|
|
|
EMPTY_FUNCTION_SIGNATURES_SECTION, // --
|
|
|
|
EMPTY_FUNCTION_BODIES_SECTION // --
|
|
|
|
};
|
2016-03-09 22:50:36 +00:00
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, FunctionBodies_one_empty) {
|
2016-03-10 12:36:42 +00:00
|
|
|
static const byte data[] = {
|
2016-04-29 09:39:26 +00:00
|
|
|
SIGNATURES_SECTION(1, SIG_ENTRY_v_v), // --
|
|
|
|
FUNCTION_SIGNATURES_SECTION(1, 0), // --
|
|
|
|
SECTION(FUNCTION_BODIES, 1 + SIZEOF_EMPTY_BODY), 1, EMPTY_BODY // --
|
2016-04-21 11:18:41 +00:00
|
|
|
};
|
2016-03-09 22:50:36 +00:00
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, FunctionBodies_one_nop) {
|
2016-03-10 12:36:42 +00:00
|
|
|
static const byte data[] = {
|
2016-04-29 09:39:26 +00:00
|
|
|
SIGNATURES_SECTION(1, SIG_ENTRY_v_v), // --
|
|
|
|
FUNCTION_SIGNATURES_SECTION(1, 0), // --
|
|
|
|
SECTION(FUNCTION_BODIES, 1 + SIZEOF_NOP_BODY), 1, NOP_BODY // --
|
2016-04-21 11:18:41 +00:00
|
|
|
};
|
2016-03-09 22:50:36 +00:00
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, FunctionBodies_count_mismatch1) {
|
2016-04-21 11:18:41 +00:00
|
|
|
static const byte data[] = {
|
2016-04-29 09:39:26 +00:00
|
|
|
SIGNATURES_SECTION(1, SIG_ENTRY_v_v), // --
|
|
|
|
FUNCTION_SIGNATURES_SECTION(2, 0, 0), // --
|
|
|
|
SECTION(FUNCTION_BODIES, 1 + SIZEOF_EMPTY_BODY), 1, // --
|
|
|
|
EMPTY_BODY // --
|
2016-04-21 11:18:41 +00:00
|
|
|
};
|
2016-03-09 22:50:36 +00:00
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, FunctionBodies_count_mismatch2) {
|
2016-04-21 11:18:41 +00:00
|
|
|
static const byte data[] = {
|
2016-04-29 09:39:26 +00:00
|
|
|
SIGNATURES_SECTION(1, SIG_ENTRY_v_v), // --
|
|
|
|
FUNCTION_SIGNATURES_SECTION(1, 0), // --
|
|
|
|
SECTION(FUNCTION_BODIES, 1 + 2 * SIZEOF_NOP_BODY), // --
|
|
|
|
2, // --
|
|
|
|
NOP_BODY, // --
|
|
|
|
NOP_BODY // --
|
2016-04-21 11:18:41 +00:00
|
|
|
};
|
2016-03-09 22:50:36 +00:00
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, Names_empty) {
|
|
|
|
static const byte data[] = {
|
|
|
|
EMPTY_SIGNATURES_SECTION, EMPTY_FUNCTION_SIGNATURES_SECTION,
|
|
|
|
EMPTY_FUNCTION_BODIES_SECTION, EMPTY_NAMES_SECTION};
|
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, Names_one_empty) {
|
|
|
|
static const byte data[] = {
|
2016-04-29 09:39:26 +00:00
|
|
|
SIGNATURES_SECTION(1, SIG_ENTRY_v_v), // --
|
2016-03-10 12:36:42 +00:00
|
|
|
FUNCTION_SIGNATURES_SECTION(1, 0), // --
|
2016-04-29 09:39:26 +00:00
|
|
|
SECTION(FUNCTION_BODIES, 1 + SIZEOF_EMPTY_BODY),
|
2016-03-10 12:36:42 +00:00
|
|
|
1,
|
|
|
|
EMPTY_BODY, // --
|
|
|
|
SECTION(NAMES, 1 + 5),
|
|
|
|
1,
|
|
|
|
FOO_STRING,
|
|
|
|
NO_LOCAL_NAMES // --
|
2016-03-09 22:50:36 +00:00
|
|
|
};
|
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, Names_two_empty) {
|
|
|
|
static const byte data[] = {
|
2016-04-29 09:39:26 +00:00
|
|
|
SIGNATURES_SECTION(1, SIG_ENTRY_v_v), // --
|
|
|
|
FUNCTION_SIGNATURES_SECTION(2, 0, 0), // --
|
|
|
|
SECTION(FUNCTION_BODIES, 1 + 2 * SIZEOF_EMPTY_BODY), // --
|
2016-03-10 12:36:42 +00:00
|
|
|
2,
|
|
|
|
EMPTY_BODY,
|
|
|
|
EMPTY_BODY, // --
|
|
|
|
SECTION(NAMES, 1 + 10),
|
|
|
|
2, // --
|
|
|
|
FOO_STRING,
|
|
|
|
NO_LOCAL_NAMES, // --
|
|
|
|
FOO_STRING,
|
|
|
|
NO_LOCAL_NAMES, // --
|
2016-03-09 22:50:36 +00:00
|
|
|
};
|
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
2015-12-11 12:26:16 +00:00
|
|
|
} // namespace wasm
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|