Skip to content
Merged
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
3 changes: 3 additions & 0 deletions lib/fizzy/instantiate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ void match_imported_functions(const std::vector<FuncType>& module_imported_types

void match_limits(const Limits& external_limits, const Limits& module_limits)
{
if (external_limits.max.has_value() && external_limits.min > *external_limits.max)
throw instantiate_error{"provided import's min limit is above import's max limit"};

if (external_limits.min < module_limits.min)
throw instantiate_error{"provided import's min is below import's min defined in module"};

Expand Down
8 changes: 8 additions & 0 deletions test/unittests/instantiate_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ TEST(instantiate, imported_table_invalid)
EXPECT_THROW_MESSAGE(instantiate(*module, {}, {{&table, {10, std::nullopt}}}),
instantiate_error, "provided import's max is above import's max defined in module");

// Provided limits have max less than min
EXPECT_THROW_MESSAGE(instantiate(*module, {}, {{&table, {10, 0}}}), instantiate_error,
"provided import's min limit is above import's max limit");

// Null pointer
EXPECT_THROW_MESSAGE(instantiate(*module, {}, {{nullptr, {10, 30}}}), instantiate_error,
"provided imported table has a null pointer to data");
Expand Down Expand Up @@ -283,6 +287,10 @@ TEST(instantiate, imported_memory_invalid)
EXPECT_THROW_MESSAGE(instantiate(*module, {}, {}, {{&memory, {1, std::nullopt}}}),
instantiate_error, "provided import's max is above import's max defined in module");

// Provided limits have max less than min
EXPECT_THROW_MESSAGE(instantiate(*module, {}, {}, {{&memory, {1, 0}}}), instantiate_error,
"provided import's min limit is above import's max limit");

// Null pointer
EXPECT_THROW_MESSAGE(instantiate(*module, {}, {}, {{nullptr, {1, 3}}}), instantiate_error,
"provided imported memory has a null pointer to data");
Expand Down