Skip to content

fs: Work around rustix listxattr c_char wonkiness #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 5, 2024

Conversation

cgwalters
Copy link
Collaborator

See bytecodealliance/rustix#1061 (comment) Basically current rustix 0.38 sometimes may expose the element type as a signed or unsigned variant, depending on the version of linux-raw-sys and rustix feature flags.

Add a cast to work around this; if we cared to drop the unsafe we could use the zerocopy crate.

See bytecodealliance/rustix#1061 (comment)
Basically current rustix 0.38 sometimes may expose the element type as a signed
or unsigned variant, depending on the version of linux-raw-sys and rustix feature
flags.

Add a cast to work around this; if we cared to drop the unsafe we could
use the zerocopy crate.

Signed-off-by: Colin Walters <[email protected]>
// See https://github.com/bytecodealliance/rustix/pull/1061#issuecomment-2518467534
// Basically current rustix 0.38 sometimes may expose the element type as a signed
// or unsigned variant, depending on the version of linux-raw-sys and rustix feature
// flags.
let mut names = vec![0; names_size];
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A confusing thing here is that type inference is kicking in for the 0 here and we had conflicting requirements before in the wrong case. It'd help to be able to explicitly specify this array as the target type but I don't think rustix exposes that type alias right now even though it probably should because it's part of the public API.

@@ -149,6 +153,8 @@ impl FilesystemReader<'_> {

let mut buffer = [0; 65536];
for name in names.split_inclusive(|c| *c == 0) {
// SAFETY: casting i8 to u8 is safe.
let name: &[u8] = unsafe { std::mem::transmute(name) };
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really wanted to avoid unsafe but my old //fml solution was causing warnings in the case that c_char ended up already being u8. I guess this one won't.

I also expect this to be relatively short-lived until rustix figures out the solution here...

@allisonkarlitskaya allisonkarlitskaya merged commit 692d277 into containers:main Dec 5, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants