Fix UB: use || instead of && #7779
Merged
Manishearth merged 2 commits intounicode-org:mainfrom Mar 15, 2026
Merged
Conversation
…check The condition guarding `from_raw_parts` joined the alignment check and length check with `&&`, meaning the error was only returned when *both* were wrong. A misaligned-but-correctly-sized buffer passed the check, then `from_raw_parts` dereferences misaligned data — undefined behavior. Added tests that verify each condition is rejected independently. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Manishearth
approved these changes
Mar 14, 2026
Member
Manishearth
left a comment
There was a problem hiding this comment.
Nice catch, thanks! I'm pretty sure the tests can be written in a way that doesn't need unsafe but I'll look into that later.
Member
|
Please run |
Member
|
Oh and you'll have to sign the CLA unfortunately. |
Contributor
Author
|
Oh, I don't care about the CLA. It's 6pm here, I'll figure it out tomorrow. |
Member
|
Yeah you just have to go click a button on link on the failing ci task. |
auto-merge was automatically disabled
March 15, 2026 16:29
Head branch was pushed to by a user without write access
Contributor
Author
Maybe so, I never use it, so my knowledge is just from FFI wrappers and the Rust Book. |
Manishearth
approved these changes
Mar 15, 2026
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.
in cast_bytes_to_slice alignment/length check
The condition guarding
from_raw_partsjoined the alignment check and length check with&&, meaning the error was only returned when both were wrong. A misaligned-but-correctly-sized buffer passed the check, thenfrom_raw_partsdereferences misaligned data — undefined behavior.Added tests that verify each condition is rejected independently.
Changelog
resb: Fix UB around alignment check