-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cap hard memory limit at 4GB #748
Conversation
Codecov Report
@@ Coverage Diff @@
## master #748 +/- ##
=======================================
Coverage 99.26% 99.26%
=======================================
Files 74 74
Lines 11448 11462 +14
=======================================
+ Hits 11364 11378 +14
Misses 84 84
Flags with carried forward coverage won't be shown. Click here to find out more.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "Rename MemoryPagesValidationLimit -> MemoryPagesMaxLimit" commit should go first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still considering using 0xffffffff
limit value for "unlimited". Not sure this change helps. Maybe it is better to report hard limit in parser?
What would it mean? Given that spec limits it at 4GB.
It helps to simplify
What does this mean, pass it to parser instead of instantiate? |
565247f
to
8d3569d
Compare
Using
Make modules with max higher than 4GB invalid. |
This doesn't seem related, it's about replacing
They are already invalid of course Lines 260 to 262 in 56ffca7
But modules with min/max higher than Fizzy's hard limit are not invalid, because we pass this limit to instantiate only. |
8d3569d
to
7d7bbfc
Compare
lib/fizzy/limits.hpp
Outdated
@@ -13,8 +13,8 @@ constexpr uint32_t PageSize = 65536; | |||
|
|||
/// The maximum memory page limit as defined by the specification. | |||
/// It is only possible to address 4 GB (32-bit) of memory. | |||
constexpr uint32_t MemoryPagesValidationLimit = (4 * 1024 * 1024 * 1024ULL) / PageSize; | |||
static_assert(MemoryPagesValidationLimit == 65536); | |||
constexpr uint32_t MemoryPagesMaxLimit = (4 * 1024 * 1024 * 1024ULL) / PageSize; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, I would change to MaxMemoryPagesLimit
/DefaultMemoryPagesLimit
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine to me too.
@@ -174,6 +174,13 @@ std::tuple<bytes_ptr, Limits> allocate_memory(const std::vector<Memory>& module_ | |||
static const auto bytes_delete = [](bytes* b) noexcept { delete b; }; | |||
static const auto null_delete = [](bytes*) noexcept {}; | |||
|
|||
if (memory_pages_limit > MemoryPagesMaxLimit) | |||
{ | |||
throw instantiate_error{"hard memory limit cannot exceed " + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gumb0 Is this now properly covered by spectests or you are planning to submit some cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not covered and can't be, as "hard memory limit" is not defined in any precise way in the spec, it's just an internal limit which can be arbitrary set by implementations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not easy to find, but you can get this information from codecov. You need to go to single commit view -> Files, and then only select "spectests" flag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not easy to find, but you can get this information from codecov.
I know, I went through that and listed the 10% missing cases in the chat last week. But that is only reflected if we upgrade out spectest branch, and we haven't done that in this PR :)
@@ -693,6 +694,12 @@ TEST(execute, memory_grow_custom_hard_limit) | |||
EXPECT_THAT(execute(*instance, 0, {input}), Result(expected)); | |||
} | |||
|
|||
{ | |||
const auto instance_huge_hard_limit = instantiate(*module, {}, {}, {}, {}, 65536); | |||
EXPECT_THAT(execute(*instance_huge_hard_limit, 0, {65536}), Result(-1)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the goal here? According to the other test, 65536 total is acceptable. Why don't we add something like instantiate with 0 and enlarge to 65536.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the goal here?
To test the check at high values of hard limit.
According to the other test, 65536 total is acceptable. Why don't we add something like instantiate with 0 and enlarge to 65536.
It would allocate 4GB, but I think we want to keep unit tests light-weight.
(there is a spec test that does this)
7d7bbfc
to
ebbc24f
Compare
bytes memory(PageSize, 0); | ||
const auto instance_huge_hard_limit = | ||
instantiate(*module_imported, {}, {}, {{&memory, {1, std::nullopt}}}, {}, 65536); | ||
EXPECT_THAT(execute(*instance_huge_hard_limit, 0, {65536}), Result(-1)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well perhaps leave a comment then here that we should test for increasing by 65535
but don't want to spend too much time in unittests (to allocate 4gb) as spectests covers it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I checked and there're no spec tests that allocate 4GB, only one that sets the upper limit to 4GB (but doesn't allocate anything).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is hard to test for it when VMs are allowed to return an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with this, though not 100% convinced our test cases are the best.
e936c1f
to
ebbc24f
Compare
ebbc24f
to
4484678
Compare
4484678
to
207741f
Compare
No description provided.