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

hybrid-array: make ArraySize an unsafe trait #914

Merged
merged 1 commit into from
May 31, 2023

Conversation

tarcieri
Copy link
Member

It's used when checking the lengths of slices match an array size prior to using a pointer cast to convert types.

If someone were to make their own typenum::Unsigned type and impl ArraySize for it with an ArrayType whose size does not match Unsigned::USIZE, that would be UB.

Really ArraySize is not intended for downstream crates to impl anyway, but making it an unsafe trait at least captures the UB potential.

Additionally this adds more debug checks to check_slice_length to ensure that if there is a length mismatch, it's at least caught in debug builds.

@tarcieri tarcieri force-pushed the hybrid-array/make-array-size-unsafe-trait branch 2 times, most recently from beb2b92 to cf96416 Compare May 31, 2023 00:30
It's used when checking the lengths of slices match an array size prior
to using a pointer cast to convert types.

If someone were to make their own `typenum::Unsigned` type and impl
`ArraySize` for it with an `ArrayType` whose size does not match
`Unsigned::USIZE`, that would be UB.

Really `ArraySize` is not intended for downstream crates to impl anyway,
but making it an `unsafe trait` at least captures the UB potential.

Additionally this adds more debug checks to `check_slice_length` to
ensure that if there is a length mismatch, it's at least caught in debug
builds.
@tarcieri tarcieri force-pushed the hybrid-array/make-array-size-unsafe-trait branch from cf96416 to 6ef5edf Compare May 31, 2023 00:33
@tarcieri tarcieri merged commit 04a440a into master May 31, 2023
@tarcieri tarcieri deleted the hybrid-array/make-array-size-unsafe-trait branch May 31, 2023 00:45
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.

1 participant