-
Notifications
You must be signed in to change notification settings - Fork 39
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
UB in From<String>
for BoxedString
#49
Comments
This appears to still be a problem. I have a similar Miri UB detection for this code: use scraper::Html;
use smartstring::{LazyCompact, SmartString};
fn main() {
let a = Html::parse_document("<html></html>");
let s: String = a.html(); // ~ Fine
let _: SmartString<LazyCompact> = s.into(); // ~ Not fine
} Cargo.toml [package]
name = "boo"
version = "0.1.0"
edition = "2021"
[dependencies]
smartstring = "1.0.1"
scraper = "0.18.1" error: Undefined Behavior: attempting a read access using <26426> at alloc8296[0x27], but that tag does not exist in the borrow stack for this location
--> ~\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\alloc\src\alloc.rs:228:17
|
228 | ptr::copy_nonoverlapping(ptr.as_ptr(), new_ptr.as_mut_ptr(), old_size);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| attempting a read access using <26426> at alloc8296[0x27], but that tag does not exist in the borrow stack for this location
| this error occurs as part of an access at alloc8296[0x0..0x40]
|
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
help: <26426> was created by a SharedReadWrite retag at offsets [0x0..0x27]
--> src\main.rs:7:39
|
7 | let _: SmartString<LazyCompact> = s.into();
| ^^^^^^^^
= note: BACKTRACE (of the first span):
= note: inside `std::alloc::Global::grow_impl` at ~\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\alloc\src\alloc.rs:228:17: 228:87
= note: inside `<std::alloc::Global as std::alloc::Allocator>::grow` at ~\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\alloc\src\alloc.rs:266:18: 266:68
= note: inside `<smartstring::boxed::BoxedString as std::convert::From<std::string::String>>::from` at ~\.cargo\registry\src\index.crates.io-6f17d22bba15001f\smartstring-1.0.1\src\boxed.rs:187:30: 187:84
= note: inside `<std::string::String as std::convert::Into<smartstring::boxed::BoxedString>>::into` at ~\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\convert\mod.rs:757:9: 757:22
= note: inside `<smartstring::SmartString<smartstring::LazyCompact> as std::convert::From<std::string::String>>::from` at ~\.cargo\registry\src\index.crates.io-6f17d22bba15001f\smartstring-1.0.1\src\lib.rs:679:30: 679:43
= note: inside `<std::string::String as std::convert::Into<smartstring::SmartString<smartstring::LazyCompact>>>::into` at ~\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\convert\mod.rs:757:9: 757:22 |
Tested PR #34, which appears to fix the UB I was experiencing |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I ran the existing test suite with miri, which encountered undefined behavior in
From<String> for BoxedString
. Specifically, the error is on the line:And the output from miri is as follows:
The text was updated successfully, but these errors were encountered: