-
Notifications
You must be signed in to change notification settings - Fork 356
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
Pointer dereferenced after allocation was freed in String::replace_range #2759
Comments
Miri is correctly identifying a bug in the standard library, here's a candidate fix: rust-lang/rust#106950 |
compiler-errors
added a commit
to compiler-errors/rust
that referenced
this issue
Jan 18, 2023
Don't do pointer arithmetic on pointers to deallocated memory vec::Splice can invalidate the slice::Iter inside vec::Drain. So we replace them with dangling pointers which, unlike ones to deallocated memory, are allowed. Fixes miri test failures. Fixes rust-lang/miri#2759
bors
pushed a commit
that referenced
this issue
Jan 23, 2023
Don't do pointer arithmetic on pointers to deallocated memory vec::Splice can invalidate the slice::Iter inside vec::Drain. So we replace them with dangling pointers which, unlike ones to deallocated memory, are allowed. Fixes miri test failures. Fixes #2759
thomcc
pushed a commit
to tcdi/postgrestd
that referenced
this issue
May 31, 2023
Don't do pointer arithmetic on pointers to deallocated memory vec::Splice can invalidate the slice::Iter inside vec::Drain. So we replace them with dangling pointers which, unlike ones to deallocated memory, are allowed. Fixes miri test failures. Fixes rust-lang/miri#2759
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Miri reported a pointer being dereferenced after its allocation was freed in a function using
String::replace_range
in a test (ip::sanitize_ip_recognizes_subpages_of_ipv6_address
) in the mwtitle library, and this was reported in Wikimedia Phabricator by @legoktm.I couldn't detect an error in the code, and the test runs fine in stable and nightly, but I reduced the Miri-error-producing code to this minimal example:
If I reduce the input
"1"
or the replacement"0"
to a zero-length string, or if I change the range to0..
or..
, there is no error.The code looks correct and it compiles and runs fine in nightly. I thought this might be a Rustc problem generating code that's incorrect (freeing an allocation early) but happens not to crash so is only caught by Miri, but I'm not very familiar with how Miri works, so I thought I'd post here first.
The full error from `cargo +nightly miri run`
Versions
Probably doesn't matter, but I ran this in Ubuntu in WSL.
rustc +nightly --version --verbose && echo && cargo +nightly miri --version
:The text was updated successfully, but these errors were encountered: