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

MIRI reports UB on <Vec<u8> as ByteVecExt>::try_extend_zeroed #62

Closed
Joeoc2001 opened this issue Jan 8, 2024 · 2 comments · Fixed by #63
Closed

MIRI reports UB on <Vec<u8> as ByteVecExt>::try_extend_zeroed #62

Joeoc2001 opened this issue Jan 8, 2024 · 2 comments · Fixed by #63

Comments

@Joeoc2001
Copy link
Contributor

Running the test suite in this repository through MIRI reports that <Vec<u8> as ByteVecExt>::try_extend_zeroed results in Undefined Behaviour.

I believe that this is because the end of as_mut_ptr_end is open and therefore is not pointing to anything borrowed. I'll open a pull request in a minute with a fix which both adds MIRI to CI and which passes all tests with MIRI.

@teoxoy
Copy link
Owner

teoxoy commented Jan 9, 2024

Hmm, good catch!

So this is because as_mut_ptr_end is actually a method on slices and the Vec will Deref to a slice first.
The PR fixes it via Vec's own as_mut_ptr impl and adding the length.

I doubt this specific code is UB in practice though; backports and/or an immediate release might not be necessary.

@Joeoc2001
Copy link
Contributor Author

To be honest, I just want MIRI to pass on my project, and this was a snag. Like you say, I doubt the compiler is about to abuse this UB in any weird ways.

@teoxoy teoxoy closed this as completed in #63 Jan 9, 2024
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 a pull request may close this issue.

2 participants