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"
|
2018-08-08 14:54:44 +00:00
|
|
|
#include "src/wasm/wasm-features.h"
|
2016-12-14 17:45:59 +00:00
|
|
|
#include "src/wasm/wasm-limits.h"
|
2015-12-11 12:26:16 +00:00
|
|
|
#include "src/wasm/wasm-opcodes.h"
|
2017-05-31 13:31:52 +00:00
|
|
|
#include "test/common/wasm/flag-utils.h"
|
2017-04-25 11:29:17 +00:00
|
|
|
#include "test/common/wasm/wasm-macro-gen.h"
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace wasm {
|
2017-09-28 17:55:52 +00:00
|
|
|
namespace module_decoder_unittest {
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
#define WASM_INIT_EXPR_I32V_1(val) WASM_I32V_1(val), kExprEnd
|
|
|
|
#define WASM_INIT_EXPR_I32V_2(val) WASM_I32V_2(val), kExprEnd
|
|
|
|
#define WASM_INIT_EXPR_I32V_3(val) WASM_I32V_3(val), kExprEnd
|
|
|
|
#define WASM_INIT_EXPR_I32V_4(val) WASM_I32V_4(val), kExprEnd
|
|
|
|
#define WASM_INIT_EXPR_I32V_5(val) WASM_I32V_5(val), kExprEnd
|
|
|
|
#define WASM_INIT_EXPR_F32(val) WASM_F32(val), kExprEnd
|
|
|
|
#define WASM_INIT_EXPR_I64(val) WASM_I64(val), kExprEnd
|
|
|
|
#define WASM_INIT_EXPR_F64(val) WASM_F64(val), kExprEnd
|
2018-04-05 10:49:26 +00:00
|
|
|
#define WASM_INIT_EXPR_ANYREF WASM_REF_NULL, kExprEnd
|
2016-09-27 20:46:10 +00:00
|
|
|
#define WASM_INIT_EXPR_GLOBAL(index) WASM_GET_GLOBAL(index), kExprEnd
|
|
|
|
|
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)
|
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
#define UNKNOWN_SECTION(size) 0, U32V_1(size + 5), 4, 'l', 'u', 'l', 'z'
|
2016-04-29 09:39:26 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
#define SECTION(name, size) k##name##SectionCode, U32V_1(size)
|
2016-04-29 09:39:26 +00:00
|
|
|
|
|
|
|
#define SIGNATURES_SECTION(count, ...) \
|
2016-09-27 20:46:10 +00:00
|
|
|
SECTION(Type, 1 + 3 * (count)), U32V_1(count), __VA_ARGS__
|
2016-04-29 09:39:26 +00:00
|
|
|
#define FUNCTION_SIGNATURES_SECTION(count, ...) \
|
2016-09-27 20:46:10 +00:00
|
|
|
SECTION(Function, 1 + (count)), U32V_1(count), __VA_ARGS__
|
2016-04-29 09:39:26 +00:00
|
|
|
|
|
|
|
#define FOO_STRING 3, 'f', 'o', 'o'
|
|
|
|
#define NO_LOCAL_NAMES 0
|
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
#define EMPTY_SIGNATURES_SECTION SECTION(Type, 1), 0
|
|
|
|
#define EMPTY_FUNCTION_SIGNATURES_SECTION SECTION(Function, 1), 0
|
|
|
|
#define EMPTY_FUNCTION_BODIES_SECTION SECTION(Code, 1), 0
|
2016-10-12 09:17:12 +00:00
|
|
|
#define SECTION_NAMES(size) SECTION(Unknown, size + 5), 4, 'n', 'a', 'm', 'e'
|
2017-08-01 20:56:39 +00:00
|
|
|
#define SECTION_EXCEPTIONS(size) SECTION(Exception, size)
|
2016-09-27 20:46:10 +00:00
|
|
|
#define EMPTY_NAMES_SECTION SECTION_NAMES(1), 0
|
2016-04-29 09:39:26 +00:00
|
|
|
|
2017-08-01 20:56:39 +00:00
|
|
|
#define FAIL_IF_NO_EXPERIMENTAL_EH(data) \
|
|
|
|
do { \
|
|
|
|
ModuleResult result = DecodeModule((data), (data) + sizeof((data))); \
|
|
|
|
EXPECT_FALSE(result.ok()); \
|
|
|
|
EXPECT_EQ(0u, result.val->exceptions.size()); \
|
2018-09-19 17:41:30 +00:00
|
|
|
} while (false)
|
2017-08-01 20:56:39 +00:00
|
|
|
|
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__
|
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
#define ONE_EMPTY_FUNCTION SECTION(Function, 1 + 1 * 1), 1, X1(0)
|
2016-05-25 16:12:09 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
#define TWO_EMPTY_FUNCTIONS SECTION(Function, 1 + 2 * 1), 2, X2(0)
|
2016-05-25 16:12:09 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
#define THREE_EMPTY_FUNCTIONS SECTION(Function, 1 + 3 * 1), 3, X3(0)
|
2016-05-25 16:12:09 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
#define FOUR_EMPTY_FUNCTIONS SECTION(Function, 1 + 4 * 1), 4, X4(0)
|
2016-05-25 16:12:09 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
#define ONE_EMPTY_BODY \
|
|
|
|
SECTION(Code, 1 + 1 * (1 + SIZEOF_EMPTY_BODY)) \
|
|
|
|
, 1, X1(SIZEOF_EMPTY_BODY, EMPTY_BODY)
|
2016-05-25 16:12:09 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
#define TWO_EMPTY_BODIES \
|
|
|
|
SECTION(Code, 1 + 2 * (1 + SIZEOF_EMPTY_BODY)) \
|
|
|
|
, 2, X2(SIZEOF_EMPTY_BODY, EMPTY_BODY)
|
2016-05-25 16:12:09 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
#define THREE_EMPTY_BODIES \
|
|
|
|
SECTION(Code, 1 + 3 * (1 + SIZEOF_EMPTY_BODY)) \
|
|
|
|
, 3, X3(SIZEOF_EMPTY_BODY, EMPTY_BODY)
|
2016-05-25 16:12:09 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
#define FOUR_EMPTY_BODIES \
|
|
|
|
SECTION(Code, 1 + 4 * (1 + SIZEOF_EMPTY_BODY)) \
|
|
|
|
, 4, X4(SIZEOF_EMPTY_BODY, EMPTY_BODY)
|
2016-05-25 16:12:09 +00:00
|
|
|
|
2016-04-29 09:39:26 +00:00
|
|
|
#define SIGNATURES_SECTION_VOID_VOID \
|
2016-09-27 20:46:10 +00:00
|
|
|
SECTION(Type, 1 + SIZEOF_SIG_ENTRY_v_v), 1, SIG_ENTRY_v_v
|
|
|
|
|
|
|
|
#define LINEAR_MEMORY_INDEX_0 0
|
2016-02-27 01:52:30 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
#define EXPECT_VERIFIES(data) \
|
|
|
|
do { \
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data)); \
|
|
|
|
EXPECT_TRUE(result.ok()); \
|
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()); \
|
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))
|
|
|
|
|
2018-10-16 13:28:20 +00:00
|
|
|
#define EXPECT_OFF_END_FAILURE(data, min) \
|
|
|
|
do { \
|
|
|
|
STATIC_ASSERT(min < arraysize(data)); \
|
|
|
|
for (size_t length = min; length < arraysize(data); length++) { \
|
|
|
|
EXPECT_FAILURE_LEN(data, length); \
|
|
|
|
} \
|
2016-02-28 00:37:11 +00:00
|
|
|
} while (false)
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2017-05-08 12:45:20 +00:00
|
|
|
#define EXPECT_OK(result) \
|
|
|
|
do { \
|
|
|
|
EXPECT_TRUE(result.ok()); \
|
|
|
|
if (!result.ok()) return; \
|
2016-04-21 11:18:41 +00:00
|
|
|
} 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;
|
|
|
|
}
|
|
|
|
|
2016-12-21 13:43:00 +00:00
|
|
|
struct ValueTypePair {
|
2015-12-11 12:26:16 +00:00
|
|
|
uint8_t code;
|
2016-12-21 13:43:00 +00:00
|
|
|
ValueType type;
|
2018-07-09 09:15:45 +00:00
|
|
|
} kValueTypes[] = {
|
|
|
|
{kLocalI32, kWasmI32}, // --
|
|
|
|
{kLocalI64, kWasmI64}, // --
|
|
|
|
{kLocalF32, kWasmF32}, // --
|
|
|
|
{kLocalF64, kWasmF64}, // --
|
|
|
|
{kLocalAnyFunc, kWasmAnyFunc}, // --
|
|
|
|
{kLocalAnyRef, kWasmAnyRef} // --
|
|
|
|
};
|
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 WasmModuleVerifyTest : public TestWithIsolateAndZone {
|
2016-02-28 00:37:11 +00:00
|
|
|
public:
|
2018-08-08 14:54:44 +00:00
|
|
|
WasmFeatures enabled_features_;
|
|
|
|
|
2016-02-28 00:37:11 +00:00
|
|
|
ModuleResult DecodeModule(const byte* module_start, const byte* module_end) {
|
2017-06-09 12:21:52 +00:00
|
|
|
// Add the wasm magic and version number automatically.
|
2016-02-28 00:37:11 +00:00
|
|
|
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);
|
2018-08-08 14:54:44 +00:00
|
|
|
ModuleResult result = DecodeWasmModule(
|
|
|
|
enabled_features_, temp, temp + total, false, kWasmOrigin,
|
|
|
|
isolate()->counters(), isolate()->allocator());
|
2016-02-28 00:37:11 +00:00
|
|
|
delete[] temp;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
ModuleResult DecodeModuleNoHeader(const byte* module_start,
|
|
|
|
const byte* module_end) {
|
2018-08-08 14:54:44 +00:00
|
|
|
return DecodeWasmModule(enabled_features_, module_start, module_end, false,
|
|
|
|
kWasmOrigin, isolate()->counters(),
|
|
|
|
isolate()->allocator());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
class EnableBoolScope {
|
|
|
|
public:
|
|
|
|
bool prev_;
|
|
|
|
bool* ptr_;
|
|
|
|
explicit EnableBoolScope(bool* ptr, bool val = true)
|
|
|
|
: prev_(*ptr), ptr_(ptr) {
|
|
|
|
*ptr = val;
|
2016-02-28 00:37:11 +00:00
|
|
|
}
|
2018-08-08 14:54:44 +00:00
|
|
|
~EnableBoolScope() { *ptr_ = prev_; }
|
2016-02-28 00:37:11 +00:00
|
|
|
};
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2018-08-08 14:54:44 +00:00
|
|
|
#define WASM_FEATURE_SCOPE(feat) \
|
|
|
|
EnableBoolScope feat##_scope(&this->enabled_features_.feat)
|
|
|
|
|
|
|
|
#define WASM_FEATURE_SCOPE_VAL(feat, val) \
|
|
|
|
EnableBoolScope feat##_scope(&this->enabled_features_.feat, val)
|
|
|
|
} // namespace
|
|
|
|
|
2016-02-28 00:37:11 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, WrongMagic) {
|
|
|
|
for (uint32_t x = 1; x; x <<= 1) {
|
2016-09-27 20:46:10 +00:00
|
|
|
const byte data[] = {U32_LE(kWasmMagic ^ x), U32_LE(kWasmVersion)};
|
2016-02-28 00:37:11 +00:00
|
|
|
ModuleResult result = DecodeModuleNoHeader(data, data + sizeof(data));
|
|
|
|
EXPECT_FALSE(result.ok());
|
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) {
|
2016-09-27 20:46:10 +00:00
|
|
|
const byte data[] = {U32_LE(kWasmMagic), U32_LE(kWasmVersion ^ x)};
|
2016-02-28 00:37:11 +00:00
|
|
|
ModuleResult result = DecodeModuleNoHeader(data, data + sizeof(data));
|
|
|
|
EXPECT_FALSE(result.ok());
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-28 00:37:11 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, DecodeEmpty) {
|
2018-09-13 14:55:18 +00:00
|
|
|
ModuleResult result = DecodeModule(nullptr, nullptr);
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_TRUE(result.ok());
|
2016-02-28 00:37:11 +00:00
|
|
|
}
|
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-09-27 20:46:10 +00:00
|
|
|
SECTION(Global, 6), // --
|
2015-12-11 12:26:16 +00:00
|
|
|
1,
|
2016-09-27 20:46:10 +00:00
|
|
|
kLocalI32, // local type
|
|
|
|
0, // immutable
|
|
|
|
WASM_INIT_EXPR_I32V_1(13) // init
|
2015-12-11 12:26:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
{
|
|
|
|
// Should decode to exactly one global.
|
2016-09-27 20:46:10 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
2016-04-21 11:18:41 +00:00
|
|
|
EXPECT_OK(result);
|
2016-11-11 11:55:30 +00:00
|
|
|
EXPECT_EQ(1u, result.val->globals.size());
|
|
|
|
EXPECT_EQ(0u, result.val->functions.size());
|
|
|
|
EXPECT_EQ(0u, 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-12-21 13:43:00 +00:00
|
|
|
EXPECT_EQ(kWasmI32, global->type);
|
2016-11-11 11:55:30 +00:00
|
|
|
EXPECT_EQ(0u, global->offset);
|
2016-09-27 22:09:36 +00:00
|
|
|
EXPECT_FALSE(global->mutability);
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_EQ(WasmInitExpr::kI32Const, global->init.kind);
|
|
|
|
EXPECT_EQ(13, global->init.val.i32_const);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2018-10-16 13:28:20 +00:00
|
|
|
EXPECT_OFF_END_FAILURE(data, 1);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2018-04-05 10:49:26 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, AnyRefGlobal) {
|
2018-08-08 14:54:44 +00:00
|
|
|
WASM_FEATURE_SCOPE(anyref);
|
2018-04-05 10:49:26 +00:00
|
|
|
static const byte data[] = {
|
|
|
|
SECTION(Global, 5), // --
|
|
|
|
1,
|
|
|
|
kLocalAnyRef, // local type
|
|
|
|
0, // immutable
|
|
|
|
WASM_INIT_EXPR_ANYREF // init
|
|
|
|
};
|
|
|
|
|
|
|
|
{
|
|
|
|
// Should decode to exactly one global.
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_OK(result);
|
|
|
|
EXPECT_EQ(1u, result.val->globals.size());
|
|
|
|
EXPECT_EQ(0u, result.val->functions.size());
|
|
|
|
EXPECT_EQ(0u, result.val->data_segments.size());
|
|
|
|
|
|
|
|
const WasmGlobal* global = &result.val->globals.back();
|
|
|
|
|
|
|
|
EXPECT_EQ(kWasmAnyRef, global->type);
|
|
|
|
EXPECT_FALSE(global->mutability);
|
|
|
|
EXPECT_EQ(WasmInitExpr::kAnyRefConst, global->init.kind);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, AnyRefGlobalWithGlobalInit) {
|
2018-08-08 14:54:44 +00:00
|
|
|
WASM_FEATURE_SCOPE(anyref);
|
2018-04-05 10:49:26 +00:00
|
|
|
static const byte data[] = {
|
|
|
|
SECTION(Import, 8), // section header
|
|
|
|
1, // number of imports
|
|
|
|
NAME_LENGTH(1), // --
|
|
|
|
'm', // module name
|
|
|
|
NAME_LENGTH(1), // --
|
|
|
|
'f', // global name
|
|
|
|
kExternalGlobal, // import kind
|
|
|
|
kLocalAnyRef, // type
|
|
|
|
0, // mutability
|
|
|
|
SECTION(Global, 6), // --
|
|
|
|
1,
|
|
|
|
kLocalAnyRef, // local type
|
|
|
|
0, // immutable
|
|
|
|
WASM_INIT_EXPR_GLOBAL(0),
|
|
|
|
};
|
|
|
|
|
|
|
|
{
|
|
|
|
// Should decode to exactly one global.
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_OK(result);
|
|
|
|
EXPECT_EQ(2u, result.val->globals.size());
|
|
|
|
EXPECT_EQ(0u, result.val->functions.size());
|
|
|
|
EXPECT_EQ(0u, result.val->data_segments.size());
|
|
|
|
|
|
|
|
const WasmGlobal* global = &result.val->globals.back();
|
|
|
|
|
|
|
|
EXPECT_EQ(kWasmAnyRef, global->type);
|
|
|
|
EXPECT_FALSE(global->mutability);
|
|
|
|
EXPECT_EQ(WasmInitExpr::kGlobalIndex, global->init.kind);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-07 09:35:52 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, Global_invalid_type) {
|
|
|
|
static const byte data[] = {
|
2016-09-27 20:46:10 +00:00
|
|
|
SECTION(Global, 6), // --
|
2016-06-07 09:35:52 +00:00
|
|
|
1,
|
2016-09-27 20:46:10 +00:00
|
|
|
64, // invalid memory type
|
|
|
|
1, // mutable
|
|
|
|
WASM_INIT_EXPR_I32V_1(33), // init
|
2016-06-07 09:35:52 +00:00
|
|
|
};
|
|
|
|
|
2018-10-16 13:19:03 +00:00
|
|
|
EXPECT_FAILURE(data);
|
2016-09-14 15:44:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, Global_invalid_type2) {
|
|
|
|
static const byte data[] = {
|
2016-09-27 20:46:10 +00:00
|
|
|
SECTION(Global, 6), // --
|
2016-09-14 15:44:15 +00:00
|
|
|
1,
|
2016-09-27 20:46:10 +00:00
|
|
|
kLocalVoid, // invalid memory type
|
|
|
|
1, // mutable
|
|
|
|
WASM_INIT_EXPR_I32V_1(33), // init
|
2016-09-14 15:44:15 +00:00
|
|
|
};
|
|
|
|
|
2018-10-16 13:19:03 +00:00
|
|
|
EXPECT_FAILURE(data);
|
2016-06-07 09:35:52 +00:00
|
|
|
}
|
|
|
|
|
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-09-27 20:46:10 +00:00
|
|
|
SECTION(Global, 1), // --
|
|
|
|
0, // declare 0 globals
|
2015-12-11 12:26:16 +00:00
|
|
|
};
|
2016-09-27 20:46:10 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
2016-04-21 11:18:41 +00:00
|
|
|
EXPECT_OK(result);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-11-08 14:18:07 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ExportMutableGlobal) {
|
2018-08-08 14:54:44 +00:00
|
|
|
WASM_FEATURE_SCOPE(mut_global);
|
2016-11-08 14:18:07 +00:00
|
|
|
{
|
|
|
|
static const byte data[] = {
|
|
|
|
SECTION(Global, 6), // --
|
|
|
|
1,
|
|
|
|
kLocalI32, // local type
|
|
|
|
0, // immutable
|
|
|
|
WASM_INIT_EXPR_I32V_1(13), // init
|
|
|
|
SECTION(Export, 8), // --
|
|
|
|
1, // Export count
|
|
|
|
4, // name length
|
|
|
|
'n', // --
|
|
|
|
'a', // --
|
|
|
|
'm', // --
|
|
|
|
'e', // --
|
|
|
|
kExternalGlobal, // global
|
|
|
|
0, // global index
|
|
|
|
};
|
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
static const byte data[] = {
|
|
|
|
SECTION(Global, 6), // --
|
|
|
|
1, // --
|
|
|
|
kLocalI32, // local type
|
|
|
|
1, // mutable
|
|
|
|
WASM_INIT_EXPR_I32V_1(13), // init
|
|
|
|
SECTION(Export, 8), // --
|
|
|
|
1, // Export count
|
|
|
|
4, // name length
|
|
|
|
'n', // --
|
|
|
|
'a', // --
|
|
|
|
'm', // --
|
|
|
|
'e', // --
|
|
|
|
kExternalGlobal, // global
|
|
|
|
0, // global index
|
|
|
|
};
|
2018-06-12 22:23:35 +00:00
|
|
|
EXPECT_VERIFIES(data);
|
2016-11-08 14:18:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
2017-12-02 00:30:37 +00:00
|
|
|
uint32_t out = val & 0x7F;
|
2015-12-11 12:26:16 +00:00
|
|
|
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-09-27 20:46:10 +00:00
|
|
|
kLocalF32, // memory type
|
|
|
|
0, // immutable
|
|
|
|
WASM_INIT_EXPR_F32(7.7), // init
|
2015-12-11 12:26:16 +00:00
|
|
|
};
|
2016-02-28 00:37:11 +00:00
|
|
|
|
2016-12-14 17:45:59 +00:00
|
|
|
for (uint32_t i = 0; i < kV8MaxWasmGlobals; 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);
|
2016-09-27 20:46:10 +00:00
|
|
|
const byte globals[] = {kGlobalSectionCode, 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-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, GlobalWithInvalidMemoryType) {
|
2016-09-27 20:46:10 +00:00
|
|
|
static const byte data[] = {SECTION(Global, 7),
|
|
|
|
33, // memory type
|
|
|
|
0, // exported
|
|
|
|
WASM_INIT_EXPR_I32V_1(1)};
|
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-09-27 20:46:10 +00:00
|
|
|
SECTION(Global, 21),
|
2015-12-11 12:26:16 +00:00
|
|
|
2,
|
2016-07-21 12:34:28 +00:00
|
|
|
kLocalF32, // type
|
2016-09-27 20:46:10 +00:00
|
|
|
0, // immutable
|
|
|
|
WASM_INIT_EXPR_F32(22.0),
|
2016-07-21 12:34:28 +00:00
|
|
|
kLocalF64, // type
|
2016-09-27 20:46:10 +00:00
|
|
|
1, // mutable
|
|
|
|
WASM_INIT_EXPR_F64(23.0),
|
2015-12-11 12:26:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
{
|
|
|
|
// Should decode to exactly two globals.
|
2016-09-27 20:46:10 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
2016-04-21 11:18:41 +00:00
|
|
|
EXPECT_OK(result);
|
2016-11-11 11:55:30 +00:00
|
|
|
EXPECT_EQ(2u, result.val->globals.size());
|
|
|
|
EXPECT_EQ(0u, result.val->functions.size());
|
|
|
|
EXPECT_EQ(0u, 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];
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-12-21 13:43:00 +00:00
|
|
|
EXPECT_EQ(kWasmF32, g0->type);
|
2016-11-11 11:55:30 +00:00
|
|
|
EXPECT_EQ(0u, g0->offset);
|
2016-09-27 22:09:36 +00:00
|
|
|
EXPECT_FALSE(g0->mutability);
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_EQ(WasmInitExpr::kF32Const, g0->init.kind);
|
|
|
|
|
|
|
|
const WasmGlobal* g1 = &result.val->globals[1];
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-12-21 13:43:00 +00:00
|
|
|
EXPECT_EQ(kWasmF64, g1->type);
|
2016-11-11 11:55:30 +00:00
|
|
|
EXPECT_EQ(8u, g1->offset);
|
2016-09-27 22:09:36 +00:00
|
|
|
EXPECT_TRUE(g1->mutability);
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_EQ(WasmInitExpr::kF64Const, g1->init.kind);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2018-10-16 13:28:20 +00:00
|
|
|
EXPECT_OFF_END_FAILURE(data, 1);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2017-07-10 19:15:28 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ZeroExceptions) {
|
|
|
|
static const byte data[] = {
|
|
|
|
SECTION_EXCEPTIONS(1), 0,
|
|
|
|
};
|
2017-08-01 20:56:39 +00:00
|
|
|
FAIL_IF_NO_EXPERIMENTAL_EH(data);
|
2017-07-10 19:15:28 +00:00
|
|
|
|
2018-08-08 14:54:44 +00:00
|
|
|
WASM_FEATURE_SCOPE(eh);
|
2017-08-01 20:56:39 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_OK(result);
|
|
|
|
EXPECT_EQ(0u, result.val->exceptions.size());
|
2017-07-10 19:15:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, OneI32Exception) {
|
2018-10-15 14:31:16 +00:00
|
|
|
static const byte data[] = {SECTION(Type, 1 + SIZEOF_SIG_ENTRY_v_x),
|
|
|
|
1,
|
|
|
|
SIG_ENTRY_v_x(kLocalI32), // sig#0 (i32)
|
|
|
|
SECTION_EXCEPTIONS(2), // section header
|
|
|
|
1, // # of exceptions
|
|
|
|
IMPORT_SIG_INDEX(0)}; // except[0] (sig#0)
|
2017-08-01 20:56:39 +00:00
|
|
|
FAIL_IF_NO_EXPERIMENTAL_EH(data);
|
2017-07-10 19:15:28 +00:00
|
|
|
|
2018-08-08 14:54:44 +00:00
|
|
|
WASM_FEATURE_SCOPE(eh);
|
2017-08-01 20:56:39 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_OK(result);
|
|
|
|
EXPECT_EQ(1u, result.val->exceptions.size());
|
2017-07-10 19:15:28 +00:00
|
|
|
|
2017-08-01 20:56:39 +00:00
|
|
|
const WasmException& e0 = result.val->exceptions.front();
|
|
|
|
EXPECT_EQ(1u, e0.sig->parameter_count());
|
2018-05-07 11:02:21 +00:00
|
|
|
EXPECT_EQ(kWasmI32, e0.sig->GetParam(0));
|
2017-07-10 19:15:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, TwoExceptions) {
|
2018-10-15 14:31:16 +00:00
|
|
|
constexpr int SIZEOF_SIGs = SIZEOF_SIG_ENTRY_v_x + SIZEOF_SIG_ENTRY_v_xx;
|
|
|
|
static const byte data[] = {SECTION(Type, 1 + SIZEOF_SIGs), 2,
|
|
|
|
// sig#0 (i32)
|
|
|
|
SIG_ENTRY_v_x(kLocalI32),
|
|
|
|
// sig#1 (f32, i64)
|
|
|
|
SIG_ENTRY_v_xx(kLocalF32, kLocalI64),
|
|
|
|
SECTION_EXCEPTIONS(3), 2,
|
|
|
|
// except[0] (sig#1)
|
|
|
|
IMPORT_SIG_INDEX(1),
|
|
|
|
// except[1] (sig#0)
|
|
|
|
IMPORT_SIG_INDEX(0)};
|
2017-08-01 20:56:39 +00:00
|
|
|
FAIL_IF_NO_EXPERIMENTAL_EH(data);
|
|
|
|
|
2018-08-08 14:54:44 +00:00
|
|
|
WASM_FEATURE_SCOPE(eh);
|
2017-08-01 20:56:39 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_OK(result);
|
|
|
|
EXPECT_EQ(2u, result.val->exceptions.size());
|
|
|
|
const WasmException& e0 = result.val->exceptions.front();
|
|
|
|
EXPECT_EQ(2u, e0.sig->parameter_count());
|
2018-05-07 11:02:21 +00:00
|
|
|
EXPECT_EQ(kWasmF32, e0.sig->GetParam(0));
|
|
|
|
EXPECT_EQ(kWasmI64, e0.sig->GetParam(1));
|
2017-08-01 20:56:39 +00:00
|
|
|
const WasmException& e1 = result.val->exceptions.back();
|
2018-05-07 11:02:21 +00:00
|
|
|
EXPECT_EQ(kWasmI32, e1.sig->GetParam(0));
|
2017-07-10 19:15:28 +00:00
|
|
|
}
|
|
|
|
|
2018-10-15 14:31:16 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, Exception_invalid_sig_index) {
|
|
|
|
static const byte data[] = {SIGNATURES_SECTION_VOID_VOID,
|
|
|
|
SECTION_EXCEPTIONS(2), 1,
|
|
|
|
// except[0] (sig#23 [out-of-bounds])
|
|
|
|
IMPORT_SIG_INDEX(23)};
|
|
|
|
FAIL_IF_NO_EXPERIMENTAL_EH(data);
|
|
|
|
|
|
|
|
// Should fail decoding exception section.
|
|
|
|
WASM_FEATURE_SCOPE(eh);
|
2018-10-16 13:19:03 +00:00
|
|
|
EXPECT_FAILURE(data);
|
2018-10-15 14:31:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, Exception_invalid_sig_return) {
|
|
|
|
static const byte data[] = {SECTION(Type, 1 + SIZEOF_SIG_ENTRY_x_x), 1,
|
|
|
|
SIG_ENTRY_i_i, SECTION_EXCEPTIONS(2), 1,
|
|
|
|
// except[0] (sig#0 [invalid-return-type])
|
|
|
|
IMPORT_SIG_INDEX(0)};
|
2017-08-01 20:56:39 +00:00
|
|
|
FAIL_IF_NO_EXPERIMENTAL_EH(data);
|
2017-07-10 19:15:28 +00:00
|
|
|
|
2017-08-01 20:56:39 +00:00
|
|
|
// Should fail decoding exception section.
|
2018-08-08 14:54:44 +00:00
|
|
|
WASM_FEATURE_SCOPE(eh);
|
2018-10-16 13:19:03 +00:00
|
|
|
EXPECT_FAILURE(data);
|
2017-07-10 19:15:28 +00:00
|
|
|
}
|
|
|
|
|
2018-09-06 08:14:22 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ExceptionSectionCorrectPlacement) {
|
|
|
|
static const byte data[] = {SECTION(Import, 1), 0, SECTION_EXCEPTIONS(1), 0,
|
|
|
|
SECTION(Export, 1), 0};
|
2018-09-04 13:56:54 +00:00
|
|
|
FAIL_IF_NO_EXPERIMENTAL_EH(data);
|
|
|
|
|
|
|
|
WASM_FEATURE_SCOPE(eh);
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_OK(result);
|
|
|
|
}
|
|
|
|
|
2018-09-06 08:14:22 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ExceptionSectionAfterExport) {
|
|
|
|
static const byte data[] = {SECTION(Export, 1), 0, SECTION_EXCEPTIONS(1), 0};
|
|
|
|
FAIL_IF_NO_EXPERIMENTAL_EH(data);
|
|
|
|
|
|
|
|
WASM_FEATURE_SCOPE(eh);
|
2018-10-16 13:19:03 +00:00
|
|
|
EXPECT_FAILURE(data);
|
2018-09-06 08:14:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, ExceptionSectionBeforeImport) {
|
|
|
|
static const byte data[] = {SECTION_EXCEPTIONS(1), 0, SECTION(Import, 1), 0};
|
2018-09-04 13:56:54 +00:00
|
|
|
FAIL_IF_NO_EXPERIMENTAL_EH(data);
|
|
|
|
|
|
|
|
WASM_FEATURE_SCOPE(eh);
|
2018-10-16 13:19:03 +00:00
|
|
|
EXPECT_FAILURE(data);
|
2018-09-04 13:56:54 +00:00
|
|
|
}
|
|
|
|
|
2018-09-11 08:38:24 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ExceptionImport) {
|
2018-10-15 14:31:16 +00:00
|
|
|
static const byte data[] = {SIGNATURES_SECTION_VOID_VOID,
|
|
|
|
SECTION(Import, 8), // section header
|
|
|
|
1, // number of imports
|
|
|
|
NAME_LENGTH(1), // --
|
|
|
|
'm', // module name
|
|
|
|
NAME_LENGTH(2), // --
|
|
|
|
'e', // exception name
|
|
|
|
'x', // --
|
|
|
|
kExternalException, // import kind
|
|
|
|
IMPORT_SIG_INDEX(0)}; // except[0] (sig#0)
|
2018-09-11 08:38:24 +00:00
|
|
|
FAIL_IF_NO_EXPERIMENTAL_EH(data);
|
|
|
|
|
|
|
|
WASM_FEATURE_SCOPE(eh);
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_OK(result);
|
|
|
|
EXPECT_EQ(1u, result.val->exceptions.size());
|
|
|
|
EXPECT_EQ(1u, result.val->import_table.size());
|
|
|
|
}
|
|
|
|
|
2018-09-06 08:14:22 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ExceptionExport) {
|
2018-10-15 14:31:16 +00:00
|
|
|
static const byte data[] = {SIGNATURES_SECTION_VOID_VOID,
|
|
|
|
SECTION_EXCEPTIONS(2),
|
|
|
|
1,
|
|
|
|
IMPORT_SIG_INDEX(0), // except[0] (sig#0)
|
|
|
|
SECTION(Export, 4), // section header
|
|
|
|
1, // number of exports
|
|
|
|
NO_NAME, // --
|
|
|
|
kExternalException, // --
|
2018-09-06 08:14:22 +00:00
|
|
|
EXCEPTION_INDEX(0)};
|
|
|
|
FAIL_IF_NO_EXPERIMENTAL_EH(data);
|
|
|
|
|
|
|
|
WASM_FEATURE_SCOPE(eh);
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_OK(result);
|
|
|
|
EXPECT_EQ(1u, result.val->exceptions.size());
|
|
|
|
EXPECT_EQ(1u, result.val->export_table.size());
|
|
|
|
}
|
|
|
|
|
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-09-27 20:46:10 +00:00
|
|
|
static const byte data[] = {SECTION(Type, 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-09-27 20:46:10 +00:00
|
|
|
SECTION(Type, 1 + SIZEOF_SIG_ENTRY_v_v + SIZEOF_SIG_ENTRY_x_x +
|
|
|
|
SIZEOF_SIG_ENTRY_x_xx), // --
|
2016-04-29 09:39:26 +00:00
|
|
|
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
|
|
|
};
|
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
2016-04-21 11:18:41 +00:00
|
|
|
EXPECT_OK(result);
|
2016-11-11 11:55:30 +00:00
|
|
|
EXPECT_EQ(3u, result.val->signatures.size());
|
2016-02-28 19:04:10 +00:00
|
|
|
if (result.val->signatures.size() == 3) {
|
2016-11-11 11:55:30 +00:00
|
|
|
EXPECT_EQ(0u, result.val->signatures[0]->return_count());
|
|
|
|
EXPECT_EQ(1u, result.val->signatures[1]->return_count());
|
|
|
|
EXPECT_EQ(1u, result.val->signatures[2]->return_count());
|
2016-02-28 19:04:10 +00:00
|
|
|
|
2016-11-11 11:55:30 +00:00
|
|
|
EXPECT_EQ(0u, result.val->signatures[0]->parameter_count());
|
|
|
|
EXPECT_EQ(1u, result.val->signatures[1]->parameter_count());
|
|
|
|
EXPECT_EQ(2u, result.val->signatures[2]->parameter_count());
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2018-10-16 13:28:20 +00:00
|
|
|
EXPECT_OFF_END_FAILURE(data, 1);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-11-09 15:52:17 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, DataSegmentWithImmutableImportedGlobal) {
|
|
|
|
// Import 2 globals so that we can initialize data with a global index != 0.
|
|
|
|
const byte data[] = {
|
|
|
|
SECTION(Import, 15), // section header
|
|
|
|
2, // number of imports
|
|
|
|
NAME_LENGTH(1), // --
|
|
|
|
'm', // module name
|
|
|
|
NAME_LENGTH(1), // --
|
|
|
|
'f', // global name
|
|
|
|
kExternalGlobal, // import kind
|
|
|
|
kLocalI32, // type
|
|
|
|
0, // mutability
|
|
|
|
NAME_LENGTH(1), // --
|
|
|
|
'n', // module name
|
|
|
|
NAME_LENGTH(1), // --
|
|
|
|
'g', // global name
|
|
|
|
kExternalGlobal, // import kind
|
|
|
|
kLocalI32, // type
|
|
|
|
0, // mutability
|
|
|
|
SECTION(Memory, 4),
|
|
|
|
ENTRY_COUNT(1),
|
2017-10-13 07:30:13 +00:00
|
|
|
kHasMaximumFlag,
|
2016-11-09 15:52:17 +00:00
|
|
|
28,
|
|
|
|
28,
|
|
|
|
SECTION(Data, 9),
|
|
|
|
ENTRY_COUNT(1),
|
|
|
|
LINEAR_MEMORY_INDEX_0,
|
|
|
|
WASM_INIT_EXPR_GLOBAL(1), // dest addr
|
|
|
|
U32V_1(3), // source size
|
|
|
|
'a',
|
|
|
|
'b',
|
|
|
|
'c' // data bytes
|
|
|
|
};
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_OK(result);
|
|
|
|
WasmInitExpr expr = result.val->data_segments.back().dest_addr;
|
|
|
|
EXPECT_EQ(WasmInitExpr::kGlobalIndex, expr.kind);
|
2016-11-11 11:55:30 +00:00
|
|
|
EXPECT_EQ(1u, expr.val.global_index);
|
2016-11-09 15:52:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, DataSegmentWithMutableImportedGlobal) {
|
|
|
|
// Only an immutable imported global can be used as an init_expr.
|
|
|
|
const byte data[] = {
|
|
|
|
SECTION(Import, 8), // section header
|
|
|
|
1, // number of imports
|
|
|
|
NAME_LENGTH(1), // --
|
|
|
|
'm', // module name
|
|
|
|
NAME_LENGTH(1), // --
|
|
|
|
'f', // global name
|
|
|
|
kExternalGlobal, // import kind
|
|
|
|
kLocalI32, // type
|
|
|
|
1, // mutability
|
|
|
|
SECTION(Memory, 4),
|
|
|
|
ENTRY_COUNT(1),
|
2017-10-13 07:30:13 +00:00
|
|
|
kHasMaximumFlag,
|
2016-11-09 15:52:17 +00:00
|
|
|
28,
|
|
|
|
28,
|
|
|
|
SECTION(Data, 9),
|
|
|
|
ENTRY_COUNT(1),
|
|
|
|
LINEAR_MEMORY_INDEX_0,
|
|
|
|
WASM_INIT_EXPR_GLOBAL(0), // dest addr
|
|
|
|
U32V_1(3), // source size
|
|
|
|
'a',
|
|
|
|
'b',
|
|
|
|
'c' // data bytes
|
|
|
|
};
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
TEST_F(WasmModuleVerifyTest, DataSegmentWithImmutableGlobal) {
|
|
|
|
// Only an immutable imported global can be used as an init_expr.
|
|
|
|
const byte data[] = {
|
|
|
|
SECTION(Memory, 4),
|
|
|
|
ENTRY_COUNT(1),
|
2017-10-13 07:30:13 +00:00
|
|
|
kHasMaximumFlag,
|
2016-11-09 15:52:17 +00:00
|
|
|
28,
|
|
|
|
28,
|
|
|
|
SECTION(Global, 8), // --
|
|
|
|
1,
|
|
|
|
kLocalI32, // local type
|
|
|
|
0, // immutable
|
2017-12-02 00:30:37 +00:00
|
|
|
WASM_INIT_EXPR_I32V_3(0x9BBAA), // init
|
2016-11-09 15:52:17 +00:00
|
|
|
SECTION(Data, 9),
|
|
|
|
ENTRY_COUNT(1),
|
|
|
|
LINEAR_MEMORY_INDEX_0,
|
|
|
|
WASM_INIT_EXPR_GLOBAL(0), // dest addr
|
|
|
|
U32V_1(3), // source size
|
|
|
|
'a',
|
|
|
|
'b',
|
|
|
|
'c' // data bytes
|
|
|
|
};
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
2015-12-11 12:26:16 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, OneDataSegment) {
|
2016-09-27 20:46:10 +00:00
|
|
|
const byte kDataSegmentSourceOffset = 24;
|
2015-12-11 12:26:16 +00:00
|
|
|
const byte data[] = {
|
2016-09-27 20:46:10 +00:00
|
|
|
SECTION(Memory, 4),
|
|
|
|
ENTRY_COUNT(1),
|
2017-10-13 07:30:13 +00:00
|
|
|
kHasMaximumFlag,
|
2016-03-10 12:36:42 +00:00
|
|
|
28,
|
|
|
|
28,
|
2016-09-27 20:46:10 +00:00
|
|
|
SECTION(Data, 11),
|
|
|
|
ENTRY_COUNT(1),
|
|
|
|
LINEAR_MEMORY_INDEX_0,
|
2017-12-02 00:30:37 +00:00
|
|
|
WASM_INIT_EXPR_I32V_3(0x9BBAA), // dest addr
|
2016-09-27 20:46:10 +00:00
|
|
|
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);
|
2016-09-27 20:46:10 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
2016-04-21 11:18:41 +00:00
|
|
|
EXPECT_OK(result);
|
2016-11-11 11:55:30 +00:00
|
|
|
EXPECT_EQ(0u, result.val->globals.size());
|
|
|
|
EXPECT_EQ(0u, result.val->functions.size());
|
|
|
|
EXPECT_EQ(1u, 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
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_EQ(WasmInitExpr::kI32Const, segment->dest_addr.kind);
|
2017-12-02 00:30:37 +00:00
|
|
|
EXPECT_EQ(0x9BBAA, segment->dest_addr.val.i32_const);
|
2017-06-12 11:59:14 +00:00
|
|
|
EXPECT_EQ(kDataSegmentSourceOffset, segment->source.offset());
|
|
|
|
EXPECT_EQ(3u, segment->source.length());
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2018-10-16 13:28:20 +00:00
|
|
|
EXPECT_OFF_END_FAILURE(data, 14);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, TwoDataSegments) {
|
2016-09-27 20:46:10 +00:00
|
|
|
const byte kDataSegment0SourceOffset = 24;
|
|
|
|
const byte kDataSegment1SourceOffset = kDataSegment0SourceOffset + 11;
|
2016-03-09 19:43:02 +00:00
|
|
|
|
2015-12-11 12:26:16 +00:00
|
|
|
const byte data[] = {
|
2016-09-27 20:46:10 +00:00
|
|
|
SECTION(Memory, 4),
|
|
|
|
ENTRY_COUNT(1),
|
2017-10-13 07:30:13 +00:00
|
|
|
kHasMaximumFlag,
|
2016-03-10 12:36:42 +00:00
|
|
|
28,
|
|
|
|
28,
|
2016-09-27 20:46:10 +00:00
|
|
|
SECTION(Data, 29),
|
|
|
|
ENTRY_COUNT(2), // segment count
|
|
|
|
LINEAR_MEMORY_INDEX_0,
|
2017-12-02 00:30:37 +00:00
|
|
|
WASM_INIT_EXPR_I32V_3(0x7FFEE), // #0: dest addr
|
2016-09-27 20:46:10 +00:00
|
|
|
U32V_1(4), // source size
|
2016-03-10 12:36:42 +00:00
|
|
|
1,
|
|
|
|
2,
|
|
|
|
3,
|
2016-09-27 20:46:10 +00:00
|
|
|
4, // data bytes
|
|
|
|
LINEAR_MEMORY_INDEX_0,
|
2017-12-02 00:30:37 +00:00
|
|
|
WASM_INIT_EXPR_I32V_3(0x6DDCC), // #1: dest addr
|
2016-09-27 20:46:10 +00:00
|
|
|
U32V_1(10), // source size
|
2016-03-10 12:36:42 +00:00
|
|
|
1,
|
|
|
|
2,
|
|
|
|
3,
|
|
|
|
4,
|
|
|
|
5,
|
|
|
|
6,
|
|
|
|
7,
|
|
|
|
8,
|
|
|
|
9,
|
|
|
|
10 // data bytes
|
2015-12-11 12:26:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
{
|
2016-09-27 20:46:10 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
2016-04-21 11:18:41 +00:00
|
|
|
EXPECT_OK(result);
|
2016-11-11 11:55:30 +00:00
|
|
|
EXPECT_EQ(0u, result.val->globals.size());
|
|
|
|
EXPECT_EQ(0u, result.val->functions.size());
|
|
|
|
EXPECT_EQ(2u, 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
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_EQ(WasmInitExpr::kI32Const, s0->dest_addr.kind);
|
2017-12-02 00:30:37 +00:00
|
|
|
EXPECT_EQ(0x7FFEE, s0->dest_addr.val.i32_const);
|
2017-06-12 11:59:14 +00:00
|
|
|
EXPECT_EQ(kDataSegment0SourceOffset, s0->source.offset());
|
|
|
|
EXPECT_EQ(4u, s0->source.length());
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_EQ(WasmInitExpr::kI32Const, s1->dest_addr.kind);
|
2017-12-02 00:30:37 +00:00
|
|
|
EXPECT_EQ(0x6DDCC, s1->dest_addr.val.i32_const);
|
2017-06-12 11:59:14 +00:00
|
|
|
EXPECT_EQ(kDataSegment1SourceOffset, s1->source.offset());
|
|
|
|
EXPECT_EQ(10u, s1->source.length());
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2018-10-16 13:28:20 +00:00
|
|
|
EXPECT_OFF_END_FAILURE(data, 14);
|
2016-09-27 20:46:10 +00:00
|
|
|
}
|
|
|
|
|
2016-11-09 10:37:06 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, DataWithoutMemory) {
|
|
|
|
const byte data[] = {
|
|
|
|
SECTION(Data, 11),
|
|
|
|
ENTRY_COUNT(1),
|
|
|
|
LINEAR_MEMORY_INDEX_0,
|
2017-12-02 00:30:37 +00:00
|
|
|
WASM_INIT_EXPR_I32V_3(0x9BBAA), // dest addr
|
2016-11-09 10:37:06 +00:00
|
|
|
U32V_1(3), // source size
|
|
|
|
'a',
|
|
|
|
'b',
|
|
|
|
'c' // data bytes
|
|
|
|
};
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
2016-11-07 12:25:49 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, MaxMaximumMemorySize) {
|
|
|
|
{
|
|
|
|
const byte data[] = {
|
2017-10-13 07:30:13 +00:00
|
|
|
SECTION(Memory, 6), ENTRY_COUNT(1), kHasMaximumFlag, 0, U32V_3(65536),
|
2016-11-07 12:25:49 +00:00
|
|
|
};
|
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
const byte data[] = {
|
2017-10-13 07:30:13 +00:00
|
|
|
SECTION(Memory, 6), ENTRY_COUNT(1), kHasMaximumFlag, 0, U32V_3(65537),
|
2016-11-07 12:25:49 +00:00
|
|
|
};
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, DataSegment_wrong_init_type) {
|
|
|
|
const byte data[] = {
|
|
|
|
SECTION(Memory, 4),
|
|
|
|
ENTRY_COUNT(1),
|
2017-10-13 07:30:13 +00:00
|
|
|
kHasMaximumFlag,
|
2016-09-27 20:46:10 +00:00
|
|
|
28,
|
|
|
|
28,
|
|
|
|
SECTION(Data, 11),
|
|
|
|
ENTRY_COUNT(1),
|
|
|
|
LINEAR_MEMORY_INDEX_0,
|
|
|
|
WASM_INIT_EXPR_F64(9.9), // dest addr
|
|
|
|
U32V_1(3), // source size
|
|
|
|
'a',
|
|
|
|
'b',
|
|
|
|
'c' // data bytes
|
|
|
|
};
|
|
|
|
|
|
|
|
EXPECT_FAILURE(data);
|
2016-09-23 15:56:42 +00:00
|
|
|
}
|
|
|
|
|
2017-08-08 14:09:39 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, DataSegmentEndOverflow) {
|
|
|
|
const byte data[] = {
|
|
|
|
SECTION(Memory, 4), // memory section
|
2017-10-13 07:30:13 +00:00
|
|
|
ENTRY_COUNT(1), kHasMaximumFlag, 28, 28,
|
2017-08-08 14:09:39 +00:00
|
|
|
SECTION(Data, 10), // data section
|
|
|
|
ENTRY_COUNT(1), // one entry
|
|
|
|
LINEAR_MEMORY_INDEX_0, // mem index
|
|
|
|
WASM_INIT_EXPR_I32V_1(0), // offset
|
2017-12-02 00:30:37 +00:00
|
|
|
U32V_5(0xFFFFFFFF) // size
|
2017-08-08 14:09:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
2016-09-23 17:58:07 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, OneIndirectFunction) {
|
2016-09-23 15:56:42 +00:00
|
|
|
static const byte data[] = {
|
2016-09-27 20:46:10 +00:00
|
|
|
// sig#0 ---------------------------------------------------------------
|
2016-09-23 15:56:42 +00:00
|
|
|
SIGNATURES_SECTION_VOID_VOID,
|
2016-09-27 20:46:10 +00:00
|
|
|
// funcs ---------------------------------------------------------------
|
2016-09-23 15:56:42 +00:00
|
|
|
ONE_EMPTY_FUNCTION,
|
2016-09-27 20:46:10 +00:00
|
|
|
// table declaration ---------------------------------------------------
|
2018-07-10 12:14:06 +00:00
|
|
|
SECTION(Table, 4), ENTRY_COUNT(1), kLocalAnyFunc, 0, 1};
|
2016-09-23 15:56:42 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_OK(result);
|
|
|
|
if (result.ok()) {
|
2016-11-11 11:55:30 +00:00
|
|
|
EXPECT_EQ(1u, result.val->signatures.size());
|
|
|
|
EXPECT_EQ(1u, result.val->functions.size());
|
2018-07-10 12:14:06 +00:00
|
|
|
EXPECT_EQ(1u, result.val->tables.size());
|
|
|
|
EXPECT_EQ(1u, result.val->tables[0].initial_size);
|
2016-09-27 20:46:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-24 09:53:25 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ElementSectionWithInternalTable) {
|
|
|
|
static const byte data[] = {
|
|
|
|
// table ---------------------------------------------------------------
|
2018-07-10 12:14:06 +00:00
|
|
|
SECTION(Table, 4), ENTRY_COUNT(1), kLocalAnyFunc, 0, 1,
|
2017-08-24 09:53:25 +00:00
|
|
|
// elements ------------------------------------------------------------
|
|
|
|
SECTION(Element, 1),
|
|
|
|
0 // entry count
|
|
|
|
};
|
|
|
|
|
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, ElementSectionWithImportedTable) {
|
|
|
|
static const byte data[] = {
|
|
|
|
// imports -------------------------------------------------------------
|
|
|
|
SECTION(Import, 9), ENTRY_COUNT(1),
|
2018-07-10 12:14:06 +00:00
|
|
|
NAME_LENGTH(1), // --
|
|
|
|
'm', // module name
|
|
|
|
NAME_LENGTH(1), // --
|
|
|
|
't', // table name
|
|
|
|
kExternalTable, // import kind
|
|
|
|
kLocalAnyFunc, // elem_type
|
|
|
|
0, // no maximum field
|
|
|
|
1, // initial size
|
2017-08-24 09:53:25 +00:00
|
|
|
// elements ------------------------------------------------------------
|
|
|
|
SECTION(Element, 1),
|
|
|
|
0 // entry count
|
|
|
|
};
|
|
|
|
|
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, ElementSectionWithoutTable) {
|
|
|
|
// Test that an element section without a table causes a validation error.
|
|
|
|
static const byte data[] = {
|
|
|
|
// elements ------------------------------------------------------------
|
|
|
|
SECTION(Element, 4),
|
|
|
|
1, // entry count
|
|
|
|
0, // table index
|
|
|
|
0, // offset
|
|
|
|
0 // number of elements
|
|
|
|
};
|
|
|
|
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
2017-07-06 12:35:25 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, Regression_735887) {
|
|
|
|
// Test with an invalid function index in the element section.
|
|
|
|
static const byte data[] = {
|
|
|
|
// sig#0 ---------------------------------------------------------------
|
|
|
|
SIGNATURES_SECTION_VOID_VOID,
|
|
|
|
// funcs ---------------------------------------------------------------
|
|
|
|
ONE_EMPTY_FUNCTION,
|
|
|
|
// table declaration ---------------------------------------------------
|
2018-07-10 12:14:06 +00:00
|
|
|
SECTION(Table, 4), ENTRY_COUNT(1), kLocalAnyFunc, 0, 1,
|
2017-07-06 12:35:25 +00:00
|
|
|
// elements ------------------------------------------------------------
|
|
|
|
SECTION(Element, 7),
|
|
|
|
1, // entry count
|
|
|
|
TABLE_INDEX(0), WASM_INIT_EXPR_I32V_1(0),
|
|
|
|
1, // elements count
|
2017-12-02 00:30:37 +00:00
|
|
|
0x9A // invalid I32V as function index
|
2017-07-06 12:35:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, OneIndirectFunction_one_entry) {
|
|
|
|
static const byte data[] = {
|
|
|
|
// sig#0 ---------------------------------------------------------------
|
|
|
|
SIGNATURES_SECTION_VOID_VOID,
|
|
|
|
// funcs ---------------------------------------------------------------
|
|
|
|
ONE_EMPTY_FUNCTION,
|
|
|
|
// table declaration ---------------------------------------------------
|
2018-07-10 12:14:06 +00:00
|
|
|
SECTION(Table, 4), ENTRY_COUNT(1), kLocalAnyFunc, 0, 1,
|
2016-09-27 20:46:10 +00:00
|
|
|
// elements ------------------------------------------------------------
|
|
|
|
SECTION(Element, 7),
|
|
|
|
1, // entry count
|
|
|
|
TABLE_INDEX(0), WASM_INIT_EXPR_I32V_1(0),
|
|
|
|
1, // elements count
|
|
|
|
FUNC_INDEX(0)};
|
|
|
|
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
2016-04-21 11:18:41 +00:00
|
|
|
EXPECT_OK(result);
|
2015-12-11 12:26:16 +00:00
|
|
|
if (result.ok()) {
|
2016-11-11 11:55:30 +00:00
|
|
|
EXPECT_EQ(1u, result.val->signatures.size());
|
|
|
|
EXPECT_EQ(1u, result.val->functions.size());
|
2018-07-10 12:14:06 +00:00
|
|
|
EXPECT_EQ(1u, result.val->tables.size());
|
|
|
|
EXPECT_EQ(1u, result.val->tables[0].initial_size);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, MultipleIndirectFunctions) {
|
|
|
|
static const byte data[] = {
|
|
|
|
// sig#0 -------------------------------------------------------
|
2016-09-27 20:46:10 +00:00
|
|
|
SECTION(Type, 1 + SIZEOF_SIG_ENTRY_v_v + SIZEOF_SIG_ENTRY_v_x),
|
2016-04-29 09:39:26 +00:00
|
|
|
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,
|
2016-09-27 20:46:10 +00:00
|
|
|
// table declaration -------------------------------------------
|
2018-07-10 12:14:06 +00:00
|
|
|
SECTION(Table, 4), ENTRY_COUNT(1), kLocalAnyFunc, 0, 8,
|
2016-09-27 20:46:10 +00:00
|
|
|
// table elements ----------------------------------------------
|
|
|
|
SECTION(Element, 14),
|
|
|
|
1, // entry count
|
|
|
|
TABLE_INDEX(0), WASM_INIT_EXPR_I32V_1(0),
|
|
|
|
8, // elements count
|
|
|
|
FUNC_INDEX(0), // --
|
|
|
|
FUNC_INDEX(1), // --
|
|
|
|
FUNC_INDEX(2), // --
|
|
|
|
FUNC_INDEX(3), // --
|
|
|
|
FUNC_INDEX(0), // --
|
|
|
|
FUNC_INDEX(1), // --
|
|
|
|
FUNC_INDEX(2), // --
|
|
|
|
FUNC_INDEX(3), // --
|
2016-05-25 16:12:09 +00:00
|
|
|
FOUR_EMPTY_BODIES};
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
2016-04-21 11:18:41 +00:00
|
|
|
EXPECT_OK(result);
|
2015-12-11 12:26:16 +00:00
|
|
|
if (result.ok()) {
|
2016-11-11 11:55:30 +00:00
|
|
|
EXPECT_EQ(2u, result.val->signatures.size());
|
|
|
|
EXPECT_EQ(4u, result.val->functions.size());
|
2018-07-10 12:14:06 +00:00
|
|
|
EXPECT_EQ(1u, result.val->tables.size());
|
|
|
|
EXPECT_EQ(8u, result.val->tables[0].initial_size);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-12 09:56:25 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ElementSectionMultipleTables) {
|
|
|
|
// Test that if we have multiple tables, in the element section we can target
|
|
|
|
// and initialize all tables.
|
2018-08-08 14:54:44 +00:00
|
|
|
WASM_FEATURE_SCOPE(anyref);
|
2018-07-12 09:56:25 +00:00
|
|
|
static const byte data[] = {
|
|
|
|
// sig#0 ---------------------------------------------------------------
|
|
|
|
SIGNATURES_SECTION_VOID_VOID,
|
|
|
|
// funcs ---------------------------------------------------------------
|
|
|
|
ONE_EMPTY_FUNCTION,
|
|
|
|
// table declaration ---------------------------------------------------
|
|
|
|
SECTION(Table, 7), ENTRY_COUNT(2), // section header
|
|
|
|
kLocalAnyFunc, 0, 5, // table 0
|
|
|
|
kLocalAnyFunc, 0, 9, // table 1
|
|
|
|
// elements ------------------------------------------------------------
|
|
|
|
SECTION(Element, 14),
|
|
|
|
2, // entry count
|
|
|
|
TABLE_INDEX(0), // element for table 0
|
|
|
|
WASM_INIT_EXPR_I32V_1(0), // index
|
|
|
|
1, // elements count
|
|
|
|
FUNC_INDEX(0), // function
|
|
|
|
TABLE_INDEX(1), // element for table 1
|
|
|
|
WASM_INIT_EXPR_I32V_1(7), // index
|
|
|
|
2, // elements count
|
|
|
|
FUNC_INDEX(0), // entry 0
|
|
|
|
FUNC_INDEX(0), // entry 1
|
|
|
|
};
|
|
|
|
|
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, ElementSectionMixedTables) {
|
|
|
|
// Test that if we have multiple tables, both imported and module-defined, in
|
|
|
|
// the element section we can target and initialize all tables.
|
2018-08-08 14:54:44 +00:00
|
|
|
WASM_FEATURE_SCOPE(anyref);
|
2018-07-12 09:56:25 +00:00
|
|
|
static const byte data[] = {
|
|
|
|
// sig#0 ---------------------------------------------------------------
|
|
|
|
SIGNATURES_SECTION_VOID_VOID,
|
|
|
|
// imports -------------------------------------------------------------
|
|
|
|
SECTION(Import, 17), ENTRY_COUNT(2),
|
|
|
|
NAME_LENGTH(1), // --
|
|
|
|
'm', // module name
|
|
|
|
NAME_LENGTH(1), // --
|
|
|
|
't', // table name
|
|
|
|
kExternalTable, // import kind
|
|
|
|
kLocalAnyFunc, // elem_type
|
|
|
|
0, // no maximum field
|
|
|
|
5, // initial size
|
|
|
|
NAME_LENGTH(1), // --
|
|
|
|
'm', // module name
|
|
|
|
NAME_LENGTH(1), // --
|
|
|
|
's', // table name
|
|
|
|
kExternalTable, // import kind
|
|
|
|
kLocalAnyFunc, // elem_type
|
|
|
|
0, // no maximum field
|
|
|
|
10, // initial size
|
|
|
|
// funcs ---------------------------------------------------------------
|
|
|
|
ONE_EMPTY_FUNCTION,
|
|
|
|
// table declaration ---------------------------------------------------
|
|
|
|
SECTION(Table, 7), ENTRY_COUNT(2), // section header
|
|
|
|
kLocalAnyFunc, 0, 15, // table 0
|
|
|
|
kLocalAnyFunc, 0, 19, // table 1
|
|
|
|
// elements ------------------------------------------------------------
|
|
|
|
SECTION(Element, 27),
|
|
|
|
4, // entry count
|
|
|
|
TABLE_INDEX(0), // element for table 0
|
|
|
|
WASM_INIT_EXPR_I32V_1(0), // index
|
|
|
|
1, // elements count
|
|
|
|
FUNC_INDEX(0), // function
|
|
|
|
TABLE_INDEX(1), // element for table 1
|
|
|
|
WASM_INIT_EXPR_I32V_1(7), // index
|
|
|
|
2, // elements count
|
|
|
|
FUNC_INDEX(0), // entry 0
|
|
|
|
FUNC_INDEX(0), // entry 1
|
|
|
|
TABLE_INDEX(2), // element for table 2
|
|
|
|
WASM_INIT_EXPR_I32V_1(12), // index
|
|
|
|
1, // elements count
|
|
|
|
FUNC_INDEX(0), // function
|
|
|
|
TABLE_INDEX(3), // element for table 1
|
|
|
|
WASM_INIT_EXPR_I32V_1(17), // index
|
|
|
|
2, // elements count
|
|
|
|
FUNC_INDEX(0), // entry 0
|
|
|
|
FUNC_INDEX(0), // entry 1
|
|
|
|
};
|
|
|
|
|
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, ElementSectionMultipleTablesArbitraryOrder) {
|
|
|
|
// Test that the order in which tables are targeted in the element secion
|
|
|
|
// can be arbitrary.
|
2018-08-08 14:54:44 +00:00
|
|
|
WASM_FEATURE_SCOPE(anyref);
|
2018-07-12 09:56:25 +00:00
|
|
|
static const byte data[] = {
|
|
|
|
// sig#0 ---------------------------------------------------------------
|
|
|
|
SIGNATURES_SECTION_VOID_VOID,
|
|
|
|
// funcs ---------------------------------------------------------------
|
|
|
|
ONE_EMPTY_FUNCTION,
|
|
|
|
// table declaration ---------------------------------------------------
|
|
|
|
SECTION(Table, 7), ENTRY_COUNT(2), // section header
|
|
|
|
kLocalAnyFunc, 0, 5, // table 0
|
|
|
|
kLocalAnyFunc, 0, 9, // table 1
|
|
|
|
// elements ------------------------------------------------------------
|
|
|
|
SECTION(Element, 20),
|
|
|
|
3, // entry count
|
|
|
|
TABLE_INDEX(0), // element for table 1
|
|
|
|
WASM_INIT_EXPR_I32V_1(0), // index
|
|
|
|
1, // elements count
|
|
|
|
FUNC_INDEX(0), // function
|
|
|
|
TABLE_INDEX(1), // element for table 0
|
|
|
|
WASM_INIT_EXPR_I32V_1(7), // index
|
|
|
|
2, // elements count
|
|
|
|
FUNC_INDEX(0), // entry 0
|
|
|
|
FUNC_INDEX(0), // entry 1
|
|
|
|
TABLE_INDEX(0), // element for table 1
|
|
|
|
WASM_INIT_EXPR_I32V_1(3), // index
|
|
|
|
1, // elements count
|
|
|
|
FUNC_INDEX(0), // function
|
|
|
|
};
|
|
|
|
|
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, ElementSectionMixedTablesArbitraryOrder) {
|
|
|
|
// Test that the order in which tables are targeted in the element secion can
|
|
|
|
// be arbitrary. In this test, tables can be both imported and module-defined.
|
2018-08-08 14:54:44 +00:00
|
|
|
WASM_FEATURE_SCOPE(anyref);
|
2018-07-12 09:56:25 +00:00
|
|
|
static const byte data[] = {
|
|
|
|
// sig#0 ---------------------------------------------------------------
|
|
|
|
SIGNATURES_SECTION_VOID_VOID,
|
|
|
|
// imports -------------------------------------------------------------
|
|
|
|
SECTION(Import, 17), ENTRY_COUNT(2),
|
|
|
|
NAME_LENGTH(1), // --
|
|
|
|
'm', // module name
|
|
|
|
NAME_LENGTH(1), // --
|
|
|
|
't', // table name
|
|
|
|
kExternalTable, // import kind
|
|
|
|
kLocalAnyFunc, // elem_type
|
|
|
|
0, // no maximum field
|
|
|
|
5, // initial size
|
|
|
|
NAME_LENGTH(1), // --
|
|
|
|
'm', // module name
|
|
|
|
NAME_LENGTH(1), // --
|
|
|
|
's', // table name
|
|
|
|
kExternalTable, // import kind
|
|
|
|
kLocalAnyFunc, // elem_type
|
|
|
|
0, // no maximum field
|
|
|
|
10, // initial size
|
|
|
|
// funcs ---------------------------------------------------------------
|
|
|
|
ONE_EMPTY_FUNCTION,
|
|
|
|
// table declaration ---------------------------------------------------
|
|
|
|
SECTION(Table, 7), ENTRY_COUNT(2), // section header
|
|
|
|
kLocalAnyFunc, 0, 15, // table 0
|
|
|
|
kLocalAnyFunc, 0, 19, // table 1
|
|
|
|
// elements ------------------------------------------------------------
|
|
|
|
SECTION(Element, 27),
|
|
|
|
4, // entry count
|
|
|
|
TABLE_INDEX(2), // element for table 0
|
|
|
|
WASM_INIT_EXPR_I32V_1(10), // index
|
|
|
|
1, // elements count
|
|
|
|
FUNC_INDEX(0), // function
|
|
|
|
TABLE_INDEX(3), // element for table 1
|
|
|
|
WASM_INIT_EXPR_I32V_1(17), // index
|
|
|
|
2, // elements count
|
|
|
|
FUNC_INDEX(0), // entry 0
|
|
|
|
FUNC_INDEX(0), // entry 1
|
|
|
|
TABLE_INDEX(0), // element for table 2
|
|
|
|
WASM_INIT_EXPR_I32V_1(2), // index
|
|
|
|
1, // elements count
|
|
|
|
FUNC_INDEX(0), // function
|
|
|
|
TABLE_INDEX(1), // element for table 1
|
|
|
|
WASM_INIT_EXPR_I32V_1(7), // index
|
|
|
|
2, // elements count
|
|
|
|
FUNC_INDEX(0), // entry 0
|
|
|
|
FUNC_INDEX(0), // entry 1
|
|
|
|
};
|
|
|
|
|
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, ElementSectionDontInitAnyRefTable) {
|
|
|
|
// Test that tables of type 'AnyRef' cannot be initialized by the element
|
|
|
|
// section.
|
2018-08-08 14:54:44 +00:00
|
|
|
WASM_FEATURE_SCOPE(anyref);
|
2018-07-12 09:56:25 +00:00
|
|
|
static const byte data[] = {
|
|
|
|
// sig#0 ---------------------------------------------------------------
|
|
|
|
SIGNATURES_SECTION_VOID_VOID,
|
|
|
|
// funcs ---------------------------------------------------------------
|
|
|
|
ONE_EMPTY_FUNCTION,
|
|
|
|
// table declaration ---------------------------------------------------
|
|
|
|
SECTION(Table, 7), ENTRY_COUNT(2), // section header
|
|
|
|
kLocalAnyRef, 0, 5, // table 0
|
|
|
|
kLocalAnyFunc, 0, 9, // table 1
|
|
|
|
// elements ------------------------------------------------------------
|
|
|
|
SECTION(Element, 14),
|
|
|
|
2, // entry count
|
|
|
|
TABLE_INDEX(0), // element for table 0
|
|
|
|
WASM_INIT_EXPR_I32V_1(0), // index
|
|
|
|
1, // elements count
|
|
|
|
FUNC_INDEX(0), // function
|
|
|
|
TABLE_INDEX(1), // element for table 1
|
|
|
|
WASM_INIT_EXPR_I32V_1(7), // index
|
|
|
|
2, // elements count
|
|
|
|
FUNC_INDEX(0), // entry 0
|
|
|
|
FUNC_INDEX(0), // entry 1
|
|
|
|
};
|
|
|
|
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, ElementSectionDontInitAnyRefImportedTable) {
|
|
|
|
// Test that imported tables of type AnyRef cannot be initialized in the
|
|
|
|
// elements section.
|
2018-08-08 14:54:44 +00:00
|
|
|
WASM_FEATURE_SCOPE(anyref);
|
2018-07-12 09:56:25 +00:00
|
|
|
static const byte data[] = {
|
|
|
|
// sig#0 ---------------------------------------------------------------
|
|
|
|
SIGNATURES_SECTION_VOID_VOID,
|
|
|
|
// imports -------------------------------------------------------------
|
|
|
|
SECTION(Import, 17), ENTRY_COUNT(2),
|
|
|
|
NAME_LENGTH(1), // --
|
|
|
|
'm', // module name
|
|
|
|
NAME_LENGTH(1), // --
|
|
|
|
't', // table name
|
|
|
|
kExternalTable, // import kind
|
|
|
|
kLocalAnyFunc, // elem_type
|
|
|
|
0, // no maximum field
|
|
|
|
5, // initial size
|
|
|
|
NAME_LENGTH(1), // --
|
|
|
|
'm', // module name
|
|
|
|
NAME_LENGTH(1), // --
|
|
|
|
's', // table name
|
|
|
|
kExternalTable, // import kind
|
|
|
|
kLocalAnyRef, // elem_type
|
|
|
|
0, // no maximum field
|
|
|
|
10, // initial size
|
|
|
|
// funcs ---------------------------------------------------------------
|
|
|
|
ONE_EMPTY_FUNCTION,
|
|
|
|
// table declaration ---------------------------------------------------
|
|
|
|
SECTION(Table, 7), ENTRY_COUNT(2), // section header
|
|
|
|
kLocalAnyFunc, 0, 15, // table 0
|
|
|
|
kLocalAnyFunc, 0, 19, // table 1
|
|
|
|
// elements ------------------------------------------------------------
|
|
|
|
SECTION(Element, 14),
|
|
|
|
4, // entry count
|
|
|
|
TABLE_INDEX(0), // element for table 0
|
|
|
|
WASM_INIT_EXPR_I32V_1(10), // index
|
|
|
|
1, // elements count
|
|
|
|
FUNC_INDEX(0), // function
|
|
|
|
TABLE_INDEX(1), // element for table 1
|
|
|
|
WASM_INIT_EXPR_I32V_1(17), // index
|
|
|
|
2, // elements count
|
|
|
|
FUNC_INDEX(0), // entry 0
|
|
|
|
FUNC_INDEX(0), // entry 1
|
|
|
|
};
|
|
|
|
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
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-09-27 20:46:10 +00:00
|
|
|
SECTION(Table, 4), ENTRY_COUNT(1), 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-09-27 20:46:10 +00:00
|
|
|
SECTION(Table, 4), ENTRY_COUNT(1), 1, 1, 0,
|
2015-12-11 12:26:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
2018-07-10 12:14:06 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, MultipleTablesWithoutFlag) {
|
|
|
|
static const byte data[] = {
|
|
|
|
SECTION(Table, 7), // table section
|
|
|
|
ENTRY_COUNT(2), // 2 tables
|
|
|
|
kLocalAnyFunc, // table 1: type
|
|
|
|
0, // table 1: no maximum
|
|
|
|
10, // table 1: minimum size
|
|
|
|
kLocalAnyFunc, // table 2: type
|
|
|
|
0, // table 2: no maximum
|
|
|
|
10, // table 2: minimum size
|
|
|
|
};
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, MultipleTablesWithFlag) {
|
2018-08-08 14:54:44 +00:00
|
|
|
WASM_FEATURE_SCOPE(anyref);
|
2018-07-10 12:14:06 +00:00
|
|
|
static const byte data[] = {
|
|
|
|
SECTION(Table, 7), // table section
|
|
|
|
ENTRY_COUNT(2), // 2 tables
|
|
|
|
kLocalAnyFunc, // table 1: type
|
|
|
|
0, // table 1: no maximum
|
|
|
|
10, // table 1: minimum size
|
|
|
|
kLocalAnyRef, // table 2: type
|
|
|
|
0, // table 2: no maximum
|
|
|
|
11, // table 2: minimum size
|
|
|
|
};
|
|
|
|
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_OK(result);
|
|
|
|
|
|
|
|
EXPECT_EQ(2u, result.val->tables.size());
|
|
|
|
|
|
|
|
EXPECT_EQ(10u, result.val->tables[0].initial_size);
|
|
|
|
EXPECT_EQ(kWasmAnyFunc, result.val->tables[0].type);
|
|
|
|
|
|
|
|
EXPECT_EQ(11u, result.val->tables[1].initial_size);
|
|
|
|
EXPECT_EQ(kWasmAnyRef, result.val->tables[1].type);
|
|
|
|
}
|
|
|
|
|
2018-03-22 09:43:44 +00:00
|
|
|
class WasmSignatureDecodeTest : public TestWithZone {
|
|
|
|
public:
|
2018-08-08 14:54:44 +00:00
|
|
|
WasmFeatures enabled_features_;
|
|
|
|
|
|
|
|
FunctionSig* DecodeSig(const byte* start, const byte* end) {
|
|
|
|
return DecodeWasmSignatureForTesting(enabled_features_, zone(), start, end);
|
|
|
|
}
|
2018-03-22 09:43:44 +00:00
|
|
|
};
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
TEST_F(WasmSignatureDecodeTest, Ok_v_v) {
|
2016-04-29 09:39:26 +00:00
|
|
|
static const byte data[] = {SIG_ENTRY_v_v};
|
2016-09-20 16:07:25 +00:00
|
|
|
v8::internal::AccountingAllocator allocator;
|
2016-10-17 12:12:30 +00:00
|
|
|
Zone zone(&allocator, ZONE_NAME);
|
2018-08-08 14:54:44 +00:00
|
|
|
FunctionSig* sig = DecodeSig(data, data + sizeof(data));
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
EXPECT_TRUE(sig != nullptr);
|
2016-11-11 11:55:30 +00:00
|
|
|
EXPECT_EQ(0u, sig->parameter_count());
|
|
|
|
EXPECT_EQ(0u, sig->return_count());
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmSignatureDecodeTest, Ok_t_v) {
|
2018-08-08 14:54:44 +00:00
|
|
|
WASM_FEATURE_SCOPE(anyref);
|
2016-12-21 13:43:00 +00:00
|
|
|
for (size_t i = 0; i < arraysize(kValueTypes); i++) {
|
|
|
|
ValueTypePair ret_type = kValueTypes[i];
|
2016-04-29 09:39:26 +00:00
|
|
|
const byte data[] = {SIG_ENTRY_x(ret_type.code)};
|
2018-08-08 14:54:44 +00:00
|
|
|
FunctionSig* sig = DecodeSig(data, data + sizeof(data));
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
EXPECT_TRUE(sig != nullptr);
|
2016-11-11 11:55:30 +00:00
|
|
|
EXPECT_EQ(0u, sig->parameter_count());
|
|
|
|
EXPECT_EQ(1u, sig->return_count());
|
2015-12-11 12:26:16 +00:00
|
|
|
EXPECT_EQ(ret_type.type, sig->GetReturn());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmSignatureDecodeTest, Ok_v_t) {
|
2018-08-08 14:54:44 +00:00
|
|
|
WASM_FEATURE_SCOPE(anyref);
|
2016-12-21 13:43:00 +00:00
|
|
|
for (size_t i = 0; i < arraysize(kValueTypes); i++) {
|
|
|
|
ValueTypePair param_type = kValueTypes[i];
|
2016-04-29 09:39:26 +00:00
|
|
|
const byte data[] = {SIG_ENTRY_v_x(param_type.code)};
|
2018-08-08 14:54:44 +00:00
|
|
|
FunctionSig* sig = DecodeSig(data, data + sizeof(data));
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
EXPECT_TRUE(sig != nullptr);
|
2016-11-11 11:55:30 +00:00
|
|
|
EXPECT_EQ(1u, sig->parameter_count());
|
|
|
|
EXPECT_EQ(0u, sig->return_count());
|
2015-12-11 12:26:16 +00:00
|
|
|
EXPECT_EQ(param_type.type, sig->GetParam(0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmSignatureDecodeTest, Ok_t_t) {
|
2018-08-08 14:54:44 +00:00
|
|
|
WASM_FEATURE_SCOPE(anyref);
|
2016-12-21 13:43:00 +00:00
|
|
|
for (size_t i = 0; i < arraysize(kValueTypes); i++) {
|
|
|
|
ValueTypePair ret_type = kValueTypes[i];
|
|
|
|
for (size_t j = 0; j < arraysize(kValueTypes); j++) {
|
|
|
|
ValueTypePair param_type = kValueTypes[j];
|
2016-04-29 09:39:26 +00:00
|
|
|
const byte data[] = {SIG_ENTRY_x_x(ret_type.code, param_type.code)};
|
2018-08-08 14:54:44 +00:00
|
|
|
FunctionSig* sig = DecodeSig(data, data + sizeof(data));
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
EXPECT_TRUE(sig != nullptr);
|
2016-11-11 11:55:30 +00:00
|
|
|
EXPECT_EQ(1u, sig->parameter_count());
|
|
|
|
EXPECT_EQ(1u, sig->return_count());
|
2015-12-11 12:26:16 +00:00
|
|
|
EXPECT_EQ(param_type.type, sig->GetParam(0));
|
|
|
|
EXPECT_EQ(ret_type.type, sig->GetReturn());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmSignatureDecodeTest, Ok_i_tt) {
|
2018-08-08 14:54:44 +00:00
|
|
|
WASM_FEATURE_SCOPE(anyref);
|
|
|
|
WASM_FEATURE_SCOPE(mv);
|
2016-12-21 13:43:00 +00:00
|
|
|
for (size_t i = 0; i < arraysize(kValueTypes); i++) {
|
|
|
|
ValueTypePair p0_type = kValueTypes[i];
|
|
|
|
for (size_t j = 0; j < arraysize(kValueTypes); j++) {
|
|
|
|
ValueTypePair p1_type = kValueTypes[j];
|
2016-04-29 09:39:26 +00:00
|
|
|
const byte data[] = {
|
|
|
|
SIG_ENTRY_x_xx(kLocalI32, p0_type.code, p1_type.code)};
|
2018-08-08 14:54:44 +00:00
|
|
|
FunctionSig* sig = DecodeSig(data, data + sizeof(data));
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
EXPECT_TRUE(sig != nullptr);
|
2016-11-11 11:55:30 +00:00
|
|
|
EXPECT_EQ(2u, sig->parameter_count());
|
|
|
|
EXPECT_EQ(1u, sig->return_count());
|
2015-12-11 12:26:16 +00:00
|
|
|
EXPECT_EQ(p0_type.type, sig->GetParam(0));
|
|
|
|
EXPECT_EQ(p1_type.type, sig->GetParam(1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-08 14:54:44 +00:00
|
|
|
TEST_F(WasmSignatureDecodeTest, Ok_tt_tt) {
|
|
|
|
WASM_FEATURE_SCOPE(anyref);
|
|
|
|
WASM_FEATURE_SCOPE(mv);
|
|
|
|
for (size_t i = 0; i < arraysize(kValueTypes); i++) {
|
|
|
|
ValueTypePair p0_type = kValueTypes[i];
|
|
|
|
for (size_t j = 0; j < arraysize(kValueTypes); j++) {
|
|
|
|
ValueTypePair p1_type = kValueTypes[j];
|
|
|
|
const byte data[] = {SIG_ENTRY_xx_xx(p0_type.code, p1_type.code,
|
|
|
|
p0_type.code, p1_type.code)};
|
|
|
|
FunctionSig* sig = DecodeSig(data, data + sizeof(data));
|
|
|
|
|
|
|
|
EXPECT_TRUE(sig != nullptr);
|
|
|
|
EXPECT_EQ(2u, sig->parameter_count());
|
|
|
|
EXPECT_EQ(2u, sig->return_count());
|
|
|
|
EXPECT_EQ(p0_type.type, sig->GetParam(0));
|
|
|
|
EXPECT_EQ(p1_type.type, sig->GetParam(1));
|
|
|
|
EXPECT_EQ(p0_type.type, sig->GetReturn(0));
|
|
|
|
EXPECT_EQ(p1_type.type, sig->GetReturn(1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-14 17:45:59 +00:00
|
|
|
TEST_F(WasmSignatureDecodeTest, TooManyParams) {
|
2018-01-11 11:49:29 +00:00
|
|
|
static const byte data[] = {kWasmFunctionTypeCode,
|
2016-12-14 17:45:59 +00:00
|
|
|
WASM_I32V_3(kV8MaxWasmFunctionParams + 1),
|
|
|
|
kLocalI32, 0};
|
2018-08-08 14:54:44 +00:00
|
|
|
FunctionSig* sig = DecodeSig(data, data + sizeof(data));
|
2016-12-14 17:45:59 +00:00
|
|
|
EXPECT_FALSE(sig != nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmSignatureDecodeTest, TooManyReturns) {
|
|
|
|
for (int i = 0; i < 2; i++) {
|
2018-08-08 14:54:44 +00:00
|
|
|
bool enable_mv = i != 0;
|
|
|
|
WASM_FEATURE_SCOPE_VAL(mv, enable_mv);
|
2017-05-31 13:31:52 +00:00
|
|
|
const int max_return_count = static_cast<int>(
|
2018-08-08 14:54:44 +00:00
|
|
|
enable_mv ? kV8MaxWasmFunctionMultiReturns : kV8MaxWasmFunctionReturns);
|
2018-01-11 11:49:29 +00:00
|
|
|
byte data[] = {kWasmFunctionTypeCode, 0, WASM_I32V_3(max_return_count + 1),
|
2016-12-14 17:45:59 +00:00
|
|
|
kLocalI32};
|
2018-08-08 14:54:44 +00:00
|
|
|
FunctionSig* sig = DecodeSig(data, data + sizeof(data));
|
2016-12-14 17:45:59 +00:00
|
|
|
EXPECT_EQ(nullptr, sig);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-11 12:26:16 +00:00
|
|
|
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.
|
2018-08-08 14:54:44 +00:00
|
|
|
FunctionSig* sig = DecodeSig(data, data + i);
|
2015-12-11 12:26:16 +00:00
|
|
|
EXPECT_EQ(nullptr, sig);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-22 09:43:44 +00:00
|
|
|
TEST_F(WasmSignatureDecodeTest, Fail_anyref_without_flag) {
|
|
|
|
// Disable AnyRef support and check that decoding fails.
|
2018-08-08 14:54:44 +00:00
|
|
|
WASM_FEATURE_SCOPE_VAL(anyref, false);
|
2018-07-09 09:15:45 +00:00
|
|
|
byte ref_types[] = {kLocalAnyFunc, kLocalAnyRef};
|
|
|
|
for (byte invalid_type : ref_types) {
|
|
|
|
for (size_t i = 0; i < SIZEOF_SIG_ENTRY_x_xx; i++) {
|
|
|
|
byte data[] = {SIG_ENTRY_x_xx(kLocalI32, kLocalI32, kLocalI32)};
|
|
|
|
data[i] = invalid_type;
|
2018-08-08 14:54:44 +00:00
|
|
|
FunctionSig* sig = DecodeSig(data, data + sizeof(data));
|
2018-07-09 09:15:45 +00:00
|
|
|
EXPECT_EQ(nullptr, sig);
|
|
|
|
}
|
2018-03-22 09:43:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-11 12:26:16 +00:00
|
|
|
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;
|
2018-08-08 14:54:44 +00:00
|
|
|
FunctionSig* sig = DecodeSig(data, data + sizeof(data));
|
2015-12-11 12:26:16 +00:00
|
|
|
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)};
|
2018-08-08 14:54:44 +00:00
|
|
|
FunctionSig* sig = DecodeSig(data, data + sizeof(data));
|
2016-04-29 09:39:26 +00:00
|
|
|
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)};
|
2018-08-08 14:54:44 +00:00
|
|
|
FunctionSig* sig = DecodeSig(data, data + sizeof(data));
|
2016-04-29 09:39:26 +00:00
|
|
|
EXPECT_EQ(nullptr, sig);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmSignatureDecodeTest, Fail_invalid_param_type2) {
|
|
|
|
static const byte data[] = {SIG_ENTRY_x_xx(kLocalI32, kLocalI32, kLocalVoid)};
|
2018-08-08 14:54:44 +00:00
|
|
|
FunctionSig* sig = DecodeSig(data, data + sizeof(data));
|
2016-04-29 09:39:26 +00:00
|
|
|
EXPECT_EQ(nullptr, sig);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2017-03-28 14:27:42 +00:00
|
|
|
class WasmFunctionVerifyTest : public TestWithIsolateAndZone {
|
|
|
|
public:
|
2018-08-08 14:54:44 +00:00
|
|
|
WasmFeatures enabled_features_;
|
2017-03-28 14:27:42 +00:00
|
|
|
WasmModule module;
|
|
|
|
Vector<const byte> bytes;
|
2018-08-08 14:54:44 +00:00
|
|
|
|
|
|
|
FunctionResult DecodeWasmFunction(const ModuleWireBytes& wire_bytes,
|
|
|
|
const WasmModule* module,
|
|
|
|
const byte* function_start,
|
|
|
|
const byte* function_end) {
|
|
|
|
return DecodeWasmFunctionForTesting(enabled_features_, zone(), wire_bytes,
|
|
|
|
module, function_start, function_end,
|
|
|
|
isolate()->counters());
|
|
|
|
}
|
2017-03-28 14:27:42 +00:00
|
|
|
};
|
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, // --
|
2017-01-15 21:18:53 +00:00
|
|
|
kExprEnd // body
|
2015-12-11 12:26:16 +00:00
|
|
|
};
|
|
|
|
|
2018-08-08 14:54:44 +00:00
|
|
|
FunctionResult result =
|
|
|
|
DecodeWasmFunction(bytes, &module, data, data + sizeof(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()) {
|
2017-05-08 12:45:20 +00:00
|
|
|
WasmFunction* function = result.val.get();
|
2016-11-11 11:55:30 +00:00
|
|
|
EXPECT_EQ(0u, function->sig->parameter_count());
|
|
|
|
EXPECT_EQ(0u, function->sig->return_count());
|
|
|
|
EXPECT_EQ(static_cast<uint32_t>(SIZEOF_SIG_ENTRY_v_v),
|
2017-06-12 11:59:14 +00:00
|
|
|
function->code.offset());
|
|
|
|
EXPECT_EQ(sizeof(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
|
|
|
}
|
|
|
|
}
|
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-09-27 20:46:10 +00:00
|
|
|
0, // unknown section code.
|
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-09-27 20:46:10 +00:00
|
|
|
UNKNOWN_SECTION(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-09-27 20:46:10 +00:00
|
|
|
UNKNOWN_SECTION(5),
|
2017-12-02 00:30:37 +00:00
|
|
|
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-09-27 20:46:10 +00:00
|
|
|
UNKNOWN_SECTION(0)};
|
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
|
|
|
// -----------------------------------------------------------
|
2017-12-02 00:30:37 +00:00
|
|
|
UNKNOWN_SECTION(5), 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
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-09-27 20:46:10 +00:00
|
|
|
UNKNOWN_SECTION(9),
|
2016-04-29 09:39:26 +00:00
|
|
|
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-09-27 20:46:10 +00:00
|
|
|
UNKNOWN_SECTION(333),
|
2016-04-29 09:39:26 +00:00
|
|
|
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, UnknownSectionSkipped) {
|
|
|
|
static const byte data[] = {
|
2016-09-27 20:46:10 +00:00
|
|
|
UNKNOWN_SECTION(1),
|
2016-04-29 09:39:26 +00:00
|
|
|
0, // one byte section
|
2016-09-27 20:46:10 +00:00
|
|
|
SECTION(Global, 6),
|
2016-03-03 16:52:10 +00:00
|
|
|
1,
|
2016-09-27 20:46:10 +00:00
|
|
|
kLocalI32, // memory type
|
|
|
|
0, // exported
|
|
|
|
WASM_INIT_EXPR_I32V_1(33), // init
|
2016-03-03 16:52:10 +00:00
|
|
|
};
|
2016-09-27 20:46:10 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
2016-04-21 11:18:41 +00:00
|
|
|
EXPECT_OK(result);
|
2016-03-03 16:52:10 +00:00
|
|
|
|
2016-11-11 11:55:30 +00:00
|
|
|
EXPECT_EQ(1u, result.val->globals.size());
|
|
|
|
EXPECT_EQ(0u, result.val->functions.size());
|
|
|
|
EXPECT_EQ(0u, result.val->data_segments.size());
|
2016-03-03 16:52:10 +00:00
|
|
|
|
2016-05-24 16:32:03 +00:00
|
|
|
const WasmGlobal* global = &result.val->globals.back();
|
2016-03-03 16:52:10 +00:00
|
|
|
|
2016-12-21 13:43:00 +00:00
|
|
|
EXPECT_EQ(kWasmI32, global->type);
|
2016-11-11 11:55:30 +00:00
|
|
|
EXPECT_EQ(0u, global->offset);
|
2016-03-03 16:52:10 +00:00
|
|
|
}
|
|
|
|
|
2016-02-19 14:58:25 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ImportTable_empty) {
|
2016-09-27 20:46:10 +00:00
|
|
|
static const byte data[] = {SECTION(Type, 1), 0, SECTION(Import, 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-09-27 20:46:10 +00:00
|
|
|
static const byte data[] = {SECTION(Import, 1), 0};
|
2016-04-21 11:18:41 +00:00
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
2016-11-08 13:25:00 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ImportTable_mutable_global) {
|
2018-08-08 14:54:44 +00:00
|
|
|
WASM_FEATURE_SCOPE(mut_global);
|
2016-11-08 13:25:00 +00:00
|
|
|
{
|
|
|
|
static const byte data[] = {
|
|
|
|
SECTION(Import, 8), // section header
|
|
|
|
1, // number of imports
|
|
|
|
NAME_LENGTH(1), // --
|
|
|
|
'm', // module name
|
|
|
|
NAME_LENGTH(1), // --
|
|
|
|
'f', // global name
|
|
|
|
kExternalGlobal, // import kind
|
|
|
|
kLocalI32, // type
|
|
|
|
0, // mutability
|
|
|
|
};
|
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
static const byte data[] = {
|
|
|
|
SECTION(Import, 8), // section header
|
|
|
|
1, // sig table
|
|
|
|
NAME_LENGTH(1), // --
|
|
|
|
'm', // module name
|
|
|
|
NAME_LENGTH(1), // --
|
|
|
|
'f', // global name
|
|
|
|
kExternalGlobal, // import kind
|
|
|
|
kLocalI32, // type
|
|
|
|
1, // mutability
|
|
|
|
};
|
2018-06-12 22:23:35 +00:00
|
|
|
EXPECT_VERIFIES(data);
|
2016-11-08 13:25:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-17 13:35:20 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ImportTable_mutability_malformed) {
|
2018-08-08 14:54:44 +00:00
|
|
|
WASM_FEATURE_SCOPE(mut_global);
|
2017-01-17 13:35:20 +00:00
|
|
|
static const byte data[] = {
|
|
|
|
SECTION(Import, 8),
|
|
|
|
1, // --
|
|
|
|
NAME_LENGTH(1), // --
|
|
|
|
'm', // module name
|
|
|
|
NAME_LENGTH(1), // --
|
|
|
|
'g', // global name
|
|
|
|
kExternalGlobal, // import kind
|
|
|
|
kLocalI32, // type
|
|
|
|
2, // invalid mutability
|
|
|
|
};
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
2016-04-21 11:18:41 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ImportTable_nosigs2) {
|
|
|
|
static const byte data[] = {
|
2016-09-27 20:46:10 +00:00
|
|
|
SECTION(Import, 6), 1, // sig table
|
|
|
|
NAME_LENGTH(1), 'm', // module name
|
|
|
|
NAME_LENGTH(1), 'f', // function name
|
|
|
|
kExternalFunction, // import kind
|
|
|
|
IMPORT_SIG_INDEX(0), // sig index
|
2016-04-21 11:18:41 +00:00
|
|
|
};
|
2016-02-19 14:58:25 +00:00
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, ImportTable_invalid_sig) {
|
|
|
|
static const byte data[] = {
|
2016-09-27 20:46:10 +00:00
|
|
|
SECTION(Type, 1), 0, // --
|
|
|
|
SECTION(Import, 6), 1, // --
|
|
|
|
NAME_LENGTH(1), 'm', // module name
|
|
|
|
NAME_LENGTH(1), 'f', // function name
|
|
|
|
kExternalFunction, // import kind
|
|
|
|
IMPORT_SIG_INDEX(0), // sig index
|
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-09-27 20:46:10 +00:00
|
|
|
SECTION(Import, 7),
|
|
|
|
1, // --
|
2016-03-10 12:36:42 +00:00
|
|
|
NAME_LENGTH(1),
|
|
|
|
'm', // module name
|
|
|
|
NAME_LENGTH(1),
|
2016-09-27 20:46:10 +00:00
|
|
|
'f', // function name
|
|
|
|
kExternalFunction, // import kind
|
|
|
|
IMPORT_SIG_INDEX(0), // sig index
|
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
|
2016-09-27 20:46:10 +00:00
|
|
|
SIGNATURES_SECTION_VOID_VOID, // --
|
|
|
|
SECTION(Import, 7), // --
|
|
|
|
1, // --
|
|
|
|
NO_NAME, // module name
|
|
|
|
NAME_LENGTH(1), // --
|
|
|
|
'f', // function name
|
|
|
|
kExternalFunction, // import kind
|
|
|
|
IMPORT_SIG_INDEX(0), // sig index
|
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-09-27 20:46:10 +00:00
|
|
|
SECTION(Import, 6),
|
2016-03-10 12:36:42 +00:00
|
|
|
1,
|
|
|
|
NAME_LENGTH(1),
|
|
|
|
'm', // module name
|
|
|
|
NAME_LENGTH(1),
|
2016-09-27 20:46:10 +00:00
|
|
|
'f', // function name
|
|
|
|
kExternalFunction, // import kind
|
|
|
|
IMPORT_SIG_INDEX(0), // sig index
|
2016-02-19 14:58:25 +00:00
|
|
|
};
|
|
|
|
|
2018-10-16 13:28:20 +00:00
|
|
|
EXPECT_OFF_END_FAILURE(data, arraysize(data) - 3);
|
2016-02-19 14:58:25 +00:00
|
|
|
}
|
|
|
|
|
2016-03-09 22:50:36 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ExportTable_empty1) {
|
2016-09-27 20:46:10 +00:00
|
|
|
static const byte data[] = { // signatures
|
|
|
|
SIGNATURES_SECTION_VOID_VOID, // --
|
|
|
|
ONE_EMPTY_FUNCTION, SECTION(Export, 1), // --
|
|
|
|
0, // --
|
2016-05-25 16:12:09 +00:00
|
|
|
ONE_EMPTY_BODY};
|
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
2016-05-25 16:12:09 +00:00
|
|
|
EXPECT_OK(result);
|
|
|
|
|
2016-11-11 11:55:30 +00:00
|
|
|
EXPECT_EQ(1u, result.val->functions.size());
|
|
|
|
EXPECT_EQ(0u, result.val->export_table.size());
|
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-09-27 20:46:10 +00:00
|
|
|
SECTION(Type, 1), 0, SECTION(Export, 1), 0 // --
|
2016-04-29 09:39:26 +00:00
|
|
|
};
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(data);
|
2016-02-27 01:52:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, ExportTable_NoFunctions2) {
|
2016-09-27 20:46:10 +00:00
|
|
|
static const byte data[] = {SECTION(Export, 1), 0};
|
|
|
|
EXPECT_VERIFIES(data);
|
2016-02-27 01:52:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, ExportTableOne) {
|
2016-05-25 16:12:09 +00:00
|
|
|
static const byte data[] = {// signatures
|
|
|
|
SIGNATURES_SECTION_VOID_VOID,
|
|
|
|
ONE_EMPTY_FUNCTION,
|
2016-09-27 20:46:10 +00:00
|
|
|
SECTION(Export, 4),
|
|
|
|
1, // exports
|
|
|
|
NO_NAME, // --
|
|
|
|
kExternalFunction, // --
|
|
|
|
FUNC_INDEX(0), // --
|
2016-05-25 16:12:09 +00:00
|
|
|
ONE_EMPTY_BODY};
|
2016-09-27 20:46:10 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
2016-05-25 16:12:09 +00:00
|
|
|
EXPECT_OK(result);
|
|
|
|
|
2016-11-11 11:55:30 +00:00
|
|
|
EXPECT_EQ(1u, result.val->functions.size());
|
|
|
|
EXPECT_EQ(1u, result.val->export_table.size());
|
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,
|
2016-09-27 20:46:10 +00:00
|
|
|
SECTION(Export, 12),
|
|
|
|
1, // exports
|
|
|
|
NAME_LENGTH(84), // invalid string length
|
|
|
|
'e', // --
|
|
|
|
kExternalFunction, // --
|
|
|
|
FUNC_INDEX(0)};
|
2016-09-06 09:50:12 +00:00
|
|
|
|
|
|
|
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,
|
2016-09-27 20:46:10 +00:00
|
|
|
SECTION(Export, 14),
|
|
|
|
2, // exports
|
2016-05-25 16:12:09 +00:00
|
|
|
NAME_LENGTH(4),
|
|
|
|
'n',
|
|
|
|
'a',
|
|
|
|
'm',
|
2016-09-27 20:46:10 +00:00
|
|
|
'e', // --
|
|
|
|
kExternalFunction,
|
2016-05-25 16:12:09 +00:00
|
|
|
FUNC_INDEX(0), // --
|
|
|
|
NAME_LENGTH(3),
|
|
|
|
'n',
|
|
|
|
'o',
|
2016-09-27 20:46:10 +00:00
|
|
|
'm', // --
|
|
|
|
kExternalFunction, // --
|
|
|
|
FUNC_INDEX(0), // --
|
2016-05-25 16:12:09 +00:00
|
|
|
ONE_EMPTY_BODY};
|
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
2016-05-25 16:12:09 +00:00
|
|
|
EXPECT_OK(result);
|
|
|
|
|
2016-11-11 11:55:30 +00:00
|
|
|
EXPECT_EQ(1u, result.val->functions.size());
|
|
|
|
EXPECT_EQ(2u, result.val->export_table.size());
|
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,
|
2016-09-27 20:46:10 +00:00
|
|
|
SECTION(Export, 13),
|
|
|
|
3, // exports
|
|
|
|
NAME_LENGTH(1),
|
|
|
|
'a', // --
|
|
|
|
kExternalFunction,
|
2016-05-25 16:12:09 +00:00
|
|
|
FUNC_INDEX(0), // --
|
|
|
|
NAME_LENGTH(1),
|
2016-09-27 20:46:10 +00:00
|
|
|
'b', // --
|
|
|
|
kExternalFunction,
|
2016-05-25 16:12:09 +00:00
|
|
|
FUNC_INDEX(1), // --
|
|
|
|
NAME_LENGTH(1),
|
2016-09-23 17:58:07 +00:00
|
|
|
'c', // --
|
2016-09-27 20:46:10 +00:00
|
|
|
kExternalFunction,
|
|
|
|
FUNC_INDEX(2), // --
|
2016-05-25 16:12:09 +00:00
|
|
|
THREE_EMPTY_BODIES};
|
2016-09-27 20:46:10 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
2016-05-25 16:12:09 +00:00
|
|
|
EXPECT_OK(result);
|
|
|
|
|
2016-11-11 11:55:30 +00:00
|
|
|
EXPECT_EQ(3u, result.val->functions.size());
|
|
|
|
EXPECT_EQ(3u, result.val->export_table.size());
|
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,
|
2016-09-27 20:46:10 +00:00
|
|
|
SECTION(Export, 6),
|
|
|
|
1, // exports
|
2016-05-25 16:12:09 +00:00
|
|
|
NAME_LENGTH(2),
|
|
|
|
'e',
|
|
|
|
'x', // --
|
2016-09-27 20:46:10 +00:00
|
|
|
kExternalFunction,
|
|
|
|
FUNC_INDEX(i), // --
|
2016-05-25 16:12:09 +00:00
|
|
|
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-09-27 20:46:10 +00:00
|
|
|
SECTION(Export, 1 + 6),
|
|
|
|
1, // exports
|
|
|
|
NO_NAME, // --
|
|
|
|
kExternalFunction,
|
2016-03-10 12:36:42 +00:00
|
|
|
FUNC_INDEX(0), // --
|
2016-02-27 01:52:30 +00:00
|
|
|
};
|
|
|
|
|
2018-10-16 13:28:20 +00:00
|
|
|
EXPECT_OFF_END_FAILURE(data, arraysize(data) - 3);
|
2016-02-27 01:52:30 +00:00
|
|
|
}
|
|
|
|
|
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[] = {
|
2016-09-27 20:46:10 +00:00
|
|
|
SECTION(Type, 1), 0, // --
|
|
|
|
SECTION(Function, 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);
|
|
|
|
}
|
|
|
|
|
2016-09-21 16:18:00 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, Regression_648070) {
|
|
|
|
static const byte data[] = {
|
2016-09-27 20:46:10 +00:00
|
|
|
SECTION(Type, 1), 0, // --
|
|
|
|
SECTION(Function, 5), // --
|
|
|
|
U32V_5(3500228624) // function count = 3500228624
|
|
|
|
}; // --
|
2016-09-21 16:18:00 +00:00
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
2017-07-06 13:27:57 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, Regression_738097) {
|
|
|
|
// The function body size caused an integer overflow in the module decoder.
|
|
|
|
static const byte data[] = {
|
|
|
|
SIGNATURES_SECTION(1, SIG_ENTRY_v_v), // --
|
|
|
|
FUNCTION_SIGNATURES_SECTION(1, 0), // --
|
|
|
|
SECTION(Code, 1 + 5 + 1), // --
|
|
|
|
1, // --
|
2017-12-02 00:30:37 +00:00
|
|
|
U32V_5(0xFFFFFFFF), // function size,
|
2017-07-06 13:27:57 +00:00
|
|
|
0 // No real body
|
|
|
|
};
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
2017-10-23 13:24:15 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, FunctionBodySizeLimit) {
|
|
|
|
const uint32_t delta = 3;
|
|
|
|
for (uint32_t body_size = kV8MaxWasmFunctionSize - delta;
|
|
|
|
body_size < kV8MaxWasmFunctionSize + delta; body_size++) {
|
|
|
|
byte data[] = {
|
|
|
|
SIGNATURES_SECTION(1, SIG_ENTRY_v_v), // --
|
|
|
|
FUNCTION_SIGNATURES_SECTION(1, 0), // --
|
|
|
|
kCodeSectionCode, // code section
|
|
|
|
U32V_5(1 + body_size + 5), // section size
|
|
|
|
1, // # functions
|
|
|
|
U32V_5(body_size) // body size
|
|
|
|
};
|
|
|
|
size_t total = sizeof(data) + body_size;
|
|
|
|
byte* buffer = reinterpret_cast<byte*>(calloc(1, total));
|
|
|
|
memcpy(buffer, data, sizeof(data));
|
|
|
|
ModuleResult result = DecodeModule(buffer, buffer + total);
|
|
|
|
if (body_size <= kV8MaxWasmFunctionSize) {
|
|
|
|
EXPECT_TRUE(result.ok());
|
|
|
|
} else {
|
|
|
|
EXPECT_FALSE(result.ok());
|
|
|
|
}
|
|
|
|
free(buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-09 22:50:36 +00:00
|
|
|
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-09-27 20:46:10 +00:00
|
|
|
SIGNATURES_SECTION(1, SIG_ENTRY_v_v), // --
|
|
|
|
FUNCTION_SIGNATURES_SECTION(1, 0), // --
|
|
|
|
SECTION(Code, 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-09-27 20:46:10 +00:00
|
|
|
SIGNATURES_SECTION(1, SIG_ENTRY_v_v), // --
|
|
|
|
FUNCTION_SIGNATURES_SECTION(1, 0), // --
|
|
|
|
SECTION(Code, 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-09-27 20:46:10 +00:00
|
|
|
SIGNATURES_SECTION(1, SIG_ENTRY_v_v), // --
|
|
|
|
FUNCTION_SIGNATURES_SECTION(2, 0, 0), // --
|
|
|
|
SECTION(Code, 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-09-27 20:46:10 +00:00
|
|
|
SIGNATURES_SECTION(1, SIG_ENTRY_v_v), // --
|
|
|
|
FUNCTION_SIGNATURES_SECTION(1, 0), // --
|
|
|
|
SECTION(Code, 1 + 2 * SIZEOF_NOP_BODY), // --
|
|
|
|
ENTRY_COUNT(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-09-27 20:46:10 +00:00
|
|
|
SECTION(Code, 1 + SIZEOF_EMPTY_BODY),
|
|
|
|
ENTRY_COUNT(1),
|
2016-03-10 12:36:42 +00:00
|
|
|
EMPTY_BODY, // --
|
2016-09-27 20:46:10 +00:00
|
|
|
SECTION_NAMES(1 + 5),
|
|
|
|
ENTRY_COUNT(1),
|
2016-03-10 12:36:42 +00:00
|
|
|
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-09-27 20:46:10 +00:00
|
|
|
SIGNATURES_SECTION(1, SIG_ENTRY_v_v), // --
|
|
|
|
FUNCTION_SIGNATURES_SECTION(2, 0, 0), // --
|
|
|
|
SECTION(Code, 1 + 2 * SIZEOF_EMPTY_BODY), // --
|
|
|
|
ENTRY_COUNT(2),
|
2016-03-10 12:36:42 +00:00
|
|
|
EMPTY_BODY,
|
|
|
|
EMPTY_BODY, // --
|
2016-09-27 20:46:10 +00:00
|
|
|
SECTION_NAMES(1 + 10),
|
|
|
|
ENTRY_COUNT(2), // --
|
2016-03-10 12:36:42 +00:00
|
|
|
FOO_STRING,
|
|
|
|
NO_LOCAL_NAMES, // --
|
|
|
|
FOO_STRING,
|
|
|
|
NO_LOCAL_NAMES, // --
|
2016-03-09 22:50:36 +00:00
|
|
|
};
|
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
2017-02-02 08:38:34 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, Regression684855) {
|
|
|
|
static const byte data[] = {
|
|
|
|
SECTION_NAMES(12),
|
2017-12-02 00:30:37 +00:00
|
|
|
0xFB, // functions count
|
2017-02-02 08:38:34 +00:00
|
|
|
0x27, // |
|
|
|
|
0x00, // function name length
|
2017-12-02 00:30:37 +00:00
|
|
|
0xFF, // local names count
|
|
|
|
0xFF, // |
|
|
|
|
0xFF, // |
|
|
|
|
0xFF, // |
|
|
|
|
0xFF, // |
|
|
|
|
0xFF, // error: "varint too large"
|
|
|
|
0xFF, // |
|
2017-02-02 08:38:34 +00:00
|
|
|
0x00, // --
|
|
|
|
0x00 // --
|
|
|
|
};
|
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
2018-08-08 14:54:44 +00:00
|
|
|
class WasmInitExprDecodeTest : public TestWithZone {
|
|
|
|
public:
|
2018-09-13 09:27:26 +00:00
|
|
|
WasmInitExprDecodeTest() = default;
|
2018-08-08 14:54:44 +00:00
|
|
|
|
|
|
|
WasmFeatures enabled_features_;
|
|
|
|
|
|
|
|
WasmInitExpr DecodeInitExpr(const byte* start, const byte* end) {
|
|
|
|
return DecodeWasmInitExprForTesting(enabled_features_, start, end);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#define EXPECT_INIT_EXPR(Type, type, value, ...) \
|
|
|
|
{ \
|
|
|
|
static const byte data[] = {__VA_ARGS__, kExprEnd}; \
|
|
|
|
WasmInitExpr expr = DecodeInitExpr(data, data + sizeof(data)); \
|
|
|
|
EXPECT_EQ(WasmInitExpr::k##Type##Const, expr.kind); \
|
|
|
|
EXPECT_EQ(value, expr.val.type##_const); \
|
2016-09-27 20:46:10 +00:00
|
|
|
}
|
|
|
|
|
2018-08-08 14:54:44 +00:00
|
|
|
#define EXPECT_INIT_EXPR_FAIL(...) \
|
|
|
|
{ \
|
|
|
|
static const byte data[] = {__VA_ARGS__, kExprEnd}; \
|
|
|
|
WasmInitExpr expr = DecodeInitExpr(data, data + sizeof(data)); \
|
|
|
|
EXPECT_EQ(WasmInitExpr::kNone, expr.kind); \
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmInitExprDecodeTest, InitExpr_i32) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_INIT_EXPR(I32, i32, 33, WASM_I32V_1(33));
|
|
|
|
EXPECT_INIT_EXPR(I32, i32, -21, WASM_I32V_1(-21));
|
|
|
|
EXPECT_INIT_EXPR(I32, i32, 437, WASM_I32V_2(437));
|
|
|
|
EXPECT_INIT_EXPR(I32, i32, 77777, WASM_I32V_3(77777));
|
|
|
|
}
|
|
|
|
|
2018-08-08 14:54:44 +00:00
|
|
|
TEST_F(WasmInitExprDecodeTest, InitExpr_f32) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_INIT_EXPR(F32, f32, static_cast<float>(13.1), WASM_F32(13.1));
|
|
|
|
EXPECT_INIT_EXPR(F32, f32, static_cast<float>(-21.1), WASM_F32(-21.1));
|
|
|
|
EXPECT_INIT_EXPR(F32, f32, static_cast<float>(437.2), WASM_F32(437.2));
|
|
|
|
EXPECT_INIT_EXPR(F32, f32, static_cast<float>(77777.3), WASM_F32(77777.3));
|
|
|
|
}
|
|
|
|
|
2018-08-08 14:54:44 +00:00
|
|
|
TEST_F(WasmInitExprDecodeTest, InitExpr_i64) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_INIT_EXPR(I64, i64, 33, WASM_I64V_1(33));
|
|
|
|
EXPECT_INIT_EXPR(I64, i64, -21, WASM_I64V_2(-21));
|
|
|
|
EXPECT_INIT_EXPR(I64, i64, 437, WASM_I64V_5(437));
|
|
|
|
EXPECT_INIT_EXPR(I64, i64, 77777, WASM_I64V_7(77777));
|
|
|
|
}
|
|
|
|
|
2018-08-08 14:54:44 +00:00
|
|
|
TEST_F(WasmInitExprDecodeTest, InitExpr_f64) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_INIT_EXPR(F64, f64, 83.22, WASM_F64(83.22));
|
|
|
|
EXPECT_INIT_EXPR(F64, f64, -771.3, WASM_F64(-771.3));
|
|
|
|
EXPECT_INIT_EXPR(F64, f64, 43703.0, WASM_F64(43703.0));
|
|
|
|
EXPECT_INIT_EXPR(F64, f64, 77999.1, WASM_F64(77999.1));
|
|
|
|
}
|
|
|
|
|
2018-08-08 14:54:44 +00:00
|
|
|
TEST_F(WasmInitExprDecodeTest, InitExpr_AnyRef) {
|
|
|
|
WASM_FEATURE_SCOPE(anyref);
|
2018-04-05 10:49:26 +00:00
|
|
|
static const byte data[] = {kExprRefNull, kExprEnd};
|
2018-08-08 14:54:44 +00:00
|
|
|
WasmInitExpr expr = DecodeInitExpr(data, data + sizeof(data));
|
2018-04-05 10:49:26 +00:00
|
|
|
EXPECT_EQ(WasmInitExpr::kAnyRefConst, expr.kind);
|
|
|
|
}
|
|
|
|
|
2018-08-08 14:54:44 +00:00
|
|
|
TEST_F(WasmInitExprDecodeTest, InitExpr_illegal) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_INIT_EXPR_FAIL(WASM_I32V_1(0), WASM_I32V_1(0));
|
|
|
|
EXPECT_INIT_EXPR_FAIL(WASM_GET_LOCAL(0));
|
|
|
|
EXPECT_INIT_EXPR_FAIL(WASM_SET_LOCAL(0, WASM_I32V_1(0)));
|
|
|
|
EXPECT_INIT_EXPR_FAIL(WASM_I32_ADD(WASM_I32V_1(0), WASM_I32V_1(0)));
|
|
|
|
EXPECT_INIT_EXPR_FAIL(WASM_IF_ELSE(WASM_ZERO, WASM_ZERO, WASM_ZERO));
|
|
|
|
}
|
|
|
|
|
2016-10-12 09:17:12 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, Multiple_Named_Sections) {
|
|
|
|
static const byte data[] = {
|
|
|
|
SECTION(Unknown, 4), 1, 'X', 17, 18, // --
|
|
|
|
SECTION(Unknown, 9), 3, 'f', 'o', 'o', 5, 6, 7, 8, 9, // --
|
|
|
|
SECTION(Unknown, 8), 5, 'o', 't', 'h', 'e', 'r', 7, 8, // --
|
|
|
|
};
|
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
2017-01-24 15:23:02 +00:00
|
|
|
|
2017-04-11 08:28:52 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, Section_Name_No_UTF8) {
|
2017-12-02 00:30:37 +00:00
|
|
|
static const byte data[] = {SECTION(Unknown, 4), 1, 0xFF, 17, 18};
|
2017-04-11 08:28:52 +00:00
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
2017-01-24 15:23:02 +00:00
|
|
|
class WasmModuleCustomSectionTest : public TestWithIsolateAndZone {
|
|
|
|
public:
|
|
|
|
void CheckSections(const byte* module_start, const byte* module_end,
|
2017-06-12 11:59:14 +00:00
|
|
|
const CustomSectionOffset* expected, size_t num_expected) {
|
2017-01-24 15:23:02 +00:00
|
|
|
std::vector<CustomSectionOffset> custom_sections =
|
|
|
|
DecodeCustomSections(module_start, module_end);
|
|
|
|
|
|
|
|
CHECK_EQ(num_expected, custom_sections.size());
|
|
|
|
|
|
|
|
for (size_t i = 0; i < num_expected; i++) {
|
2017-06-12 11:59:14 +00:00
|
|
|
EXPECT_EQ(expected[i].section.offset(),
|
|
|
|
custom_sections[i].section.offset());
|
|
|
|
EXPECT_EQ(expected[i].section.length(),
|
|
|
|
custom_sections[i].section.length());
|
|
|
|
EXPECT_EQ(expected[i].name.offset(), custom_sections[i].name.offset());
|
|
|
|
EXPECT_EQ(expected[i].name.length(), custom_sections[i].name.length());
|
|
|
|
EXPECT_EQ(expected[i].payload.offset(),
|
|
|
|
custom_sections[i].payload.offset());
|
|
|
|
EXPECT_EQ(expected[i].payload.length(),
|
|
|
|
custom_sections[i].payload.length());
|
2017-01-24 15:23:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(WasmModuleCustomSectionTest, ThreeUnknownSections) {
|
2017-06-12 11:59:14 +00:00
|
|
|
static constexpr byte data[] = {
|
2017-01-24 15:23:02 +00:00
|
|
|
U32_LE(kWasmMagic), // --
|
|
|
|
U32_LE(kWasmVersion), // --
|
|
|
|
SECTION(Unknown, 4), 1, 'X', 17, 18, // --
|
|
|
|
SECTION(Unknown, 9), 3, 'f', 'o', 'o', 5, 6, 7, 8, 9, // --
|
|
|
|
SECTION(Unknown, 8), 5, 'o', 't', 'h', 'e', 'r', 7, 8, // --
|
|
|
|
};
|
|
|
|
|
2017-06-12 11:59:14 +00:00
|
|
|
static const CustomSectionOffset expected[] = {
|
|
|
|
// section, name, payload
|
|
|
|
{{10, 4}, {11, 1}, {12, 2}}, // --
|
|
|
|
{{16, 9}, {17, 3}, {20, 5}}, // --
|
|
|
|
{{27, 8}, {28, 5}, {33, 2}}, // --
|
2017-01-24 15:23:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
CheckSections(data, data + sizeof(data), expected, arraysize(expected));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleCustomSectionTest, TwoKnownTwoUnknownSections) {
|
|
|
|
static const byte data[] = {
|
|
|
|
U32_LE(kWasmMagic), // --
|
|
|
|
U32_LE(kWasmVersion), // --
|
|
|
|
SIGNATURES_SECTION(2, SIG_ENTRY_v_v, SIG_ENTRY_v_v), // --
|
|
|
|
SECTION(Unknown, 4),
|
|
|
|
1,
|
|
|
|
'X',
|
|
|
|
17,
|
|
|
|
18, // --
|
|
|
|
ONE_EMPTY_FUNCTION,
|
|
|
|
SECTION(Unknown, 8),
|
|
|
|
5,
|
|
|
|
'o',
|
|
|
|
't',
|
|
|
|
'h',
|
|
|
|
'e',
|
|
|
|
'r',
|
|
|
|
7,
|
|
|
|
8, // --
|
|
|
|
};
|
|
|
|
|
2017-06-12 11:59:14 +00:00
|
|
|
static const CustomSectionOffset expected[] = {
|
|
|
|
// section, name, payload
|
|
|
|
{{19, 4}, {20, 1}, {21, 2}}, // --
|
|
|
|
{{29, 8}, {30, 5}, {35, 2}}, // --
|
2017-01-24 15:23:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
CheckSections(data, data + sizeof(data), expected, arraysize(expected));
|
|
|
|
}
|
|
|
|
|
2018-09-13 19:19:30 +00:00
|
|
|
#define SRC_MAP \
|
|
|
|
16, 's', 'o', 'u', 'r', 'c', 'e', 'M', 'a', 'p', 'p', 'i', 'n', 'g', 'U', \
|
|
|
|
'R', 'L'
|
|
|
|
TEST_F(WasmModuleVerifyTest, SourceMappingURLSection) {
|
|
|
|
#define SRC 's', 'r', 'c', '/', 'x', 'y', 'z', '.', 'c'
|
|
|
|
static const byte data[] = {SECTION(Unknown, 27), SRC_MAP, 9, SRC};
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_TRUE(result.ok());
|
|
|
|
EXPECT_EQ(9u, result.val->source_map_url.size());
|
|
|
|
const char src[] = {SRC};
|
|
|
|
EXPECT_EQ(
|
|
|
|
0,
|
|
|
|
strncmp(reinterpret_cast<const char*>(result.val->source_map_url.data()),
|
|
|
|
src, 9));
|
|
|
|
#undef SRC
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, BadSourceMappingURLSection) {
|
|
|
|
#define BAD_SRC 's', 'r', 'c', '/', 'x', 0xff, 'z', '.', 'c'
|
|
|
|
static const byte data[] = {SECTION(Unknown, 27), SRC_MAP, 9, BAD_SRC};
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_TRUE(result.ok());
|
|
|
|
EXPECT_EQ(0u, result.val->source_map_url.size());
|
|
|
|
#undef BAD_SRC
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, MultipleSourceMappingURLSections) {
|
|
|
|
#define SRC 'a', 'b', 'c'
|
|
|
|
static const byte data[] = {SECTION(Unknown, 21),
|
|
|
|
SRC_MAP,
|
|
|
|
3,
|
|
|
|
SRC,
|
|
|
|
SECTION(Unknown, 21),
|
|
|
|
SRC_MAP,
|
|
|
|
3,
|
|
|
|
'p',
|
|
|
|
'q',
|
|
|
|
'r'};
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_TRUE(result.ok());
|
|
|
|
EXPECT_EQ(3u, result.val->source_map_url.size());
|
|
|
|
const char src[] = {SRC};
|
|
|
|
EXPECT_EQ(
|
|
|
|
0,
|
|
|
|
strncmp(reinterpret_cast<const char*>(result.val->source_map_url.data()),
|
|
|
|
src, 3));
|
|
|
|
#undef SRC
|
|
|
|
}
|
|
|
|
#undef SRC_MAP
|
|
|
|
|
2018-09-21 19:35:50 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, MultipleNameSections) {
|
|
|
|
#define NAME_SECTION 4, 'n', 'a', 'm', 'e'
|
|
|
|
static const byte data[] = {SECTION(Unknown, 11),
|
|
|
|
NAME_SECTION,
|
|
|
|
0,
|
|
|
|
4,
|
|
|
|
3,
|
|
|
|
'a',
|
|
|
|
'b',
|
|
|
|
'c',
|
|
|
|
SECTION(Unknown, 12),
|
|
|
|
NAME_SECTION,
|
|
|
|
0,
|
|
|
|
5,
|
|
|
|
4,
|
|
|
|
'p',
|
|
|
|
'q',
|
|
|
|
'r',
|
|
|
|
's'};
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_TRUE(result.ok());
|
|
|
|
EXPECT_EQ(3u, result.val->name.length());
|
|
|
|
#undef NAME_SECTION
|
|
|
|
}
|
|
|
|
|
2018-08-08 14:54:44 +00:00
|
|
|
#undef WASM_FEATURE_SCOPE
|
|
|
|
#undef WASM_FEATURE_SCOPE_VAL
|
|
|
|
#undef EXPECT_INIT_EXPR
|
|
|
|
#undef EXPECT_INIT_EXPR_FAIL
|
2017-09-08 13:59:05 +00:00
|
|
|
#undef WASM_INIT_EXPR_I32V_1
|
|
|
|
#undef WASM_INIT_EXPR_I32V_2
|
|
|
|
#undef WASM_INIT_EXPR_I32V_3
|
|
|
|
#undef WASM_INIT_EXPR_I32V_4
|
|
|
|
#undef WASM_INIT_EXPR_I32V_5
|
|
|
|
#undef WASM_INIT_EXPR_F32
|
|
|
|
#undef WASM_INIT_EXPR_I64
|
|
|
|
#undef WASM_INIT_EXPR_F64
|
2018-04-05 10:49:26 +00:00
|
|
|
#undef WASM_INIT_EXPR_ANYREF
|
2017-09-08 13:59:05 +00:00
|
|
|
#undef WASM_INIT_EXPR_GLOBAL
|
|
|
|
#undef SIZEOF_EMPTY_FUNCTION
|
|
|
|
#undef EMPTY_BODY
|
|
|
|
#undef SIZEOF_EMPTY_BODY
|
|
|
|
#undef NOP_BODY
|
|
|
|
#undef SIZEOF_NOP_BODY
|
|
|
|
#undef SIG_ENTRY_i_i
|
|
|
|
#undef UNKNOWN_SECTION
|
|
|
|
#undef SECTION
|
|
|
|
#undef SIGNATURES_SECTION
|
|
|
|
#undef FUNCTION_SIGNATURES_SECTION
|
|
|
|
#undef FOO_STRING
|
|
|
|
#undef NO_LOCAL_NAMES
|
|
|
|
#undef EMPTY_SIGNATURES_SECTION
|
|
|
|
#undef EMPTY_FUNCTION_SIGNATURES_SECTION
|
|
|
|
#undef EMPTY_FUNCTION_BODIES_SECTION
|
|
|
|
#undef SECTION_NAMES
|
|
|
|
#undef SECTION_EXCEPTIONS
|
|
|
|
#undef EMPTY_NAMES_SECTION
|
|
|
|
#undef FAIL_IF_NO_EXPERIMENTAL_EH
|
|
|
|
#undef X1
|
|
|
|
#undef X2
|
|
|
|
#undef X3
|
|
|
|
#undef X4
|
|
|
|
#undef ONE_EMPTY_FUNCTION
|
|
|
|
#undef TWO_EMPTY_FUNCTIONS
|
|
|
|
#undef THREE_EMPTY_FUNCTIONS
|
|
|
|
#undef FOUR_EMPTY_FUNCTIONS
|
|
|
|
#undef ONE_EMPTY_BODY
|
|
|
|
#undef TWO_EMPTY_BODIES
|
|
|
|
#undef THREE_EMPTY_BODIES
|
|
|
|
#undef FOUR_EMPTY_BODIES
|
|
|
|
#undef SIGNATURES_SECTION_VOID_VOID
|
|
|
|
#undef LINEAR_MEMORY_INDEX_0
|
|
|
|
#undef EXPECT_VERIFIES
|
|
|
|
#undef EXPECT_FAILURE_LEN
|
|
|
|
#undef EXPECT_FAILURE
|
|
|
|
#undef EXPECT_OFF_END_FAILURE
|
|
|
|
#undef EXPECT_OK
|
|
|
|
|
2017-09-28 17:55:52 +00:00
|
|
|
} // namespace module_decoder_unittest
|
2015-12-11 12:26:16 +00:00
|
|
|
} // namespace wasm
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|