-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
API soundness issue in join() implementation of [Borrow<str>] #80335
Copy link
Copy link
Closed
Labels
C-bugCategory: This is a bug.Category: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-highHigh priorityHigh priorityT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-highHigh priorityHigh priorityT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
A weird
Borrowimplementation 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_copyfunction.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_lengthsmacro, 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.