# GHSA-2rxc-gjrp-vjhx: Unsoundness in anstream

> An unsoundness in the anstream library allows attackers to cause memory corruption or crashes by providing specific UTF-8 strings, potentially leading to code execution.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 8 Sep 2024
- **Also known as:** RUSTSEC-2024-0404

## What is GHSA-2rxc-gjrp-vjhx?

GHSA-2rxc-gjrp-vjhx is a memory corruption vulnerability in anstream, published on 8 Sep 2024. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

When given a valid UTF8 string "ö\x1b😀", the function in
crates/anstream/src/adapter/strip.rs will be confused. The UTF8
bytes are \xc3\xb6 then \x1b then \xf0\x9f\x98\x80.

When looping over "non-printable bytes" \x1b\xf0 will be
considered as some non-printable sequence.

This will produce a broken str from the incorrectly segmented
bytes via str::from_utf8_unchecked, and that should never happen.

Full credit goes to [@Ralith](https://github.com/Ralith) who reviewed this code and
asked [@burakemir](https://github.com/burakemir) to follow up.

## Which versions are affected by GHSA-2rxc-gjrp-vjhx?

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


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `anstream` | crates.io | All versions | 0.6.8 |
| `anstream` | crates.io | All versions | 0.6.8 |
| `anstream` | crates.io | From 0.0.0-0 | 0.6.8 |

## How do I fix GHSA-2rxc-gjrp-vjhx?

Upgrade anstream to 0.6.8 or later.

## Is GHSA-2rxc-gjrp-vjhx being exploited?

There is no known exploitation of GHSA-2rxc-gjrp-vjhx in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-2rxc-gjrp-vjhx and fix it if it is affected.

What it is: GHSA-2rxc-gjrp-vjhx is a memory corruption vulnerability in anstream, published on 8 Sep 2024. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: There is no known exploitation of GHSA-2rxc-gjrp-vjhx in the wild and no public exploit code.

Affected packages and fixed versions:
- anstream (crates.io): affected all versions; fixed in 0.6.8
- anstream (crates.io): affected all versions; fixed in 0.6.8
- anstream (crates.io): affected from 0.0.0-0; fixed in 0.6.8

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-2rxc-gjrp-vjhx/ (Markdown: https://insights.sbomify.com/GHSA-2rxc-gjrp-vjhx/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-2rxc-gjrp-vjhx

---
From sbomify Insights: https://insights.sbomify.com/GHSA-2rxc-gjrp-vjhx/
Summaries are generated and may contain mistakes; the official description above is the record.
