`Vec::into_flattened()` may overflow `isize::MAX` with ZST
Open
Nobody has claimed this yet.
C-bug
T-libs
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
For Vec<T> where T is a ZST, Vec::into_flattened() uses usize::checked_mul() as the length and usize::MAX as the capacity of the new Vec, ultimately passing the capacity to new_cap() without further checking and violating its safety invariants.
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 at Vec::into_flattened() and trace how the ZST length and usize::MAX capacity reach new_cap(). Reproduce the overflow case and inspect the surrounding Vec safety checks. Done means the operation no longer violates the isize::MAX allocation invariant, with coverage for the ZST case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100