Skip to content

Fix large, backwards, memory.copy with fuel/epochs#13577

Merged
cfallin merged 1 commit into
bytecodealliance:mainfrom
alexcrichton:fix-chunked-big-copy
Jun 5, 2026
Merged

Fix large, backwards, memory.copy with fuel/epochs#13577
cfallin merged 1 commit into
bytecodealliance:mainfrom
alexcrichton:fix-chunked-big-copy

Conversation

@alexcrichton
Copy link
Copy Markdown
Member

This commit fixes a bug in the previous refactorings of memory.copy or other bulk copy instructions. Notably when fuel/epochs were enabled the operation was chunked up to check fuel between each operation, but the advancement of what to do unconditionally went forwards. When a backwards copy is required this means that data could get corrupted if the src/dst regions are overlapping. The fix here is to setup a separate backwards-copy loop which handles this case so the fuel/epoch-metered copy goes either backwards or forwards depending on what's being copied.

This commit fixes a bug in the previous refactorings of `memory.copy` or
other bulk copy instructions. Notably when fuel/epochs were enabled the
operation was chunked up to check fuel between each operation, but the
advancement of what to do unconditionally went forwards. When a
backwards copy is required this means that data could get corrupted if
the src/dst regions are overlapping. The fix here is to setup a separate
backwards-copy loop which handles this case so the fuel/epoch-metered
copy goes either backwards or forwards depending on what's being copied.
@alexcrichton alexcrichton requested review from a team as code owners June 5, 2026 22:37
@alexcrichton alexcrichton requested review from cfallin and removed request for a team June 5, 2026 22:37
Copy link
Copy Markdown
Member

@cfallin cfallin left a comment

Choose a reason for hiding this comment

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

Thanks!

@cfallin cfallin added this pull request to the merge queue Jun 5, 2026
Merged via the queue into bytecodealliance:main with commit 40ac363 Jun 5, 2026
51 checks passed
alexcrichton added a commit that referenced this pull request Jun 6, 2026
* Fix large, backwards, `memory.copy` with fuel/epochs (#13577)

This commit fixes a bug in the previous refactorings of `memory.copy` or
other bulk copy instructions. Notably when fuel/epochs were enabled the
operation was chunked up to check fuel between each operation, but the
advancement of what to do unconditionally went forwards. When a
backwards copy is required this means that data could get corrupted if
the src/dst regions are overlapping. The fix here is to setup a separate
backwards-copy loop which handles this case so the fuel/epoch-metered
copy goes either backwards or forwards depending on what's being copied.

* Fix corrupted pooling allocator state on OOM (#13579)

This commit fixes an issue where if the pooling allocator generated OOM
at just the right time then it would leave the pooling allocator in a
corrupt state where the instance count was incremented, never
decremented. This additionally fixes a separate issue where if an OOM
happened just a bit later then it would mean that tables/memories from
the pooling allocator would leak and not be properly destroyed within
the allocator, leaking their slots.
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