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

Fix try_pod_read_unaligned never having worked correctly #138

Merged
merged 1 commit into from Oct 30, 2022

Conversation

seritools
Copy link
Contributor

@seritools seritools commented Oct 28, 2022

It seems like a copy-paste error has happened between try_from_bytes/try_from_bytes_mut and try_pod_read_unaligned, causing internal::try_pod_read_unaligned to try to read a &T::Bits instead of a T::Bits, and thus usually failing with a SizeMismatch error.

In the worst case, this allows UB in safe code by having a type allowing any bit pattern and being pointer-sized.

It seems like a copy-paste error has happened between `try_from_bytes`/`try_from_bytes_mut` and `try_pod_read_unaligned`, causing `internal::try_pod_read_unaligned` to try to read a &T::Bits instead of a T::Bits, usually failing with a `SizeMismatch` error. In the worst case, this allows UB in safe code by having a type allowing any bit pattern and being pointer-sized.
@Lokathor Lokathor requested a review from fu5ha October 30, 2022 21:59
@Lokathor
Copy link
Owner

This looks like a correct fix. I'm going to ask @fu5ha to double check since did the rework with the internal module stuff.

Copy link
Collaborator

@fu5ha fu5ha left a comment

Choose a reason for hiding this comment

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

Nice find. Unfortunate that a seemingly small error like this would lead to bad behavior 🤔

@Lokathor Lokathor merged commit f157151 into Lokathor:main Oct 30, 2022
@Lokathor
Copy link
Owner

released as 1.12.2

@seritools
Copy link
Contributor Author

Thanks for the quick merge and fix release!

@seritools seritools deleted the fix-try-pod-read-unaligned branch November 2, 2022 12:51
leod pushed a commit to leod/bytemuck that referenced this pull request Jun 3, 2023
…or#138)

It seems like a copy-paste error has happened between `try_from_bytes`/`try_from_bytes_mut` and `try_pod_read_unaligned`, causing `internal::try_pod_read_unaligned` to try to read a &T::Bits instead of a T::Bits, usually failing with a `SizeMismatch` error. In the worst case, this allows UB in safe code by having a type allowing any bit pattern and being pointer-sized.
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.

None yet

3 participants