Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion scripts/test/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,6 @@ def get_tests(test_dir, extensions=[], recursive=False):
'annotations.wast', # String annotations IDs should be allowed
'id.wast', # Empty IDs should be disallowed
'instance.wast', # Requires support for table default elements
'table64.wast', # Requires validations for table size
'tag.wast', # Non-empty tag results allowed by stack switching
'local_init.wast', # Requires local validation to respect unnamed blocks
'ref_func.wast', # Requires rejecting undeclared functions references
Expand Down
6 changes: 3 additions & 3 deletions src/tools/fuzzing/fuzzing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -912,13 +912,13 @@ void TranslateToFuzzReader::finalizeTable() {
// reasonable limit for the maximum table size.
//
// This also avoids an issue that arises from table->initial being an
// Address (64 bits) but Table::kMaxSize being an Index (32 bits), as a
// result of which we need to clamp to Table::kMaxSize as well in order for
// Address (64 bits) but Table::kMaxSize32 being an Index (32 bits), as a
// result of which we need to clamp to Table::kMaxSize32 as well in order for
// the module to validate (but since we are clamping to a smaller value,
// there is no need).
const Address ReasonableMaxTableSize = 10000;
table->initial = std::min(table->initial, ReasonableMaxTableSize);
assert(ReasonableMaxTableSize <= Table::kMaxSize);
assert(ReasonableMaxTableSize <= Table::kMaxSize32);

table->max = oneIn(2) ? Address(Table::kUnlimitedSize) : table->initial;

Expand Down
2 changes: 1 addition & 1 deletion src/wasm-builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class Builder {
Type type = Type(HeapType::func,
Nullable),
Address initial = 0,
Address max = Table::kMaxSize,
Address max = Table::kUnlimitedSize,
Type addressType = Type::i32) {
auto table = std::make_unique<Table>();
table->name = name;
Expand Down
12 changes: 7 additions & 5 deletions src/wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -2447,12 +2447,14 @@ class ElementSegment : public Named {
class Table : public Importable {
public:
static const Address::address32_t kPageSize = 1;
static const Index kUnlimitedSize = Index(-1);
// In wasm32/64, the maximum table size is limited by a 32-bit pointer: 4GB
static const Index kMaxSize = Index(-1);
static const Address::address64_t kUnlimitedSize = Address::address64_t(-1);

// The maximum table size is limited by a 32/64 bit index
static const Address::address32_t kMaxSize32 = Address::address32_t(-1);
static const Address::address64_t kMaxSize64 = Address::address64_t(-1);

Address initial = 0;
Address max = kMaxSize;
Address max = kUnlimitedSize;
Type addressType = Type::i32;
Type type = Type(HeapType::func, Nullable);

Expand All @@ -2461,7 +2463,7 @@ class Table : public Importable {
void clear() {
name = "";
initial = 0;
max = kMaxSize;
max = kUnlimitedSize;
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/wasm/wasm-binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5009,7 +5009,7 @@ void WasmBinaryReader::readTableDeclarations() {

void WasmBinaryReader::readElementSegments() {
auto num = getU32LEB();
if (num >= Table::kMaxSize) {
if (num >= Table::kMaxSize32) {
throwError("Too many segments");
}
std::unordered_set<Name> usedNames;
Expand Down
Loading