You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Qwaz opened this issue
Dec 23, 2020
· 2 comments
· Fixed by #81728
Labels
C-bugCategory: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-highHigh priorityT-libsRelevant to the library team, which will review and decide on the PR/issue.
A weird Borrow implementation that returns a different result for each call can create a string with uninitialized bytes with join() implementation of [Borrow<str>] type.
Mark-Simulacrum
added
I-prioritize
Issue: Indicates that prioritization has been requested for this issue.
I-unsound
Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness
T-libs
Relevant to the library team, which will review and decide on the PR/issue.
labels
Dec 23, 2020
I guess all that’s needed is an assert!(target.is_empty()) at the end of the body of the spezialize_for_lengths macro? Perhaps the typo in its name could be fixed, too. It might also be beneficial to avoid the unnecessary third(!) call to borrow() that’s due to copy_slice_and_advance using its second argument twice.
C-bugCategory: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-highHigh priorityT-libsRelevant to the library team, which will review and decide on the PR/issue.
A weird
Borrow
implementation that returns a different result for each call can create a string with uninitialized bytes with join() implementation of[Borrow<str>]
type.The problem is in
join_generic_copy
function.The borrow result is first used for the length calculation.
rust/library/alloc/src/str.rs
Lines 152 to 161 in 3ffea60
Then, inside
spezialize_for_lengths
macro, the user-provided slice is borrowed again and the content is copied.rust/library/alloc/src/str.rs
Lines 110 to 114 in 3ffea60
Finally, the length of the slice is set to the length calculated in step 1.
rust/library/alloc/src/str.rs
Line 179 in 3ffea60
Playground link, which demonstrates creating a non-UTF-8 string by only using safe Rust.
The text was updated successfully, but these errors were encountered: