# GHSA-v363-rrf2-5fmj: Unsound use of str::from_utf8_unchecked on bytes which are not UTF-8

> An attacker can cause undefined behavior, potentially leading to crashes or code execution, by providing invalid UTF-8 bytes to the ferris-says library.

- **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:** 13 Jan 2024
- **Also known as:** RUSTSEC-2024-0001

## What is GHSA-v363-rrf2-5fmj?

GHSA-v363-rrf2-5fmj is a memory corruption vulnerability in ferris-says, published on 13 Jan 2024. 

### Official description

Affected versions receive a `&[u8]` from the caller through a safe API, and pass
it directly to the unsafe `str::from_utf8_unchecked` function.

The behavior of `ferris_says::say` is undefined if the bytes from the caller
don't happen to be valid UTF-8.

The flaw was corrected in [ferris-says#21] by using the safe `str::from_utf8`
instead, and returning an error on invalid input. However this fix has not yet
been published to crates.io as a patch version for 0.2.

Separately, [ferris-says#32] has introduced a different API for version 0.3
which accepts input as `&str` rather than `&[u8]`, so is unaffected by this bug.

[ferris-says#21]: https://github.com/rust-lang/ferris-says/pull/21
[ferris-says#32]: https://github.com/rust-lang/ferris-says/pull/32

## Which versions are affected by GHSA-v363-rrf2-5fmj?

5 open source packages ship an affected version, including ferris-says.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `ferris-says` | crates.io | From 0.1.2 to 0.2.1 | None |
| `ferris-says` | crates.io | From 0.1.2 to 0.2.1 | None |
| `ferris-says` | crates.io | From 0.1.3-0 | 0.3.1 |
| `ferris-says` | crates.io | From 0.3.0 | 0.3.1 |
| `ferris-says` | crates.io | From 0.3.0 | 0.3.1 |

## How do I fix GHSA-v363-rrf2-5fmj?

Upgrade ferris-says to 0.3.1 or later.

## Is GHSA-v363-rrf2-5fmj being exploited?

There is no known exploitation of GHSA-v363-rrf2-5fmj in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-v363-rrf2-5fmj and fix it if it is affected.

What it is: GHSA-v363-rrf2-5fmj is a memory corruption vulnerability in ferris-says, published on 13 Jan 2024. 
Exploitation: There is no known exploitation of GHSA-v363-rrf2-5fmj in the wild and no public exploit code.

Affected packages and fixed versions:
- ferris-says (crates.io): affected from 0.1.2 up to 0.2.1; no fix listed
- ferris-says (crates.io): affected from 0.1.2 up to 0.2.1; no fix listed
- ferris-says (crates.io): affected from 0.1.3-0; fixed in 0.3.1
- ferris-says (crates.io): affected from 0.3.0; fixed in 0.3.1
- ferris-says (crates.io): affected from 0.3.0; fixed in 0.3.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-v363-rrf2-5fmj/ (Markdown: https://insights.sbomify.com/GHSA-v363-rrf2-5fmj/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-v363-rrf2-5fmj

---
From sbomify Insights: https://insights.sbomify.com/GHSA-v363-rrf2-5fmj/
Summaries are generated and may contain mistakes; the official description above is the record.
