Skip to content

Remove some unsafe code; fix a soundness hole #721

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

joshlf
Copy link

@joshlf joshlf commented Jul 11, 2025

Replace a number of lines of unsafe code with safe equivalents, some using zerocopy. In one instance, fix a soundness hole (#720).

Closes #720

@joshlf joshlf force-pushed the remove-unsafe branch 5 times, most recently from c46b513 to 745b847 Compare July 11, 2025 19:00
@ChrisDenton
Copy link
Member

Adding a dependency on zerocopy means that zerocopy becomes a dependency of std.

That might be fine! But it is something that will need to be considered.

Cargo.toml Outdated
@@ -28,6 +28,7 @@ exclude = [
[dependencies]
cfg-if = "1.0"
rustc-demangle = "0.1.24"
zerocopy = { version = "0.8.26", features = ["derive"] }
Copy link
Member

Choose a reason for hiding this comment

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

No, this won't work. The standard library can't depend on proc-macros without completely breaking cross-compilation.

Copy link
Author

Choose a reason for hiding this comment

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

Given #720 (comment), I'll need to go back to the drawing board on this anyway. I'll see how much of this I can salvage without relying on derives.

Copy link
Member

Choose a reason for hiding this comment

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

While the definitions are auto-generated, it is still possible to add an impl block outside of that file. It's all crate-local anyway. I dunno if that helps you.

Copy link
Author

Choose a reason for hiding this comment

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

That wouldn't really help with the safety - the point of the derives is the analysis they perform which validates that certain safety properties hold. While it would technically work to write the impls by hand, it wouldn't improve the safety situation.

Replace a number of lines of unsafe code with safe equivalents, some
using `zerocopy`. In one instance, fix a soundness hole (rust-lang#720).

Closes rust-lang#720
@joshlf
Copy link
Author

joshlf commented Jul 11, 2025

Okay, I've removed all uses of derives to address #721 (comment) and #720 (comment).

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.

Soundess bug: &mut reference exposes uninitialized bytes
3 participants