Repository navigation
fix(buffer): keep map_each_in_place output aligned to the mapped type - #10282
Closed
jackylee-ch wants to merge 1 commit into
Closed
jackylee-ch wants to merge 1 commit into
jackylee-ch wants to merge 1 commit into
Conversation
`map_each_in_place` transmuted `BufferMut<T>` to `BufferMut<R>` while keeping `T`'s alignment, so mapping to a type with stricter alignment (e.g. `[u8; 4]` to `u32`) produced an under-aligned buffer, and reading it back as `R` was UB. Raise the alignment to `Alignment::of::<R>()` after mapping, reusing `aligned` (metadata-only when the data is already aligned). This requires `R: Copy`, which every caller already satisfies. The regression test is taken from the issue. Fixes vortex-data#9746 Signed-off-by: jackylee-ch <qcsd2011@gmail.com>
Contributor
|
This function is going to get removed... it's used in one place and we have better versions of this logic |
Contributor
Author
|
Thanks for flagging. This fixes the under-alignment UB from #9746 (filed with a failing test), so it closes that soundness hole while |
Contributor
Author
|
|
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.
What
map_each_in_placetransmutedBufferMut<T>intoBufferMut<R>but keptT'salignment. Mapping to a more strictly aligned type (e.g.
[u8; 4]→u32) leftthe result claiming the weaker alignment, so reading it back as
Rwas UB.Fix
After mapping, raise the alignment to
Alignment::of::<R>()via the existingalignedhelper — metadata-only when the data is already aligned, so the commonsame-alignment path is unchanged. This requires
R: Copy, which every calleralready satisfies.
The regression test is the one from the issue.
Fixes #9746
AI assistance
Prepared with AI assistance; I have reviewed and verified the change.