Commit e19dc9f6 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm][test] Compute section length automatically

Instead of specifying the byte length of a section manually, just
compute it automatically from the bytes given. Manual computation is
particularly difficult because of the macros involved, which can expand
to several bytes.
This is not a pure refactoring, it also fixes several occasions where
we calculated the length wrong.

Drive-by: Add some ENTRY_COUNT macro uses.

This is the fourth CL in a series to improve our module decoder tests and
make them more readable.

R=titzer@chromium.org

Bug: v8:8238
Change-Id: I0d2ceb751fc8e5625ffdf4189d4b5253aecc2541
Reviewed-on: https://chromium-review.googlesource.com/c/1283075
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56718}
parent 22783832
......@@ -39,22 +39,33 @@ namespace module_decoder_unittest {
#define UNKNOWN_SECTION(size) 0, U32V_1(size + 5), 4, 'l', 'u', 'l', 'z'
#define SECTION(name, size) k##name##SectionCode, U32V_1(size)
template <typename... Args>
std::integral_constant<size_t, sizeof...(Args)> CountArgsHelper(Args...);
#define COUNT_ARGS(...) (decltype(CountArgsHelper(__VA_ARGS__))::value)
#define SIGNATURES_SECTION(count, ...) \
SECTION(Type, 1 + 3 * (count)), U32V_1(count), __VA_ARGS__
template <size_t num>
struct CheckLEB1 : std::integral_constant<size_t, num> {
static_assert(num <= I32V_MAX(1), "LEB range check");
};
#define CHECK_LEB1(num) CheckLEB1<num>::value
#define ADD_COUNT(...) CHECK_LEB1(COUNT_ARGS(__VA_ARGS__)), __VA_ARGS__
#define SECTION(name, ...) k##name##SectionCode, ADD_COUNT(__VA_ARGS__)
#define SIGNATURES_SECTION(count, ...) SECTION(Type, U32V_1(count), __VA_ARGS__)
#define FUNCTION_SIGNATURES_SECTION(count, ...) \
SECTION(Function, 1 + (count)), U32V_1(count), __VA_ARGS__
SECTION(Function, U32V_1(count), __VA_ARGS__)
#define FOO_STRING 3, 'f', 'o', 'o'
#define NO_LOCAL_NAMES 0
#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
#define SECTION_NAMES(size) SECTION(Unknown, size + 5), 4, 'n', 'a', 'm', 'e'
#define SECTION_EXCEPTIONS(size) SECTION(Exception, size)
#define EMPTY_NAMES_SECTION SECTION_NAMES(1), 0
#define EMPTY_SIGNATURES_SECTION SECTION(Type, ENTRY_COUNT(0))
#define EMPTY_FUNCTION_SIGNATURES_SECTION SECTION(Function, ENTRY_COUNT(0))
#define EMPTY_FUNCTION_BODIES_SECTION SECTION(Code, ENTRY_COUNT(0))
#define SECTION_NAMES(...) \
SECTION(Unknown, 4, 'n', 'a', 'm', 'e', ##__VA_ARGS__)
#define EMPTY_NAMES_SECTION SECTION_NAMES()
#define FAIL_IF_NO_EXPERIMENTAL_EH(data) \
do { \
......@@ -69,35 +80,31 @@ namespace module_decoder_unittest {
#define X4(...) __VA_ARGS__, __VA_ARGS__, __VA_ARGS__, __VA_ARGS__
#define ONE_EMPTY_FUNCTION(sig_index) \
SECTION(Function, 1 + 1 * 1), 1, X1(sig_index)
SECTION(Function, ENTRY_COUNT(1), X1(sig_index))
#define TWO_EMPTY_FUNCTIONS(sig_index) \
SECTION(Function, 1 + 2 * 1), 2, X2(sig_index)
SECTION(Function, ENTRY_COUNT(2), X2(sig_index))
#define THREE_EMPTY_FUNCTIONS(sig_index) \
SECTION(Function, 1 + 3 * 1), 3, X3(sig_index)
SECTION(Function, ENTRY_COUNT(3), X3(sig_index))
#define FOUR_EMPTY_FUNCTIONS(sig_index) \
SECTION(Function, 1 + 4 * 1), 4, X4(sig_index)
SECTION(Function, ENTRY_COUNT(4), X4(sig_index))
#define ONE_EMPTY_BODY \
SECTION(Code, 1 + 1 * (1 + SIZEOF_EMPTY_BODY)) \
, 1, X1(SIZEOF_EMPTY_BODY, EMPTY_BODY)
#define ONE_EMPTY_BODY \
SECTION(Code, ENTRY_COUNT(1), X1(SIZEOF_EMPTY_BODY, EMPTY_BODY))
#define TWO_EMPTY_BODIES \
SECTION(Code, 1 + 2 * (1 + SIZEOF_EMPTY_BODY)) \
, 2, X2(SIZEOF_EMPTY_BODY, EMPTY_BODY)
#define TWO_EMPTY_BODIES \
SECTION(Code, ENTRY_COUNT(2), X2(SIZEOF_EMPTY_BODY, EMPTY_BODY))
#define THREE_EMPTY_BODIES \
SECTION(Code, 1 + 3 * (1 + SIZEOF_EMPTY_BODY)) \
, 3, X3(SIZEOF_EMPTY_BODY, EMPTY_BODY)
#define THREE_EMPTY_BODIES \
SECTION(Code, ENTRY_COUNT(3), X3(SIZEOF_EMPTY_BODY, EMPTY_BODY))
#define FOUR_EMPTY_BODIES \
SECTION(Code, 1 + 4 * (1 + SIZEOF_EMPTY_BODY)) \
, 4, X4(SIZEOF_EMPTY_BODY, EMPTY_BODY)
#define FOUR_EMPTY_BODIES \
SECTION(Code, ENTRY_COUNT(4), X4(SIZEOF_EMPTY_BODY, EMPTY_BODY))
#define SIGNATURES_SECTION_VOID_VOID \
SECTION(Type, 1 + SIZEOF_SIG_ENTRY_v_v), 1, SIG_ENTRY_v_v
SECTION(Type, ENTRY_COUNT(1), SIG_ENTRY_v_v)
#define LINEAR_MEMORY_INDEX_0 0
......@@ -218,11 +225,11 @@ TEST_F(WasmModuleVerifyTest, DecodeEmpty) {
TEST_F(WasmModuleVerifyTest, OneGlobal) {
static const byte data[] = {
SECTION(Global, 6), // --
1,
kLocalI32, // local type
0, // immutable
WASM_INIT_EXPR_I32V_1(13) // init
SECTION(Global, // --
ENTRY_COUNT(1), // --
kLocalI32, // local type
0, // immutable
WASM_INIT_EXPR_I32V_1(13)) // init
};
{
......@@ -248,11 +255,11 @@ TEST_F(WasmModuleVerifyTest, OneGlobal) {
TEST_F(WasmModuleVerifyTest, AnyRefGlobal) {
WASM_FEATURE_SCOPE(anyref);
static const byte data[] = {
SECTION(Global, 5), // --
1,
kLocalAnyRef, // local type
0, // immutable
WASM_INIT_EXPR_ANYREF // init
SECTION(Global, // --
ENTRY_COUNT(1), // --
kLocalAnyRef, // local type
0, // immutable
WASM_INIT_EXPR_ANYREF) // init
};
{
......@@ -274,20 +281,20 @@ TEST_F(WasmModuleVerifyTest, AnyRefGlobal) {
TEST_F(WasmModuleVerifyTest, AnyRefGlobalWithGlobalInit) {
WASM_FEATURE_SCOPE(anyref);
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),
SECTION(Import, // --
ENTRY_COUNT(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, // --
ENTRY_COUNT(1),
kLocalAnyRef, // local type
0, // immutable
WASM_INIT_EXPR_GLOBAL(0)),
};
{
......@@ -308,11 +315,11 @@ TEST_F(WasmModuleVerifyTest, AnyRefGlobalWithGlobalInit) {
TEST_F(WasmModuleVerifyTest, Global_invalid_type) {
static const byte data[] = {
SECTION(Global, 6), // --
1,
64, // invalid memory type
1, // mutable
WASM_INIT_EXPR_I32V_1(33), // init
SECTION(Global, // --
ENTRY_COUNT(1), // --
64, // invalid memory type
1, // mutable
WASM_INIT_EXPR_I32V_1(33)), // init
};
EXPECT_FAILURE(data);
......@@ -320,21 +327,18 @@ TEST_F(WasmModuleVerifyTest, Global_invalid_type) {
TEST_F(WasmModuleVerifyTest, Global_invalid_type2) {
static const byte data[] = {
SECTION(Global, 6), // --
1,
kLocalVoid, // invalid memory type
1, // mutable
WASM_INIT_EXPR_I32V_1(33), // init
SECTION(Global, // --
ENTRY_COUNT(1), // --
kLocalVoid, // invalid memory type
1, // mutable
WASM_INIT_EXPR_I32V_1(33)), // init
};
EXPECT_FAILURE(data);
}
TEST_F(WasmModuleVerifyTest, ZeroGlobals) {
static const byte data[] = {
SECTION(Global, 1), // --
0, // declare 0 globals
};
static const byte data[] = {SECTION(Global, ENTRY_COUNT(0))};
ModuleResult result = DecodeModule(data, data + sizeof(data));
EXPECT_OK(result);
}
......@@ -343,39 +347,39 @@ TEST_F(WasmModuleVerifyTest, ExportMutableGlobal) {
WASM_FEATURE_SCOPE(mut_global);
{
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
SECTION(Global, // --
ENTRY_COUNT(1), // --
kLocalI32, // local type
0, // immutable
WASM_INIT_EXPR_I32V_1(13)), // init
SECTION(Export, // --
ENTRY_COUNT(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
SECTION(Global, // --
ENTRY_COUNT(1), // --
kLocalI32, // local type
1, // mutable
WASM_INIT_EXPR_I32V_1(13)), // init
SECTION(Export, // --
ENTRY_COUNT(1), // export count
4, // name length
'n', // --
'a', // --
'm', // --
'e', // --
kExternalGlobal, // global
0), // global index
};
EXPECT_VERIFIES(data);
}
......@@ -420,25 +424,24 @@ TEST_F(WasmModuleVerifyTest, NGlobals) {
}
TEST_F(WasmModuleVerifyTest, GlobalWithInvalidMemoryType) {
static const byte data[] = {SECTION(Global, 7),
33, // memory type
0, // exported
WASM_INIT_EXPR_I32V_1(1)};
static const byte data[] = {SECTION(Global, // --
ENTRY_COUNT(1), // --
33, // memory type
0, // exported
WASM_INIT_EXPR_I32V_1(1))};
EXPECT_FAILURE(data);
}
TEST_F(WasmModuleVerifyTest, TwoGlobals) {
static const byte data[] = {
SECTION(Global, 21),
2,
kLocalF32, // type
0, // immutable
WASM_INIT_EXPR_F32(22.0),
kLocalF64, // type
1, // mutable
WASM_INIT_EXPR_F64(23.0),
};
static const byte data[] = {SECTION(Global, // --
ENTRY_COUNT(2), // --
kLocalF32, // type
0, // immutable
WASM_INIT_EXPR_F32(22.0), // --
kLocalF64, // type
1, // mutable
WASM_INIT_EXPR_F64(23.0))}; // --
{
// Should decode to exactly two globals.
......@@ -467,9 +470,7 @@ TEST_F(WasmModuleVerifyTest, TwoGlobals) {
}
TEST_F(WasmModuleVerifyTest, ZeroExceptions) {
static const byte data[] = {
SECTION_EXCEPTIONS(1), 0,
};
static const byte data[] = {SECTION(Exception, ENTRY_COUNT(0))};
FAIL_IF_NO_EXPERIMENTAL_EH(data);
WASM_FEATURE_SCOPE(eh);
......@@ -479,12 +480,9 @@ TEST_F(WasmModuleVerifyTest, ZeroExceptions) {
}
TEST_F(WasmModuleVerifyTest, OneI32Exception) {
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
SIG_INDEX(0)}; // except[0] (sig#0)
static const byte data[] = {
SECTION(Type, ENTRY_COUNT(1), SIG_ENTRY_v_x(kLocalI32)), // sig#0 (i32)
SECTION(Exception, ENTRY_COUNT(1), SIG_INDEX(0))}; // except[0] (sig#0)
FAIL_IF_NO_EXPERIMENTAL_EH(data);
WASM_FEATURE_SCOPE(eh);
......@@ -498,17 +496,13 @@ TEST_F(WasmModuleVerifyTest, OneI32Exception) {
}
TEST_F(WasmModuleVerifyTest, TwoExceptions) {
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)
SIG_INDEX(1),
// except[1] (sig#0)
SIG_INDEX(0)};
static const byte data[] = {
SECTION(Type, ENTRY_COUNT(2),
SIG_ENTRY_v_x(kLocalI32), // sig#0 (i32)
SIG_ENTRY_v_xx(kLocalF32, kLocalI64)), // sig#1 (f32, i64)
SECTION(Exception, ENTRY_COUNT(2),
SIG_INDEX(1), // except[0] (sig#1)
SIG_INDEX(0))}; // except[1] (sig#0)
FAIL_IF_NO_EXPERIMENTAL_EH(data);
WASM_FEATURE_SCOPE(eh);
......@@ -524,10 +518,10 @@ TEST_F(WasmModuleVerifyTest, TwoExceptions) {
}
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])
SIG_INDEX(23)};
static const byte data[] = {
SIGNATURES_SECTION_VOID_VOID,
SECTION(Exception, ENTRY_COUNT(1),
SIG_INDEX(23))}; // except[0] (sig#23 [out-of-bounds])
FAIL_IF_NO_EXPERIMENTAL_EH(data);
// Should fail decoding exception section.
......@@ -536,10 +530,10 @@ TEST_F(WasmModuleVerifyTest, Exception_invalid_sig_index) {
}
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])
SIG_INDEX(0)};
static const byte data[] = {
SECTION(Type, ENTRY_COUNT(1), SIG_ENTRY_i_i),
SECTION(Exception, ENTRY_COUNT(1),
SIG_INDEX(0))}; // except[0] (sig#0 [invalid-return-type])
FAIL_IF_NO_EXPERIMENTAL_EH(data);
// Should fail decoding exception section.
......@@ -548,8 +542,9 @@ TEST_F(WasmModuleVerifyTest, Exception_invalid_sig_return) {
}
TEST_F(WasmModuleVerifyTest, ExceptionSectionCorrectPlacement) {
static const byte data[] = {SECTION(Import, 1), 0, SECTION_EXCEPTIONS(1), 0,
SECTION(Export, 1), 0};
static const byte data[] = {SECTION(Import, ENTRY_COUNT(0)),
SECTION(Exception, ENTRY_COUNT(0)),
SECTION(Export, ENTRY_COUNT(0))};
FAIL_IF_NO_EXPERIMENTAL_EH(data);
WASM_FEATURE_SCOPE(eh);
......@@ -558,7 +553,8 @@ TEST_F(WasmModuleVerifyTest, ExceptionSectionCorrectPlacement) {
}
TEST_F(WasmModuleVerifyTest, ExceptionSectionAfterExport) {
static const byte data[] = {SECTION(Export, 1), 0, SECTION_EXCEPTIONS(1), 0};
static const byte data[] = {SECTION(Export, ENTRY_COUNT(0)),
SECTION(Exception, ENTRY_COUNT(0))};
FAIL_IF_NO_EXPERIMENTAL_EH(data);
WASM_FEATURE_SCOPE(eh);
......@@ -566,7 +562,8 @@ TEST_F(WasmModuleVerifyTest, ExceptionSectionAfterExport) {
}
TEST_F(WasmModuleVerifyTest, ExceptionSectionBeforeImport) {
static const byte data[] = {SECTION_EXCEPTIONS(1), 0, SECTION(Import, 1), 0};
static const byte data[] = {SECTION(Exception, ENTRY_COUNT(0)),
SECTION(Import, ENTRY_COUNT(0))};
FAIL_IF_NO_EXPERIMENTAL_EH(data);
WASM_FEATURE_SCOPE(eh);
......@@ -575,15 +572,15 @@ TEST_F(WasmModuleVerifyTest, ExceptionSectionBeforeImport) {
TEST_F(WasmModuleVerifyTest, ExceptionImport) {
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
SIG_INDEX(0)}; // except[0] (sig#0)
SECTION(Import, // section header
ENTRY_COUNT(1), // number of imports
NAME_LENGTH(1), // --
'm', // module name
NAME_LENGTH(2), // --
'e', // exception name
'x', // --
kExternalException, // import kind
SIG_INDEX(0))}; // except[0] (sig#0)
FAIL_IF_NO_EXPERIMENTAL_EH(data);
WASM_FEATURE_SCOPE(eh);
......@@ -595,14 +592,12 @@ TEST_F(WasmModuleVerifyTest, ExceptionImport) {
TEST_F(WasmModuleVerifyTest, ExceptionExport) {
static const byte data[] = {SIGNATURES_SECTION_VOID_VOID,
SECTION_EXCEPTIONS(2),
1,
SIG_INDEX(0), // except[0] (sig#0)
SECTION(Export, 4), // section header
1, // number of exports
NO_NAME, // --
kExternalException, // --
EXCEPTION_INDEX(0)};
SECTION(Exception, ENTRY_COUNT(1),
SIG_INDEX(0)), // except[0] (sig#0)
SECTION(Export, ENTRY_COUNT(1), // --
NO_NAME, // --
kExternalException, // --
EXCEPTION_INDEX(0))};
FAIL_IF_NO_EXPERIMENTAL_EH(data);
WASM_FEATURE_SCOPE(eh);
......@@ -619,20 +614,19 @@ TEST_F(WasmModuleVerifyTest, OneSignature) {
}
{
static const byte data[] = {SECTION(Type, 1 + SIZEOF_SIG_ENTRY_x_x), 1,
SIG_ENTRY_i_i};
static const byte data[] = {SECTION(Type, ENTRY_COUNT(1), SIG_ENTRY_i_i)};
EXPECT_VERIFIES(data);
}
}
TEST_F(WasmModuleVerifyTest, MultipleSignatures) {
static const byte data[] = {
SECTION(Type, 1 + SIZEOF_SIG_ENTRY_v_v + SIZEOF_SIG_ENTRY_x_x +
SIZEOF_SIG_ENTRY_x_xx), // --
3, // --
SIG_ENTRY_v_v, // void -> void
SIG_ENTRY_x_x(kLocalI32, kLocalF32), // f32 -> i32
SIG_ENTRY_x_xx(kLocalI32, kLocalF64, kLocalF64), // f64,f64 -> i32
SECTION(
Type, // --
ENTRY_COUNT(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
};
ModuleResult result = DecodeModule(data, data + sizeof(data));
......@@ -654,35 +648,27 @@ TEST_F(WasmModuleVerifyTest, MultipleSignatures) {
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),
kHasMaximumFlag,
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
SECTION(Import, // section header
ENTRY_COUNT(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, ENTRY_COUNT(1), kHasMaximumFlag, 28, 28),
SECTION(Data, 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);
......@@ -694,52 +680,35 @@ TEST_F(WasmModuleVerifyTest, DataSegmentWithImmutableImportedGlobal) {
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),
kHasMaximumFlag,
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
SECTION(Import, // section header
ENTRY_COUNT(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, ENTRY_COUNT(1), kHasMaximumFlag, 28, 28),
SECTION(Data, 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),
kHasMaximumFlag,
28,
28,
SECTION(Global, 8), // --
1,
kLocalI32, // local type
0, // immutable
WASM_INIT_EXPR_I32V_3(0x9BBAA), // init
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
SECTION(Memory, ENTRY_COUNT(1), kHasMaximumFlag, 28, 28),
SECTION(Global, ENTRY_COUNT(1),
kLocalI32, // local type
0, // immutable
WASM_INIT_EXPR_I32V_3(0x9BBAA)), // init
SECTION(Data, 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);
}
......@@ -747,19 +716,11 @@ TEST_F(WasmModuleVerifyTest, DataSegmentWithImmutableGlobal) {
TEST_F(WasmModuleVerifyTest, OneDataSegment) {
const byte kDataSegmentSourceOffset = 24;
const byte data[] = {
SECTION(Memory, 4),
ENTRY_COUNT(1),
kHasMaximumFlag,
28,
28,
SECTION(Data, 11),
ENTRY_COUNT(1),
LINEAR_MEMORY_INDEX_0,
WASM_INIT_EXPR_I32V_3(0x9BBAA), // dest addr
U32V_1(3), // source size
'a',
'b',
'c' // data bytes
SECTION(Memory, ENTRY_COUNT(1), kHasMaximumFlag, 28, 28),
SECTION(Data, ENTRY_COUNT(1), LINEAR_MEMORY_INDEX_0,
WASM_INIT_EXPR_I32V_3(0x9BBAA), // dest addr
U32V_1(3), // source size
'a', 'b', 'c') // data bytes
};
{
......@@ -786,33 +747,17 @@ TEST_F(WasmModuleVerifyTest, TwoDataSegments) {
const byte kDataSegment1SourceOffset = kDataSegment0SourceOffset + 11;
const byte data[] = {
SECTION(Memory, 4),
ENTRY_COUNT(1),
kHasMaximumFlag,
28,
28,
SECTION(Data, 29),
ENTRY_COUNT(2), // segment count
LINEAR_MEMORY_INDEX_0,
WASM_INIT_EXPR_I32V_3(0x7FFEE), // #0: dest addr
U32V_1(4), // source size
1,
2,
3,
4, // data bytes
LINEAR_MEMORY_INDEX_0,
WASM_INIT_EXPR_I32V_3(0x6DDCC), // #1: dest addr
U32V_1(10), // source size
1,
2,
3,
4,
5,
6,
7,
8,
9,
10 // data bytes
SECTION(Memory, ENTRY_COUNT(1), kHasMaximumFlag, 28, 28),
SECTION(Data,
ENTRY_COUNT(2), // segment count
LINEAR_MEMORY_INDEX_0,
WASM_INIT_EXPR_I32V_3(0x7FFEE), // #0: dest addr
U32V_1(4), // source size
1, 2, 3, 4, // data bytes
LINEAR_MEMORY_INDEX_0,
WASM_INIT_EXPR_I32V_3(0x6DDCC), // #1: dest addr
U32V_1(10), // source size
1, 2, 3, 4, 5, 6, 7, 8, 9, 10) // data bytes
};
{
......@@ -841,14 +786,10 @@ TEST_F(WasmModuleVerifyTest, TwoDataSegments) {
TEST_F(WasmModuleVerifyTest, DataWithoutMemory) {
const byte data[] = {
SECTION(Data, 11),
ENTRY_COUNT(1),
LINEAR_MEMORY_INDEX_0,
WASM_INIT_EXPR_I32V_3(0x9BBAA), // dest addr
U32V_1(3), // source size
'a',
'b',
'c' // data bytes
SECTION(Data, ENTRY_COUNT(1), LINEAR_MEMORY_INDEX_0,
WASM_INIT_EXPR_I32V_3(0x9BBAA), // dest addr
U32V_1(3), // source size
'a', 'b', 'c') // data bytes
};
EXPECT_FAILURE(data);
}
......@@ -856,33 +797,23 @@ TEST_F(WasmModuleVerifyTest, DataWithoutMemory) {
TEST_F(WasmModuleVerifyTest, MaxMaximumMemorySize) {
{
const byte data[] = {
SECTION(Memory, 6), ENTRY_COUNT(1), kHasMaximumFlag, 0, U32V_3(65536),
};
SECTION(Memory, ENTRY_COUNT(1), kHasMaximumFlag, 0, U32V_3(65536))};
EXPECT_VERIFIES(data);
}
{
const byte data[] = {
SECTION(Memory, 6), ENTRY_COUNT(1), kHasMaximumFlag, 0, U32V_3(65537),
};
SECTION(Memory, ENTRY_COUNT(1), kHasMaximumFlag, 0, U32V_3(65537))};
EXPECT_FAILURE(data);
}
}
TEST_F(WasmModuleVerifyTest, DataSegment_wrong_init_type) {
const byte data[] = {
SECTION(Memory, 4),
ENTRY_COUNT(1),
kHasMaximumFlag,
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
SECTION(Memory, ENTRY_COUNT(1), kHasMaximumFlag, 28, 28),
SECTION(Data, 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);
......@@ -890,13 +821,13 @@ TEST_F(WasmModuleVerifyTest, DataSegment_wrong_init_type) {
TEST_F(WasmModuleVerifyTest, DataSegmentEndOverflow) {
const byte data[] = {
SECTION(Memory, 4), // memory section
ENTRY_COUNT(1), kHasMaximumFlag, 28, 28,
SECTION(Data, 10), // data section
ENTRY_COUNT(1), // one entry
LINEAR_MEMORY_INDEX_0, // mem index
WASM_INIT_EXPR_I32V_1(0), // offset
U32V_5(0xFFFFFFFF) // size
SECTION(Memory, // memory section
ENTRY_COUNT(1), kHasMaximumFlag, 28, 28),
SECTION(Data, // data section
ENTRY_COUNT(1), // one entry
LINEAR_MEMORY_INDEX_0, // mem index
WASM_INIT_EXPR_I32V_1(0), // offset
U32V_5(0xFFFFFFFF)) // size
};
EXPECT_FAILURE(data);
......@@ -909,7 +840,7 @@ TEST_F(WasmModuleVerifyTest, OneIndirectFunction) {
// funcs ---------------------------------------------------------------
ONE_EMPTY_FUNCTION(SIG_INDEX(0)),
// table declaration ---------------------------------------------------
SECTION(Table, 4), ENTRY_COUNT(1), kLocalAnyFunc, 0, 1};
SECTION(Table, ENTRY_COUNT(1), kLocalAnyFunc, 0, 1)};
ModuleResult result = DecodeModule(data, data + sizeof(data));
EXPECT_OK(result);
......@@ -924,11 +855,9 @@ TEST_F(WasmModuleVerifyTest, OneIndirectFunction) {
TEST_F(WasmModuleVerifyTest, ElementSectionWithInternalTable) {
static const byte data[] = {
// table ---------------------------------------------------------------
SECTION(Table, 4), ENTRY_COUNT(1), kLocalAnyFunc, 0, 1,
SECTION(Table, ENTRY_COUNT(1), kLocalAnyFunc, 0, 1),
// elements ------------------------------------------------------------
SECTION(Element, 1),
0 // entry count
};
SECTION(Element, ENTRY_COUNT(0))};
EXPECT_VERIFIES(data);
}
......@@ -936,19 +865,17 @@ TEST_F(WasmModuleVerifyTest, ElementSectionWithInternalTable) {
TEST_F(WasmModuleVerifyTest, ElementSectionWithImportedTable) {
static const byte data[] = {
// imports -------------------------------------------------------------
SECTION(Import, 9), ENTRY_COUNT(1),
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
SECTION(Import, ENTRY_COUNT(1),
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
// elements ------------------------------------------------------------
SECTION(Element, 1),
0 // entry count
};
SECTION(Element, ENTRY_COUNT(0))};
EXPECT_VERIFIES(data);
}
......@@ -957,11 +884,11 @@ 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
SECTION(Element,
ENTRY_COUNT(1), // entry count
0, // table index
0, // offset
0) // number of elements
};
EXPECT_FAILURE(data);
......@@ -975,13 +902,13 @@ TEST_F(WasmModuleVerifyTest, Regression_735887) {
// funcs ---------------------------------------------------------------
ONE_EMPTY_FUNCTION(SIG_INDEX(0)),
// table declaration ---------------------------------------------------
SECTION(Table, 4), ENTRY_COUNT(1), kLocalAnyFunc, 0, 1,
SECTION(Table, ENTRY_COUNT(1), kLocalAnyFunc, 0, 1),
// elements ------------------------------------------------------------
SECTION(Element, 7),
1, // entry count
TABLE_INDEX(0), WASM_INIT_EXPR_I32V_1(0),
1, // elements count
0x9A // invalid I32V as function index
SECTION(Element,
ENTRY_COUNT(1), // entry count
TABLE_INDEX(0), WASM_INIT_EXPR_I32V_1(0),
1, // elements count
0x9A) // invalid I32V as function index
};
EXPECT_FAILURE(data);
......@@ -994,13 +921,13 @@ TEST_F(WasmModuleVerifyTest, OneIndirectFunction_one_entry) {
// funcs ---------------------------------------------------------------
ONE_EMPTY_FUNCTION(SIG_INDEX(0)),
// table declaration ---------------------------------------------------
SECTION(Table, 4), ENTRY_COUNT(1), kLocalAnyFunc, 0, 1,
SECTION(Table, ENTRY_COUNT(1), kLocalAnyFunc, 0, 1),
// elements ------------------------------------------------------------
SECTION(Element, 7),
1, // entry count
TABLE_INDEX(0), WASM_INIT_EXPR_I32V_1(0),
1, // elements count
FUNC_INDEX(0)};
SECTION(Element,
ENTRY_COUNT(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));
EXPECT_OK(result);
......@@ -1015,27 +942,27 @@ TEST_F(WasmModuleVerifyTest, OneIndirectFunction_one_entry) {
TEST_F(WasmModuleVerifyTest, MultipleIndirectFunctions) {
static const byte data[] = {
// sig#0 -------------------------------------------------------
SECTION(Type, 1 + SIZEOF_SIG_ENTRY_v_v + SIZEOF_SIG_ENTRY_v_x),
2, // --
SIG_ENTRY_v_v, // void -> void
SIG_ENTRY_v_x(kLocalI32), // void -> i32
SECTION(Type,
ENTRY_COUNT(2), // --
SIG_ENTRY_v_v, // void -> void
SIG_ENTRY_v_x(kLocalI32)), // void -> i32
// funcs ------------------------------------------------------
FOUR_EMPTY_FUNCTIONS(SIG_INDEX(0)),
// table declaration -------------------------------------------
SECTION(Table, 4), ENTRY_COUNT(1), kLocalAnyFunc, 0, 8,
SECTION(Table, ENTRY_COUNT(1), kLocalAnyFunc, 0, 8),
// 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), // --
SECTION(Element,
ENTRY_COUNT(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)), // --
FOUR_EMPTY_BODIES};
ModuleResult result = DecodeModule(data, data + sizeof(data));
......@@ -1058,21 +985,21 @@ TEST_F(WasmModuleVerifyTest, ElementSectionMultipleTables) {
// funcs ---------------------------------------------------------------
ONE_EMPTY_FUNCTION(SIG_INDEX(0)),
// table declaration ---------------------------------------------------
SECTION(Table, 7), ENTRY_COUNT(2), // section header
kLocalAnyFunc, 0, 5, // table 0
kLocalAnyFunc, 0, 9, // table 1
SECTION(Table, 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
SECTION(Element,
ENTRY_COUNT(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);
......@@ -1086,50 +1013,50 @@ TEST_F(WasmModuleVerifyTest, ElementSectionMixedTables) {
// 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
SECTION(Import, 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(SIG_INDEX(0)),
// table declaration ---------------------------------------------------
SECTION(Table, 7), ENTRY_COUNT(2), // section header
kLocalAnyFunc, 0, 15, // table 0
kLocalAnyFunc, 0, 19, // table 1
SECTION(Table, 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
SECTION(Element,
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);
......@@ -1145,25 +1072,25 @@ TEST_F(WasmModuleVerifyTest, ElementSectionMultipleTablesArbitraryOrder) {
// funcs ---------------------------------------------------------------
ONE_EMPTY_FUNCTION(SIG_INDEX(0)),
// table declaration ---------------------------------------------------
SECTION(Table, 7), ENTRY_COUNT(2), // section header
kLocalAnyFunc, 0, 5, // table 0
kLocalAnyFunc, 0, 9, // table 1
SECTION(Table, 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
SECTION(Element,
ENTRY_COUNT(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);
......@@ -1177,50 +1104,50 @@ TEST_F(WasmModuleVerifyTest, ElementSectionMixedTablesArbitraryOrder) {
// 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
SECTION(Import, 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(SIG_INDEX(0)),
// table declaration ---------------------------------------------------
SECTION(Table, 7), ENTRY_COUNT(2), // section header
kLocalAnyFunc, 0, 15, // table 0
kLocalAnyFunc, 0, 19, // table 1
SECTION(Table, 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
SECTION(Element,
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);
......@@ -1236,21 +1163,21 @@ TEST_F(WasmModuleVerifyTest, ElementSectionDontInitAnyRefTable) {
// funcs ---------------------------------------------------------------
ONE_EMPTY_FUNCTION(SIG_INDEX(0)),
// table declaration ---------------------------------------------------
SECTION(Table, 7), ENTRY_COUNT(2), // section header
kLocalAnyRef, 0, 5, // table 0
kLocalAnyFunc, 0, 9, // table 1
SECTION(Table, 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
SECTION(Element,
ENTRY_COUNT(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);
......@@ -1264,41 +1191,41 @@ TEST_F(WasmModuleVerifyTest, ElementSectionDontInitAnyRefImportedTable) {
// 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
SECTION(Import, 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(SIG_INDEX(0)),
// table declaration ---------------------------------------------------
SECTION(Table, 7), ENTRY_COUNT(2), // section header
kLocalAnyFunc, 0, 15, // table 0
kLocalAnyFunc, 0, 19, // table 1
SECTION(Table, 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
SECTION(Element,
ENTRY_COUNT(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);
......@@ -1309,8 +1236,7 @@ TEST_F(WasmModuleVerifyTest, IndirectFunctionNoFunctions) {
// sig#0 -------------------------------------------------------
SIGNATURES_SECTION_VOID_VOID,
// indirect table ----------------------------------------------
SECTION(Table, 4), ENTRY_COUNT(1), 1, 0, 0,
};
SECTION(Table, ENTRY_COUNT(1), 1, 0, 0)};
EXPECT_FAILURE(data);
}
......@@ -1322,22 +1248,21 @@ TEST_F(WasmModuleVerifyTest, IndirectFunctionInvalidIndex) {
// functions ---------------------------------------------------
ONE_EMPTY_FUNCTION(SIG_INDEX(0)),
// indirect table ----------------------------------------------
SECTION(Table, 4), ENTRY_COUNT(1), 1, 1, 0,
};
SECTION(Table, ENTRY_COUNT(1), 1, 1, 0)};
EXPECT_FAILURE(data);
}
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
SECTION(Table, // 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);
}
......@@ -1345,14 +1270,14 @@ TEST_F(WasmModuleVerifyTest, MultipleTablesWithoutFlag) {
TEST_F(WasmModuleVerifyTest, MultipleTablesWithFlag) {
WASM_FEATURE_SCOPE(anyref);
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
SECTION(Table, // 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));
......@@ -1683,11 +1608,10 @@ TEST_F(WasmModuleVerifyTest, UnknownSectionSkipped) {
static const byte data[] = {
UNKNOWN_SECTION(1),
0, // one byte section
SECTION(Global, 6),
1,
kLocalI32, // memory type
0, // exported
WASM_INIT_EXPR_I32V_1(33), // init
SECTION(Global, ENTRY_COUNT(1),
kLocalI32, // memory type
0, // exported
WASM_INIT_EXPR_I32V_1(33)), // init
};
ModuleResult result = DecodeModule(data, data + sizeof(data));
EXPECT_OK(result);
......@@ -1703,12 +1627,13 @@ TEST_F(WasmModuleVerifyTest, UnknownSectionSkipped) {
}
TEST_F(WasmModuleVerifyTest, ImportTable_empty) {
static const byte data[] = {SECTION(Type, 1), 0, SECTION(Import, 1), 0};
static const byte data[] = {SECTION(Type, ENTRY_COUNT(0)),
SECTION(Import, ENTRY_COUNT(0))};
EXPECT_VERIFIES(data);
}
TEST_F(WasmModuleVerifyTest, ImportTable_nosigs1) {
static const byte data[] = {SECTION(Import, 1), 0};
static const byte data[] = {SECTION(Import, ENTRY_COUNT(0))};
EXPECT_VERIFIES(data);
}
......@@ -1716,29 +1641,29 @@ TEST_F(WasmModuleVerifyTest, ImportTable_mutable_global) {
WASM_FEATURE_SCOPE(mut_global);
{
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
SECTION(Import, // section header
ENTRY_COUNT(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
SECTION(Import, // section header
ENTRY_COUNT(1), // sig table
NAME_LENGTH(1), // --
'm', // module name
NAME_LENGTH(1), // --
'f', // global name
kExternalGlobal, // import kind
kLocalI32, // type
1), // mutability
};
EXPECT_VERIFIES(data);
}
......@@ -1747,38 +1672,38 @@ TEST_F(WasmModuleVerifyTest, ImportTable_mutable_global) {
TEST_F(WasmModuleVerifyTest, ImportTable_mutability_malformed) {
WASM_FEATURE_SCOPE(mut_global);
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
SECTION(Import,
ENTRY_COUNT(1), // --
NAME_LENGTH(1), // --
'm', // module name
NAME_LENGTH(1), // --
'g', // global name
kExternalGlobal, // import kind
kLocalI32, // type
2), // invalid mutability
};
EXPECT_FAILURE(data);
}
TEST_F(WasmModuleVerifyTest, ImportTable_nosigs2) {
static const byte data[] = {
SECTION(Import, 6), 1, // sig table
NAME_LENGTH(1), 'm', // module name
NAME_LENGTH(1), 'f', // function name
kExternalFunction, // import kind
SIG_INDEX(0), // sig index
SECTION(Import, ENTRY_COUNT(1), // sig table
NAME_LENGTH(1), 'm', // module name
NAME_LENGTH(1), 'f', // function name
kExternalFunction, // import kind
SIG_INDEX(0)), // sig index
};
EXPECT_FAILURE(data);
}
TEST_F(WasmModuleVerifyTest, ImportTable_invalid_sig) {
static const byte data[] = {
SECTION(Type, 1), 0, // --
SECTION(Import, 6), 1, // --
NAME_LENGTH(1), 'm', // module name
NAME_LENGTH(1), 'f', // function name
kExternalFunction, // import kind
SIG_INDEX(0), // sig index
SECTION(Type, ENTRY_COUNT(0)), // --
SECTION(Import, ENTRY_COUNT(1), // --
NAME_LENGTH(1), 'm', // module name
NAME_LENGTH(1), 'f', // function name
kExternalFunction, // import kind
SIG_INDEX(0)), // sig index
};
EXPECT_FAILURE(data);
}
......@@ -1787,14 +1712,14 @@ TEST_F(WasmModuleVerifyTest, ImportTable_one_sig) {
static const byte data[] = {
// signatures
SIGNATURES_SECTION_VOID_VOID,
SECTION(Import, 7),
1, // --
NAME_LENGTH(1),
'm', // module name
NAME_LENGTH(1),
'f', // function name
kExternalFunction, // import kind
SIG_INDEX(0), // sig index
SECTION(Import,
ENTRY_COUNT(1), // --
NAME_LENGTH(1),
'm', // module name
NAME_LENGTH(1),
'f', // function name
kExternalFunction, // import kind
SIG_INDEX(0)), // sig index
};
EXPECT_VERIFIES(data);
}
......@@ -1803,13 +1728,14 @@ TEST_F(WasmModuleVerifyTest, ImportTable_invalid_module) {
static const byte data[] = {
// signatures
SIGNATURES_SECTION_VOID_VOID, // --
SECTION(Import, 7), // --
1, // --
NO_NAME, // module name
NAME_LENGTH(1), // --
'f', // function name
kExternalFunction, // import kind
SIG_INDEX(0), // sig index
SECTION(Import, // --
ENTRY_COUNT(1), // --
NO_NAME, // module name
NAME_LENGTH(1), // --
'f', // function name
kExternalFunction, // import kind
SIG_INDEX(0), // sig index
0), // auxiliary data
};
EXPECT_FAILURE(data);
}
......@@ -1818,14 +1744,12 @@ TEST_F(WasmModuleVerifyTest, ImportTable_off_end) {
static const byte data[] = {
// signatures
SIGNATURES_SECTION_VOID_VOID,
SECTION(Import, 6),
1,
NAME_LENGTH(1),
'm', // module name
NAME_LENGTH(1),
'f', // function name
kExternalFunction, // import kind
SIG_INDEX(0), // sig index
SECTION(Import, ENTRY_COUNT(1), NAME_LENGTH(1),
'm', // module name
NAME_LENGTH(1),
'f', // function name
kExternalFunction), // import kind
SIG_INDEX(0), // sig index (outside import section!)
};
EXPECT_OFF_END_FAILURE(data, arraysize(data) - 3);
......@@ -1835,8 +1759,7 @@ TEST_F(WasmModuleVerifyTest, ExportTable_empty1) {
static const byte data[] = { // signatures
SIGNATURES_SECTION_VOID_VOID, // --
ONE_EMPTY_FUNCTION(SIG_INDEX(0)),
SECTION(Export, 1), // --
0, // --
SECTION(Export, ENTRY_COUNT(0)), // --
ONE_EMPTY_BODY};
ModuleResult result = DecodeModule(data, data + sizeof(data));
......@@ -1847,27 +1770,26 @@ TEST_F(WasmModuleVerifyTest, ExportTable_empty1) {
}
TEST_F(WasmModuleVerifyTest, ExportTable_empty2) {
static const byte data[] = {
SECTION(Type, 1), 0, SECTION(Export, 1), 0 // --
};
static const byte data[] = {SECTION(Type, ENTRY_COUNT(0)),
SECTION(Export, ENTRY_COUNT(0))};
EXPECT_VERIFIES(data);
}
TEST_F(WasmModuleVerifyTest, ExportTable_NoFunctions2) {
static const byte data[] = {SECTION(Export, 1), 0};
static const byte data[] = {SECTION(Export, ENTRY_COUNT(0))};
EXPECT_VERIFIES(data);
}
TEST_F(WasmModuleVerifyTest, ExportTableOne) {
static const byte data[] = {// signatures
SIGNATURES_SECTION_VOID_VOID,
ONE_EMPTY_FUNCTION(SIG_INDEX(0)),
SECTION(Export, 4),
1, // exports
NO_NAME, // --
kExternalFunction, // --
FUNC_INDEX(0), // --
ONE_EMPTY_BODY};
static const byte data[] = {
// signatures
SIGNATURES_SECTION_VOID_VOID, ONE_EMPTY_FUNCTION(SIG_INDEX(0)),
SECTION(Export,
ENTRY_COUNT(1), // exports
NO_NAME, // --
kExternalFunction, // --
FUNC_INDEX(0)), // --
ONE_EMPTY_BODY};
ModuleResult result = DecodeModule(data, data + sizeof(data));
EXPECT_OK(result);
......@@ -1876,39 +1798,34 @@ TEST_F(WasmModuleVerifyTest, ExportTableOne) {
}
TEST_F(WasmModuleVerifyTest, ExportNameWithInvalidStringLength) {
static const byte data[] = {// signatures
SIGNATURES_SECTION_VOID_VOID,
ONE_EMPTY_FUNCTION(SIG_INDEX(0)),
SECTION(Export, 12),
1, // exports
NAME_LENGTH(84), // invalid string length
'e', // --
kExternalFunction, // --
FUNC_INDEX(0)};
static const byte data[] = {
// signatures
SIGNATURES_SECTION_VOID_VOID, ONE_EMPTY_FUNCTION(SIG_INDEX(0)),
SECTION(Export,
ENTRY_COUNT(1), // exports
NAME_LENGTH(84), // invalid string length
'e', // --
kExternalFunction, // --
FUNC_INDEX(0), // --
0, 0, 0) // auxiliary data
};
EXPECT_FAILURE(data);
}
TEST_F(WasmModuleVerifyTest, ExportTableTwo) {
static const byte data[] = {// signatures
SIGNATURES_SECTION_VOID_VOID,
ONE_EMPTY_FUNCTION(SIG_INDEX(0)),
SECTION(Export, 14),
2, // exports
NAME_LENGTH(4),
'n',
'a',
'm',
'e', // --
kExternalFunction,
FUNC_INDEX(0), // --
NAME_LENGTH(3),
'n',
'o',
'm', // --
kExternalFunction, // --
FUNC_INDEX(0), // --
ONE_EMPTY_BODY};
static const byte data[] = {
// signatures
SIGNATURES_SECTION_VOID_VOID, ONE_EMPTY_FUNCTION(SIG_INDEX(0)),
SECTION(Export,
ENTRY_COUNT(2), // exports
NAME_LENGTH(4), 'n', 'a', 'm', 'e', // --
kExternalFunction,
FUNC_INDEX(0), // --
NAME_LENGTH(3), 'n', 'o', 'm', // --
kExternalFunction, // --
FUNC_INDEX(0)), // --
ONE_EMPTY_BODY};
ModuleResult result = DecodeModule(data, data + sizeof(data));
EXPECT_OK(result);
......@@ -1918,24 +1835,24 @@ TEST_F(WasmModuleVerifyTest, ExportTableTwo) {
}
TEST_F(WasmModuleVerifyTest, ExportTableThree) {
static const byte data[] = {// signatures
SIGNATURES_SECTION_VOID_VOID,
THREE_EMPTY_FUNCTIONS(SIG_INDEX(0)),
SECTION(Export, 13),
3, // exports
NAME_LENGTH(1),
'a', // --
kExternalFunction,
FUNC_INDEX(0), // --
NAME_LENGTH(1),
'b', // --
kExternalFunction,
FUNC_INDEX(1), // --
NAME_LENGTH(1),
'c', // --
kExternalFunction,
FUNC_INDEX(2), // --
THREE_EMPTY_BODIES};
static const byte data[] = {
// signatures
SIGNATURES_SECTION_VOID_VOID, THREE_EMPTY_FUNCTIONS(SIG_INDEX(0)),
SECTION(Export,
ENTRY_COUNT(3), // exports
NAME_LENGTH(1),
'a', // --
kExternalFunction,
FUNC_INDEX(0), // --
NAME_LENGTH(1),
'b', // --
kExternalFunction,
FUNC_INDEX(1), // --
NAME_LENGTH(1),
'c', // --
kExternalFunction,
FUNC_INDEX(2)), // --
THREE_EMPTY_BODIES};
ModuleResult result = DecodeModule(data, data + sizeof(data));
EXPECT_OK(result);
......@@ -1945,17 +1862,15 @@ TEST_F(WasmModuleVerifyTest, ExportTableThree) {
TEST_F(WasmModuleVerifyTest, ExportTableThreeOne) {
for (int i = 0; i < 6; i++) {
const byte data[] = {// signatures
SIGNATURES_SECTION_VOID_VOID,
THREE_EMPTY_FUNCTIONS(SIG_INDEX(0)),
SECTION(Export, 6),
1, // exports
NAME_LENGTH(2),
'e',
'x', // --
kExternalFunction,
FUNC_INDEX(i), // --
THREE_EMPTY_BODIES};
const byte data[] = {
// signatures
SIGNATURES_SECTION_VOID_VOID, THREE_EMPTY_FUNCTIONS(SIG_INDEX(0)),
SECTION(Export,
ENTRY_COUNT(1), // exports
NAME_LENGTH(2), 'e', 'x', // --
kExternalFunction,
FUNC_INDEX(i)), // --
THREE_EMPTY_BODIES};
if (i < 3) {
EXPECT_VERIFIES(data);
......@@ -1968,23 +1883,21 @@ TEST_F(WasmModuleVerifyTest, ExportTableThreeOne) {
TEST_F(WasmModuleVerifyTest, ExportTableOne_off_end) {
static const byte data[] = {
// signatures
SIGNATURES_SECTION_VOID_VOID,
ONE_EMPTY_FUNCTION(SIG_INDEX(0)),
SECTION(Export, 1 + 6),
1, // exports
NO_NAME, // --
kExternalFunction,
FUNC_INDEX(0), // --
SIGNATURES_SECTION_VOID_VOID, ONE_EMPTY_FUNCTION(SIG_INDEX(0)),
SECTION(Export,
ENTRY_COUNT(1), // exports
NO_NAME, // --
kExternalFunction,
FUNC_INDEX(0), // --
0, 0, 0) // auxiliary data
};
EXPECT_OFF_END_FAILURE(data, arraysize(data) - 3);
}
TEST_F(WasmModuleVerifyTest, FunctionSignatures_empty) {
static const byte data[] = {
SECTION(Type, 1), 0, // --
SECTION(Function, 1), 0 // --
}; // --
static const byte data[] = {SECTION(Type, ENTRY_COUNT(0)),
SECTION(Function, ENTRY_COUNT(0))};
EXPECT_VERIFIES(data);
}
......@@ -1998,10 +1911,9 @@ TEST_F(WasmModuleVerifyTest, FunctionSignatures_one) {
TEST_F(WasmModuleVerifyTest, Regression_648070) {
static const byte data[] = {
SECTION(Type, 1), 0, // --
SECTION(Function, 5), // --
U32V_5(3500228624) // function count = 3500228624
}; // --
SECTION(Type, ENTRY_COUNT(0)), // --
SECTION(Function, U32V_5(3500228624)) // function count = 3500228624
}; // --
EXPECT_FAILURE(data);
}
......@@ -2010,10 +1922,10 @@ TEST_F(WasmModuleVerifyTest, Regression_738097) {
static const byte data[] = {
SIGNATURES_SECTION(1, SIG_ENTRY_v_v), // --
FUNCTION_SIGNATURES_SECTION(1, 0), // --
SECTION(Code, 1 + 5 + 1), // --
1, // --
U32V_5(0xFFFFFFFF), // function size,
0 // No real body
SECTION(Code, // --
ENTRY_COUNT(1), // --
U32V_5(0xFFFFFFFF), // function size,
0) // No real body
};
EXPECT_FAILURE(data);
}
......@@ -2054,40 +1966,36 @@ TEST_F(WasmModuleVerifyTest, FunctionBodies_empty) {
TEST_F(WasmModuleVerifyTest, FunctionBodies_one_empty) {
static const byte data[] = {
SIGNATURES_SECTION(1, SIG_ENTRY_v_v), // --
FUNCTION_SIGNATURES_SECTION(1, 0), // --
SECTION(Code, 1 + SIZEOF_EMPTY_BODY), 1, EMPTY_BODY // --
SIGNATURES_SECTION(1, SIG_ENTRY_v_v), // --
FUNCTION_SIGNATURES_SECTION(1, 0), // --
SECTION(Code, ENTRY_COUNT(1), EMPTY_BODY) // --
};
EXPECT_VERIFIES(data);
}
TEST_F(WasmModuleVerifyTest, FunctionBodies_one_nop) {
static const byte data[] = {
SIGNATURES_SECTION(1, SIG_ENTRY_v_v), // --
FUNCTION_SIGNATURES_SECTION(1, 0), // --
SECTION(Code, 1 + SIZEOF_NOP_BODY), 1, NOP_BODY // --
SIGNATURES_SECTION(1, SIG_ENTRY_v_v), // --
FUNCTION_SIGNATURES_SECTION(1, 0), // --
SECTION(Code, ENTRY_COUNT(1), NOP_BODY) // --
};
EXPECT_VERIFIES(data);
}
TEST_F(WasmModuleVerifyTest, FunctionBodies_count_mismatch1) {
static const byte data[] = {
SIGNATURES_SECTION(1, SIG_ENTRY_v_v), // --
FUNCTION_SIGNATURES_SECTION(2, 0, 0), // --
SECTION(Code, 1 + SIZEOF_EMPTY_BODY), 1, // --
EMPTY_BODY // --
SIGNATURES_SECTION(1, SIG_ENTRY_v_v), // --
FUNCTION_SIGNATURES_SECTION(2, 0, 0), // --
SECTION(Code, ENTRY_COUNT(1), EMPTY_BODY) // --
};
EXPECT_FAILURE(data);
}
TEST_F(WasmModuleVerifyTest, FunctionBodies_count_mismatch2) {
static const byte data[] = {
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 // --
SIGNATURES_SECTION(1, SIG_ENTRY_v_v), // --
FUNCTION_SIGNATURES_SECTION(1, 0), // --
SECTION(Code, ENTRY_COUNT(2), NOP_BODY, NOP_BODY) // --
};
EXPECT_FAILURE(data);
}
......@@ -2100,53 +2008,45 @@ TEST_F(WasmModuleVerifyTest, Names_empty) {
}
TEST_F(WasmModuleVerifyTest, Names_one_empty) {
// TODO(wasm): This test does not test anything (corrupt name section does not
// fail validation).
static const byte data[] = {
SIGNATURES_SECTION(1, SIG_ENTRY_v_v), // --
FUNCTION_SIGNATURES_SECTION(1, 0), // --
SECTION(Code, 1 + SIZEOF_EMPTY_BODY),
ENTRY_COUNT(1),
EMPTY_BODY, // --
SECTION_NAMES(1 + 5),
ENTRY_COUNT(1),
FOO_STRING,
NO_LOCAL_NAMES // --
SIGNATURES_SECTION(1, SIG_ENTRY_v_v), // --
FUNCTION_SIGNATURES_SECTION(1, 0), // --
SECTION(Code, ENTRY_COUNT(1), EMPTY_BODY), // --
SECTION_NAMES(ENTRY_COUNT(1), FOO_STRING, NO_LOCAL_NAMES) // --
};
EXPECT_VERIFIES(data);
}
TEST_F(WasmModuleVerifyTest, Names_two_empty) {
// TODO(wasm): This test does not test anything (corrupt name section does not
// fail validation).
static const byte data[] = {
SIGNATURES_SECTION(1, SIG_ENTRY_v_v), // --
FUNCTION_SIGNATURES_SECTION(2, 0, 0), // --
SECTION(Code, 1 + 2 * SIZEOF_EMPTY_BODY), // --
ENTRY_COUNT(2),
EMPTY_BODY,
EMPTY_BODY, // --
SECTION_NAMES(1 + 10),
ENTRY_COUNT(2), // --
FOO_STRING,
NO_LOCAL_NAMES, // --
FOO_STRING,
NO_LOCAL_NAMES, // --
SIGNATURES_SECTION(1, SIG_ENTRY_v_v), // --
FUNCTION_SIGNATURES_SECTION(2, 0, 0), // --
SECTION(Code, ENTRY_COUNT(2), EMPTY_BODY, EMPTY_BODY), // --
SECTION_NAMES(ENTRY_COUNT(2), // --
FOO_STRING, NO_LOCAL_NAMES, // --
FOO_STRING, NO_LOCAL_NAMES), // --
};
EXPECT_VERIFIES(data);
}
TEST_F(WasmModuleVerifyTest, Regression684855) {
static const byte data[] = {
SECTION_NAMES(12),
0xFB, // functions count
0x27, // |
0x00, // function name length
0xFF, // local names count
0xFF, // |
0xFF, // |
0xFF, // |
0xFF, // |
0xFF, // error: "varint too large"
0xFF, // |
0x00, // --
0x00 // --
SECTION_NAMES(0xFB, // functions count
0x27, // |
0x00, // function name length
0xFF, // local names count
0xFF, // |
0xFF, // |
0xFF, // |
0xFF, // |
0xFF, // error: "varint too large"
0xFF, // |
0x00, // --
0x00) // --
};
EXPECT_VERIFIES(data);
}
......@@ -2222,15 +2122,15 @@ TEST_F(WasmInitExprDecodeTest, InitExpr_illegal) {
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, // --
SECTION(Unknown, 1, 'X', 17, 18),
SECTION(Unknown, 3, 'f', 'o', 'o', 5, 6, 7, 8, 9),
SECTION(Unknown, 5, 'o', 't', 'h', 'e', 'r', 7, 8),
};
EXPECT_VERIFIES(data);
}
TEST_F(WasmModuleVerifyTest, Section_Name_No_UTF8) {
static const byte data[] = {SECTION(Unknown, 4), 1, 0xFF, 17, 18};
static const byte data[] = {SECTION(Unknown, 1, 0xFF, 17, 18)};
EXPECT_FAILURE(data);
}
......@@ -2260,11 +2160,11 @@ class WasmModuleCustomSectionTest : public TestWithIsolateAndZone {
TEST_F(WasmModuleCustomSectionTest, ThreeUnknownSections) {
static constexpr byte data[] = {
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, // --
U32_LE(kWasmMagic), // --
U32_LE(kWasmVersion), // --
SECTION(Unknown, 1, 'X', 17, 18), // --
SECTION(Unknown, 3, 'f', 'o', 'o', 5, 6, 7, 8, 9), // --
SECTION(Unknown, 5, 'o', 't', 'h', 'e', 'r', 7, 8), // --
};
static const CustomSectionOffset expected[] = {
......@@ -2282,21 +2182,9 @@ TEST_F(WasmModuleCustomSectionTest, TwoKnownTwoUnknownSections) {
U32_LE(kWasmMagic), // --
U32_LE(kWasmVersion), // --
SIGNATURES_SECTION(2, SIG_ENTRY_v_v, SIG_ENTRY_v_v), // --
SECTION(Unknown, 4),
1,
'X',
17,
18, // --
SECTION(Unknown, 1, 'X', 17, 18), // --
ONE_EMPTY_FUNCTION(SIG_INDEX(0)),
SECTION(Unknown, 8),
5,
'o',
't',
'h',
'e',
'r',
7,
8, // --
SECTION(Unknown, 5, 'o', 't', 'h', 'e', 'r', 7, 8), // --
};
static const CustomSectionOffset expected[] = {
......@@ -2313,7 +2201,7 @@ TEST_F(WasmModuleCustomSectionTest, TwoKnownTwoUnknownSections) {
'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};
static const byte data[] = {SECTION(Unknown, SRC_MAP, 9, SRC)};
ModuleResult result = DecodeModule(data, data + sizeof(data));
EXPECT_TRUE(result.ok());
EXPECT_EQ(9u, result.val->source_map_url.size());
......@@ -2327,7 +2215,7 @@ TEST_F(WasmModuleVerifyTest, SourceMappingURLSection) {
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};
static const byte data[] = {SECTION(Unknown, 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());
......@@ -2336,16 +2224,8 @@ TEST_F(WasmModuleVerifyTest, BadSourceMappingURLSection) {
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'};
static const byte data[] = {SECTION(Unknown, SRC_MAP, 3, SRC),
SECTION(Unknown, 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());
......@@ -2360,23 +2240,9 @@ TEST_F(WasmModuleVerifyTest, MultipleSourceMappingURLSections) {
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'};
static const byte data[] = {
SECTION(Unknown, NAME_SECTION, 0, 4, 3, 'a', 'b', 'c'),
SECTION(Unknown, 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());
......@@ -2404,6 +2270,9 @@ TEST_F(WasmModuleVerifyTest, MultipleNameSections) {
#undef SIZEOF_NOP_BODY
#undef SIG_ENTRY_i_i
#undef UNKNOWN_SECTION
#undef COUNT_ARGS
#undef CHECK_LEB1
#undef ADD_COUNT
#undef SECTION
#undef SIGNATURES_SECTION
#undef FUNCTION_SIGNATURES_SECTION
......@@ -2413,7 +2282,6 @@ TEST_F(WasmModuleVerifyTest, MultipleNameSections) {
#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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment