Skip to content
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

Handle negative grow pages to avoid shrinking memory #2120

Merged
merged 1 commit into from
Mar 5, 2024

Conversation

mathetake
Copy link
Member

@mathetake mathetake commented Mar 5, 2024

This has existed for the very long time but thanks to the wazevo's aggressive bounds check
optimization, this has surfaced just now through fuzzing. I would say this is one of the most
terrible (yet not harmful in practice) bugs in the history of wazero...

@mathetake mathetake marked this pull request as ready for review March 5, 2024 11:27
@mathetake mathetake requested a review from evacchi as a code owner March 5, 2024 11:27
@mathetake mathetake merged commit dea07e2 into main Mar 5, 2024
62 of 66 checks passed
@mathetake mathetake deleted the accidentalyshrink branch March 5, 2024 11:32
@@ -256,7 +256,7 @@ func (m *MemoryInstance) Grow(delta uint32) (result uint32, ok bool) {

// If exceeds the max of memory size, we push -1 according to the spec.
newPages := currentPages + delta
if newPages > m.Max {
if newPages > m.Max || int32(delta) < 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't newPages > m.Max || newPages < currentPages be clearer, or am I misunderstanding it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah clearer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants