docs: auto-update for PR #2978 — fix(runtime): avoid aliasing &mut into guest memory (UB)#2985
Closed
meroreviewer[bot] wants to merge 1 commit into
Closed
docs: auto-update for PR #2978 — fix(runtime): avoid aliasing &mut into guest memory (UB)#2985meroreviewer[bot] wants to merge 1 commit into
meroreviewer[bot] wants to merge 1 commit into
Conversation
Contributor
Author
There was a problem hiding this comment.
🤖 AI Code Reviewer
Reviewed by 1 agents | Quality score: 85% | Review time: 135.0s
✅ No Issues Found
All agents reviewed the code and found no issues. LGTM! 🎉
🤖 Generated by AI Code Reviewer | Review ID: review-912b2c18
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Automatic Documentation Update
Opened automatically after PR #2978 merged.
Each block shows the documentation change as a diff (added lines in green, removed in red); expand "Why this changed" for the source rationale.
Documentation changes
architecture/crates/runtime.html— Removeread_guest_memory_slice_mutthat caused aliasing UB; Addwrite_guest_memory_slicefor safe copy-out into guest memory; Addcheck_guest_memory_boundsfor bounds validation without copying;random_bytesfills a host-side buffer before copying to guest; All write call sites updated to use copy-out pattern; Rename bounds-check test to reflect new APIWhy this changed (source: PR #2978)
read_guest_memory_slice_mutuseddata_unchecked_mutto produce a&mut [u8]into guest memory from a shared&self. Becauseread_guest_memory_slicecan hand out immutable&[u8]views over the same backing store, the two references could coexist and alias, violating Rust's aliasing rules (undefined behaviour). The function (and itsclippy::mut_from_refsuppression) is removed entirely.New method
write_guest_memory_slice(&self, slice: &sys::BufferMut, data: &[u8])copies caller-owned bytes into guest memory viawasmer::MemoryView::write. It bounds-checks both thatdatafits within the guest buffer and that the guest buffer fits within total memory, then delegates the actual write to Wasmer's safe API. No mutable reference into guest memory is ever created.New method
check_guest_memory_bounds(&self, slice: &sys::BufferMut)validates that a guest buffer's address range lies entirely within guest memory without performing any copy. It is used by callers that must verify writability before executing side effects, so that the side effects are not performed if the destination is invalid.Previously, random bytes were written directly into a
&mut [u8]aliasing guest memory. Nowcheck_guest_memory_boundsvalidates the destination first, a host-ownedVec<u8>is allocated and filled by the RNG, and thenwrite_guest_memory_slicecopies it into guest memory.read_register,time_now,blob_close, andblob_readall replaced theirread_guest_memory_slice_mut(...).copy_from_slice(data)patterns with calls towrite_guest_memory_slice.blob_closespecifically replaced a block that acquired and immediately dropped a mutable slice (solely for bounds checking) with a direct call tocheck_guest_memory_bounds.Test
test_read_guest_memory_slice_mut_out_of_boundsrenamed totest_check_guest_memory_bounds_out_of_boundsand updated to callcheck_guest_memory_boundsinstead of the removedread_guest_memory_slice_mut.Generated by
ai-reviewer update-docs. Nothing was auto-merged.