Skip to content
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

Ptr type needs to handle zero-sized types #874

Closed
1 task
Tracked by #671
joshlf opened this issue Feb 13, 2024 · 0 comments · Fixed by #1614
Closed
1 task
Tracked by #671

Ptr type needs to handle zero-sized types #874

joshlf opened this issue Feb 13, 2024 · 0 comments · Fixed by #1614
Labels
blocking-next-release This issue should be resolved before we release on crates.io

Comments

@joshlf
Copy link
Member

joshlf commented Feb 13, 2024

Progress

Details

Credit to @djkoloski for noticing this issue.

Currently, the Ptr type's internal invariants require that the pointer point to a valid allocation. However, the ptr module docs imply that zero-sized accesses do not require a pointer to a valid allocation. This is problematic for us, since it implies that Rust could generate a reference to a ZST which does not point to an allocation. Thus, our impl of From<&T> for Ptr<T> might be unsound (albeit in a way that isn't currently exercisable): it promises that, based on the fact that &T is a reference, it must refer to a valid allocation. If T is a ZST, that implication might not hold.

We should do the following:

@joshlf joshlf added the blocking-next-release This issue should be resolved before we release on crates.io label May 30, 2024
joshlf added a commit that referenced this issue Sep 7, 2024
Now that [1] is completed, zero-sized accesses no longer require
provenance. Per [2], zero-sized references are no longer required to be
dereferenceable, and so may not carry provenance.

This commit updates `Ptr`'s invariants to not require provenance or a
valid allocation when its referent is zero-sized.

[1] rust-lang/rust#117945
[2] rust-lang/rust#125021

Closes #874
github-merge-queue bot pushed a commit that referenced this issue Sep 7, 2024
Now that [1] is completed, zero-sized accesses no longer require
provenance. Per [2], zero-sized references are no longer required to be
dereferenceable, and so may not carry provenance.

This commit updates `Ptr`'s invariants to not require provenance or a
valid allocation when its referent is zero-sized.

[1] rust-lang/rust#117945
[2] rust-lang/rust#125021

Closes #874
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocking-next-release This issue should be resolved before we release on crates.io
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant