Skip to content

Commit ed9f106

Browse files
committed
Require in instantiate for imported memory size to be equal min limit
1 parent 35b5ff5 commit ed9f106

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

lib/fizzy/instantiate.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ void match_imported_memories(const std::vector<Memory>& module_imported_memories
121121

122122
const auto min = imported_memories[0].limits.min;
123123
const auto& max = imported_memories[0].limits.max;
124-
if (size < memory_pages_to_bytes(min) ||
124+
if (size != memory_pages_to_bytes(min) ||
125125
(max.has_value() && size > memory_pages_to_bytes(*max)))
126-
throw instantiate_error{"provided imported memory doesn't fit provided limits"};
126+
throw instantiate_error{"provided imported memory size must be equal to its min limit"};
127127
}
128128
}
129129

test/unittests/instantiate_test.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,12 @@ TEST(instantiate, imported_memory_invalid)
302302

303303
// Allocated less than min
304304
EXPECT_THROW_MESSAGE(instantiate(*module, {}, {}, {{&memory_empty, {1, 3}}}), instantiate_error,
305-
"provided imported memory doesn't fit provided limits");
305+
"provided imported memory size must be equal to its min limit");
306306

307-
// Allocated more than max
308-
bytes memory_big(PageSize * 4, 0);
309-
EXPECT_THROW_MESSAGE(instantiate(*module, {}, {}, {{&memory_big, {1, 3}}}), instantiate_error,
310-
"provided imported memory doesn't fit provided limits");
307+
// Allocated more than min but less than max
308+
bytes memory_two_pages(PageSize * 2, 0);
309+
EXPECT_THROW_MESSAGE(instantiate(*module, {}, {}, {{&memory_two_pages, {1, 3}}}),
310+
instantiate_error, "provided imported memory size must be equal to its min limit");
311311

312312
// Provided max exceeds the hard limit
313313
/* wat2wasm

0 commit comments

Comments
 (0)