# GHSA-f85w-wvc7-crwc: bumpalo has use-after-free due to a lifetime error in `Vec::into_iter()`

> A lifetime error in bumpalo's Vec::into_iter allows use-after-free, potentially leading to memory corruption or crashes when the allocator is dropped.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Not stated
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 14 Jan 2022
- **Also known as:** RUSTSEC-2022-0078

## What is GHSA-f85w-wvc7-crwc?

GHSA-f85w-wvc7-crwc is an use after free vulnerability in bumpalo, published on 14 Jan 2022. 

### Official description

In affected versions of this crate, the lifetime of the iterator produced by `Vec::into_iter()` is not constrained to the lifetime of the `Bump` that allocated the vector's memory. Using the iterator after the `Bump` is dropped causes use-after-free accesses.

The following example demonstrates memory corruption arising from a misuse of this unsoundness.

```rust
use bumpalo::{collections::Vec, Bump};

fn main() {
    let bump = Bump::new();
    let mut vec = Vec::new_in(&bump);
    vec.extend([0x01u8; 32]);
    let into_iter = vec.into_iter();
    drop(bump);

    for _ in 0..100 {
        let reuse_bump = Bump::new();
        let _reuse_alloc = reuse_bump.alloc([0x41u8; 10]);
    }

    for x in into_iter {
        print!("0x{:02x} ", x);
    }
    println!();
}
```

The issue was corrected in version 3.11.1 by adding a lifetime to the `IntoIter` type, and updating the signature of `Vec::into_iter()` to constrain this lifetime.

## Which versions are affected by GHSA-f85w-wvc7-crwc?

3 open source packages ship an affected version, including bumpalo.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `bumpalo` | crates.io | From 1.1.0 | 3.11.1 |
| `bumpalo` | crates.io | From 1.1.0 | 3.11.1 |
| `bumpalo` | crates.io | From 1.1.0 | 3.11.1 |

## How do I fix GHSA-f85w-wvc7-crwc?

Upgrade bumpalo to 3.11.1 or later.

## Is GHSA-f85w-wvc7-crwc being exploited?

There is no known exploitation of GHSA-f85w-wvc7-crwc in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-f85w-wvc7-crwc and fix it if it is affected.

What it is: GHSA-f85w-wvc7-crwc is an use after free vulnerability in bumpalo, published on 14 Jan 2022. 
Exploitation: There is no known exploitation of GHSA-f85w-wvc7-crwc in the wild and no public exploit code.

Affected packages and fixed versions:
- bumpalo (crates.io): affected from 1.1.0; fixed in 3.11.1
- bumpalo (crates.io): affected from 1.1.0; fixed in 3.11.1
- bumpalo (crates.io): affected from 1.1.0; fixed in 3.11.1

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/GHSA-f85w-wvc7-crwc/ (Markdown: https://insights.sbomify.com/GHSA-f85w-wvc7-crwc/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-f85w-wvc7-crwc

---
From sbomify Insights: https://insights.sbomify.com/GHSA-f85w-wvc7-crwc/
Summaries are generated and may contain mistakes; the official description above is the record.
