Skip to content

Commit 2f102ae

Browse files
authored
Merge pull request #762 from wasmx/imported-limits-check
Add explicit check for imported limits validity
2 parents 7e7d3bf + 52defb1 commit 2f102ae

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ TEST(instantiate, imported_table_invalid)
177177
EXPECT_THROW_MESSAGE(instantiate(*module, {}, {{&table, {10, std::nullopt}}}),
178178
instantiate_error, "provided import's max is above import's max defined in module");
179179

180+
// Provided limits have max less than min
181+
EXPECT_THROW_MESSAGE(instantiate(*module, {}, {{&table, {10, 0}}}), instantiate_error,
182+
"provided import's min limit is above import's max limit");
183+
180184
// Null pointer
181185
EXPECT_THROW_MESSAGE(instantiate(*module, {}, {{nullptr, {10, 30}}}), instantiate_error,
182186
"provided imported table has a null pointer to data");
@@ -283,6 +287,10 @@ TEST(instantiate, imported_memory_invalid)
283287
EXPECT_THROW_MESSAGE(instantiate(*module, {}, {}, {{&memory, {1, std::nullopt}}}),
284288
instantiate_error, "provided import's max is above import's max defined in module");
285289

290+
// Provided limits have max less than min
291+
EXPECT_THROW_MESSAGE(instantiate(*module, {}, {}, {{&memory, {1, 0}}}), instantiate_error,
292+
"provided import's min limit is above import's max limit");
293+
286294
// Null pointer
287295
EXPECT_THROW_MESSAGE(instantiate(*module, {}, {}, {{nullptr, {1, 3}}}), instantiate_error,
288296
"provided imported memory has a null pointer to data");

0 commit comments

Comments
 (0)