Fix uninitialized memory references - #300
Merged
Merged
Conversation
Member
Does it really? That looks unrelated |
SimonSapin
approved these changes
Aug 19, 2026
SimonSapin
left a comment
Member
There was a problem hiding this comment.
Unfortunately miri doesn’t seem to find this problem on my machine, but uninitialized &mut [u8; 64] does look wrong so let’s fix it
❯ cargo +nightly miri -V
miri 0.1.0 (e71c0f1e33 2026-08-18)
Comment on lines
+3
to
+8
| #[test] | ||
| fn test_to_ascii_uppercase() { | ||
| let s = DefaultAtom::from("hello"); | ||
| let upper = s.to_ascii_uppercase(); | ||
| assert_eq!(&*upper, "HELLO"); | ||
| } |
Member
There was a problem hiding this comment.
This file is redundant with test_ascii_lowercase in integration-tests/src/lib.rs, isn’t it?
- Fix uninitialized memory reference UB in from_mutated_str. Creating a &mut [u8; 64] reference pointing to uninitialized bytes from MaybeUninit violates Rust's validity invariants. Replaced the slice cast with safe raw pointer arithmetic (ptr::copy_nonoverlapping) and slice creation over only the initialized portion of memory. - Refactor magic number 64 into a named const MAX_STACK_SIZE. - Add UB test case.
SimonSapin
force-pushed
the
fix-uninit-memory
branch
from
August 19, 2026 21:10
9d489a2 to
13a08c7
Compare
SimonSapin
enabled auto-merge
August 19, 2026 21:10
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.
Fixes #279
This PR resolves a critical memory safety issue in
Atom::from_mutated_str.Previously, the code did
&mut *buffer.as_mut_ptr()on aMaybeUninit<[u8; 64]>. Creating a mutable reference to uninitialized memory is instant Undefined Behavior in Rust, and it violated Stacked Borrows (caught by Miri).This is fixed by:
1. Using raw pointers (
buffer.as_mut_ptr()) andstd::ptr::copy_nonoverlappingto write to the buffer.2. Slicing only the initialized portion (
slice::from_raw_parts_mut) before creating the&mut strreference, ensuring we never create a reference to uninitialized bytes.