Skip to content

Commit 52defb1

Browse files
committed
Add check to instantiate for imported memory/table limits validity
1 parent 22fc4f7 commit 52defb1

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

lib/fizzy/instantiate.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ void match_imported_functions(const std::vector<FuncType>& module_imported_types
4040

4141
void match_limits(const Limits& external_limits, const Limits& module_limits)
4242
{
43+
if (external_limits.max.has_value() && external_limits.min > *external_limits.max)
44+
throw instantiate_error{"provided import's min limit is above import's max limit"};
45+
4346
if (external_limits.min < module_limits.min)
4447
throw instantiate_error{"provided import's min is below import's min defined in module"};
4548

test/unittests/instantiate_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ TEST(instantiate, imported_table_invalid)
179179

180180
// Provided limits have max less than min
181181
EXPECT_THROW_MESSAGE(instantiate(*module, {}, {{&table, {10, 0}}}), instantiate_error,
182-
"provided imported table doesn't fit provided limits");
182+
"provided import's min limit is above import's max limit");
183183

184184
// Null pointer
185185
EXPECT_THROW_MESSAGE(instantiate(*module, {}, {{nullptr, {10, 30}}}), instantiate_error,
@@ -289,7 +289,7 @@ TEST(instantiate, imported_memory_invalid)
289289

290290
// Provided limits have max less than min
291291
EXPECT_THROW_MESSAGE(instantiate(*module, {}, {}, {{&memory, {1, 0}}}), instantiate_error,
292-
"provided imported memory doesn't fit provided limits");
292+
"provided import's min limit is above import's max limit");
293293

294294
// Null pointer
295295
EXPECT_THROW_MESSAGE(instantiate(*module, {}, {}, {{nullptr, {1, 3}}}), instantiate_error,

0 commit comments

Comments
 (0)