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 UB in MaybeOwned by deriving the &mut T from a raw pointer, not a &T #471

Merged
merged 1 commit into from
Feb 7, 2022

Conversation

saethlin
Copy link
Contributor

@saethlin saethlin commented Feb 5, 2022

The previous implementation converts a &T to a &mut T by casting through raw pointers, which is UB. Miri can detect this with
MIRIFLAGS=-Zmiri-tag-raw-pointers, though the wasmparser crate itself doesn't have the test coverage to hit it. I became aware of this code because it is hit in the test suites of wasm-bindgen-wasm-interpreter and cranelift-wasm.

As this is only one of two uses of unsafe in this project, I don't think it's worth adding Miri to CI. The test suite for this whole workspace is pretty complex and uses a number of things which Miri is very slow at running or doesn't support at all.

I tried replacing this with an all-safe implementation, and saw a 1-3% performance hit on the benchmarks.

The previous implementation converts a &T to a &mut T by casting through
raw pointers, which is UB. Miri can detect this with
-Zmiri-tag-raw-pointers, though the wasmparser crate itself doesn't
have the test coverage to hit it.
@alexcrichton
Copy link
Member

Thanks!

@alexcrichton alexcrichton merged commit 43860b8 into bytecodealliance:main Feb 7, 2022
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