Skip to content

Conversation

@ChrisDenton
Copy link
Member

Structures returned by the OS will always be correctly aligned. However, security software that impersonates the OS APIs isn't always bug free so we sometimes need to workaround issues such as wrong alignments. In this case we currently do a lot of read_unaligned and allocate a new buffer for filenames to workaround a bug in some security software that could cause issues. We can simplify by just copying unaligned data to the (no longer used) start of the buffer, which is guaranteed to be aligned because it was aligned by us.

The specific issue this was working around in a popular sandbox software has long since been fixed. However, it is possible that other such security software may suffer from the same bug so no harm in keeping the mitigation I guess. I also added a debug assert to test for this as it does indicate a bug, just not with Rust itself. It is a case that should never happen.

@rustbot
Copy link
Collaborator

rustbot commented Jul 30, 2025

r? @thomcc

rustbot has assigned @thomcc.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jul 30, 2025
@ChrisDenton
Copy link
Member Author

On a more meta-note, I don't care too much about the performance of a case that should never be encountered tbh. My main motivation is to have a greater separation of alignment issues from the variable sized buffer issue because I'm hoping to create some helpers around using variable sized buffer that helps avoid accidentally doing the wrong thing (e.g. see the comment on the info reference).

@ChrisDenton ChrisDenton force-pushed the copy-unaligned branch 2 times, most recently from 37fc9e2 to 5ed8aa4 Compare July 30, 2025 22:38
@ChrisDenton
Copy link
Member Author

Ah, I can't really get the lifetimes to work with the Iterator trait. Well at least not easily and I don't want to add a bunch of complexity for the sake of an edge case that should never be hit.

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 31, 2025
@ChrisDenton ChrisDenton deleted the copy-unaligned branch July 31, 2025 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants