-
Notifications
You must be signed in to change notification settings - Fork 745
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
Fix memory.grow bounds and overflow checks for mem64 #7112
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3836,10 +3836,14 @@ class ModuleRunnerBase : public ExpressionRunner<SubType> { | |
auto fail = Literal::makeFromInt64(-1, memory->addressType); | ||
Flow ret = Literal::makeFromInt64(memorySize, addressType); | ||
uint64_t delta = flow.getSingleValue().getUnsigned(); | ||
if (delta > uint32_t(-1) / Memory::kPageSize && addressType == Type::i32) { | ||
uint64_t maxAddr = | ||
addressType == Type::i32 ? uint64_t(uint32_t(-1)) : uint64_t(-1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yuck, that is so much harder to read than There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Heh, I don't feel strongly. I guess it is more C++ey and can support all types and all bounds. But I wouldn't object to switching. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I get that binaryen is fully in on all the C++ things :) So lgtm either way, I just wish C++ wasn't so verbose sometimes. |
||
if (delta > maxAddr / Memory::kPageSize) { | ||
// Impossible to grow this much. | ||
return fail; | ||
} | ||
if (memorySize >= uint32_t(-1) - delta && addressType == Type::i32) { | ||
if (memorySize >= maxAddr - delta) { | ||
// Overflow. | ||
return fail; | ||
} | ||
auto newSize = memorySize + delta; | ||
|
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.
Strange there wan't event a TODO here!