The implementation of `InPlaceIterable` for `Flatten`&`FlatMap` is unsound
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
const S: String = String::new();
fn main() {
let v = vec![[S, "Hello World!".into()], [S, S]];
let mut i = v.into_iter().flatten();
let _ = i.next();
let result: Vec<String> = i.clone().collect();
println!("{result:?}");
}
["\0\0\0\0\0\0\0\0rld!", "\0\0\0\0\0\0\0\0rld!", ""]
free(): invalid pointer
[1] 1131073 IOT instruction (core dumped)
The above code is analogous to #85322 but applied to Flatten instead of Peekable: cloning the whole iterator doesn't preserve capacity in the inner vec::IntoIter. (This also applies to FlatMap.)
Introduced in 1.76
cc @the8472, #110353
@rustbot label T-libs, I-unsound, A-iterators
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the provided reproducer on nightly and compare the behavior with issue #85322. Trace the InPlaceIterable implementations for Flatten and FlatMap, along with the inner vec::IntoIter clone behavior. Done means cloning after partial iteration no longer produces corrupted strings or an invalid-pointer crash, with coverage for the reported case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100